From 50c2fb795032102cde3027732d1a17bf29afafce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 20:08:35 +0000 Subject: [PATCH 001/745] chore(deps): bump maven-compiler-plugin from 3.8.1 to 3.10.0 Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.8.1 to 3.10.0. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.8.1...maven-compiler-plugin-3.10.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 16bb54d3..3f89cb46 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.10.0 ${java.version} ${java.version} From d0225f133728eb6750f338cb872ec793f26a7a28 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Mar 2022 20:06:38 +0000 Subject: [PATCH 002/745] chore(deps): bump maven-compiler-plugin from 3.10.0 to 3.10.1 Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.0 to 3.10.1. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.0...maven-compiler-plugin-3.10.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3f89cb46..e77464a5 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.0 + 3.10.1 ${java.version} ${java.version} From a63ebc5babeab4338adc43b6359454f3221b2b6f Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 14 Mar 2022 19:28:57 +0900 Subject: [PATCH 003/745] fix: Version fix 1.16.5 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3f89cb46..e86e8e10 100644 --- a/pom.xml +++ b/pom.xml @@ -84,9 +84,9 @@ - io.papermc.paper + com.destroystokyo.paper paper-api - 1.17.1-R0.1-SNAPSHOT + 1.16.5-R0.1-SNAPSHOT provided From 324462586c2ad68a638abab5437b14e403c65eb7 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 14 Mar 2022 20:31:38 +0900 Subject: [PATCH 004/745] fix: BiFunction to BiPredicate --- .../utils/Say2Functional.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java index 429f7866..48199931 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java @@ -15,7 +15,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.UUID; -import java.util.function.BiFunction; +import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -73,7 +73,7 @@ public void onSay(AsyncChatEvent e) } } - if (entry.keywords != null && Arrays.stream(entry.keywords).noneMatch(s -> entry.matchType.apply(message, s))) + if (entry.keywords != null && Arrays.stream(entry.keywords).noneMatch(s -> entry.matchType.test(message, s))) return; e.setCancelled(true); @@ -85,7 +85,7 @@ public void onSay(AsyncChatEvent e) } entry.func.accept(Arrays.stream(entry.keywords). - filter(s -> entry.matchType.apply(message, s)) + filter(s -> entry.matchType.test(message, s)) .collect(Collectors.toList()).get(0)); } @@ -99,7 +99,7 @@ public void onConsole(ServerCommandEvent e) e.setCancelled(true); FunctionalEntry entry = consoleFunc; - if (entry.keywords != null && Arrays.stream(entry.keywords).noneMatch(s -> entry.matchType.apply(e.getCommand(), s))) + if (entry.keywords != null && Arrays.stream(entry.keywords).noneMatch(s -> entry.matchType.test(e.getCommand(), s))) return; e.setCancelled(true); @@ -111,7 +111,7 @@ public void onConsole(ServerCommandEvent e) } entry.func.accept(Arrays.stream(entry.keywords) - .filter(s -> entry.matchType.apply(e.getCommand(), s)) + .filter(s -> entry.matchType.test(e.getCommand(), s)) .collect(Collectors.toList()).get(0)); } @@ -149,14 +149,14 @@ public static class FunctionalEntry { public final String[] keywords; public final Consumer func; - public final BiFunction matchType; + public final BiPredicate matchType; - public FunctionalEntry(BiFunction matchType, Consumer runas, String... keywords) + public FunctionalEntry(BiPredicate matchType, Consumer runas, String... keywords) { this(null, matchType, runas, keywords); } - public FunctionalEntry(String comment, BiFunction matchType, Consumer runas, String... keywords) + public FunctionalEntry(String comment, BiPredicate matchType, Consumer runas, String... keywords) { if (keywords.length == 0) this.keywords = null; From 095c83d4b3667367d1aba979d03a4215bf03452c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 14 Mar 2022 22:35:45 +0900 Subject: [PATCH 005/745] refactor: Apply lombok --- pom.xml | 6 ++ .../commands/CommandImport.java | 22 ++--- .../commands/CommandRegister.java | 14 +-- .../commands/CommandUpdate.java | 5 +- .../plugin/InstallResult.java | 26 +++-- .../plugin/Installer.java | 97 +++++++++---------- .../plugin/KnownPluginEntry.java | 9 +- .../plugin/KnownPlugins.java | 37 ++++--- .../plugin/compactor/CompactBuilder.java | 4 +- .../utils/GitHubURLBuilder.java | 22 ++--- .../lab/teamkunpluginmanager/utils/Pair.java | 24 +---- .../utils/PluginResolver.java | 2 +- .../utils/PluginUtil.java | 12 +-- .../utils/rdmarker/DevBukkit.java | 4 +- 14 files changed, 130 insertions(+), 154 deletions(-) diff --git a/pom.xml b/pom.xml index e86e8e10..75c5de77 100644 --- a/pom.xml +++ b/pom.xml @@ -120,5 +120,11 @@ 1.15.2-R0.1-SNAPSHOT provided + + org.projectlombok + lombok + 1.18.22 + provided + diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java index fb912164..bd677f95 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java @@ -70,7 +70,7 @@ public static void onCommand(CommandSender sender, String[] args) Pair json = URLUtils.getAsString(url); - switch (json.getKey()) + switch (json.getLeft()) { case 404: sender.sendMessage(ChatColor.RED + "E: ファイルが見つかりませんでした。"); @@ -80,7 +80,7 @@ public static void onCommand(CommandSender sender, String[] args) break; } - if (json.getKey() != 200) + if (json.getLeft() != 200) { sender.sendMessage(ChatColor.RED + "E: 不明なエラーが発生しました。"); return; @@ -91,7 +91,7 @@ public static void onCommand(CommandSender sender, String[] args) LinkedList container; try { - container = new Gson().fromJson(json.getValue(), new TypeToken>() + container = new Gson().fromJson(json.getRight(), new TypeToken>() { }.getType()); } @@ -108,9 +108,9 @@ public static void onCommand(CommandSender sender, String[] args) container.stream().parallel() .forEach(pluginContainer -> { InstallResult result = Installer.install(null, pluginContainer.downloadUrl, true, true, true, false); - add.addAndGet(result.add); - remove.addAndGet(result.remove); - modify.addAndGet(result.modify); + add.addAndGet(result.getAdd()); + remove.addAndGet(result.getRemove()); + modify.addAndGet(result.getModify()); results.add(result); }); @@ -142,11 +142,11 @@ public static void onCommand(CommandSender sender, String[] args) }); loadOrder.forEach(installResult -> { - if (!installResult.success) + if (!installResult.isSuccess()) return; - if (PluginUtil.isPluginLoaded(installResult.pluginName)) + if (PluginUtil.isPluginLoaded(installResult.getPluginName())) { - JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(installResult.pluginName); + JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(installResult.getPluginName()); PluginUtil.unload(plugin); @@ -162,8 +162,8 @@ public void run() } }.runTaskLaterAsynchronously(TeamKunPluginManager.plugin, 20L); } - PluginUtil.load(installResult.fileName.substring(0, installResult.fileName.length() - 4)); - sender.sendMessage(ChatColor.GREEN + "+ " + installResult.pluginName); + PluginUtil.load(installResult.getFileName().substring(0, installResult.getFileName().length() - 4)); + sender.sendMessage(ChatColor.GREEN + "+ " + installResult.getPluginName()); }); TeamKunPluginManager.enableBuildTree = true; sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを構築中..."); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 2cbf0423..39dbb61c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -67,13 +67,13 @@ private static void performAction(CommandSender sender) "", "application/json", "text/plain" ); - if (data.getKey() != 200) + if (data.getLeft() != 200) { sender.sendMessage(ChatColor.RED + "E: エラーが発生しました。しばらくしてからもう一度お試しください。"); return; } - JsonObject object = new Gson().fromJson(data.getValue(), JsonObject.class); + JsonObject object = new Gson().fromJson(data.getRight(), JsonObject.class); final String device_code = object.get("device_code").getAsString(); final String user_code = object.get("user_code").getAsString(); @@ -101,14 +101,14 @@ public void run() "application/json", "text/plain" ); - if (data.getKey() != 200) + if (data.getLeft() != 200) { - sender.sendMessage(ChatColor.RED + "E: エラーが発生しました。: Server response with" + data.getKey()); + sender.sendMessage(ChatColor.RED + "E: エラーが発生しました。: Server response with" + data.getLeft()); this.cancel(); return; } - JsonObject response = new Gson().fromJson(data.getValue(), JsonObject.class); + JsonObject response = new Gson().fromJson(data.getRight(), JsonObject.class); if (response.has("error")) { @@ -117,7 +117,7 @@ public void run() String error = response.get("error").getAsString(); sender.sendMessage(ChatColor.RED + "E: エラーが発生いたしました。:" + parseError(error)); if (sender instanceof Player) - ((Player) sender).resetTitle(); + sender.resetTitle(); this.cancel(); return; } @@ -125,7 +125,7 @@ public void run() TeamKunPluginManager.vault.vault(response.get("access_token").getAsString()); sender.sendMessage(ChatColor.GREEN + "S: トークンを正常に保管しました!"); if (sender instanceof Player) - ((Player) sender).resetTitle(); + sender.resetTitle(); TeamKunPluginManager.session.unlock(); success[0] = true; this.cancel(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 861b9ea5..12150563 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -249,10 +249,7 @@ private static int doRegister(DownloadResult result) { String name = a.getKey(); String url = a.getValue().getAsString(); - KnownPluginEntry ent = new KnownPluginEntry(); - ent.name = name; - ent.url = url; - ent.source = source; + KnownPluginEntry ent = new KnownPluginEntry(name, url, source); KnownPlugins.addKnownPlugin(ent); atomicInteger.incrementAndGet(); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java index 0d1bbbea..b770ebab 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java @@ -1,14 +1,19 @@ package net.kunmc.lab.teamkunpluginmanager.plugin; +import lombok.AllArgsConstructor; +import lombok.Value; + +@Value +@AllArgsConstructor public class InstallResult { - public String fileName; - public String pluginName; - public int add; - public int remove; - public int modify; - public boolean success; + String fileName; + String pluginName; + int add; + int remove; + int modify; + boolean success; public InstallResult(boolean success) { @@ -25,13 +30,4 @@ public InstallResult(String fileName, String pluginName) this(fileName, pluginName, 0, 0, 0, true); } - public InstallResult(String fileName, String pluginName, int add, int remove, int modify, boolean success) - { - this.fileName = fileName; - this.pluginName = pluginName; - this.add = add; - this.remove = remove; - this.modify = modify; - this.success = success; - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index bad7c0bb..bdc10732 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -235,15 +235,15 @@ public static InstallResult install(CommandSender sender, String url, boolean ig //ファイルをダウンロード downloadResult = URLUtils.downloadFile(jarURL); - if (downloadResult.getKey() == null && downloadResult.getValue().startsWith("ERROR ")) + if (downloadResult.getLeft() == null && downloadResult.getRight().startsWith("ERROR ")) { - finalSender.sendMessage(ChatColor.YELLOW + "W: " + downloadResult.getValue().substring(6)); + finalSender.sendMessage(ChatColor.YELLOW + "W: " + downloadResult.getRight().substring(6)); finalSender.sendMessage(ChatColor.RED + "E: ファイルのダウンロードに失敗しました。"); finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } - finalSender.sendMessage(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadResult.getValue())); + finalSender.sendMessage(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadResult.getRight())); add++; finalSender.sendMessage(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_DOWN) + "秒で取得しました。"); @@ -258,13 +258,13 @@ public static InstallResult install(CommandSender sender, String url, boolean ig try { //plugin.ymlを読み取り - description = PluginUtil.loadDescription(new File("plugins/" + downloadResult.getValue())); + description = PluginUtil.loadDescription(new File("plugins/" + downloadResult.getRight())); } catch (FileNotFoundException e) //ファイルが見つからない場合はreturn { finalSender.sendMessage(ChatColor.RED + "E: ファイルが見つかりませんでした。"); if (!withoutRemove) - delete(finalSender, new File("plugins/" + downloadResult.getValue())); + delete(finalSender, new File("plugins/" + downloadResult.getRight())); finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); @@ -274,7 +274,7 @@ public static InstallResult install(CommandSender sender, String url, boolean ig { finalSender.sendMessage(ChatColor.RED + "E: 情報を読み込めませんでした。"); if (!withoutRemove) - delete(finalSender, new File("plugins/" + downloadResult.getValue())); + delete(finalSender, new File("plugins/" + downloadResult.getRight())); finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); @@ -286,7 +286,7 @@ public static InstallResult install(CommandSender sender, String url, boolean ig sender.sendMessage(ChatColor.RED + "E: このプラグインは保護されています。"); add--; if (!withoutRemove) - delete(finalSender, new File("plugins/" + downloadResult.getValue())); + delete(finalSender, new File("plugins/" + downloadResult.getRight())); finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } @@ -304,7 +304,7 @@ public static InstallResult install(CommandSender sender, String url, boolean ig //ファイルを移動 //114514.jar => YJSNPIPlugin-1.0.jar FileUtils.moveFile( - new File("plugins/" + downloadResult.getValue()), + new File("plugins/" + downloadResult.getRight()), new File("plugins/" + fileName) ); downloadResult = new Pair<>(false, fileName); @@ -358,7 +358,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが { //ファイルの比較を行う finalSender.sendMessage(getDiffMessage(PluginUtil.getFile(plugin), false)); - finalSender.sendMessage(getDiffMessage(new File("plugins/" + downloadResult.getValue()), true)); + finalSender.sendMessage(getDiffMessage(new File("plugins/" + downloadResult.getRight()), true)); finalSender.sendMessage("\n"); sender.sendMessage(ChatColor.RED + "プラグインを置換しますか?? " + ChatColor.WHITE + "[" + @@ -371,7 +371,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが int finalAdd = add; int finalModify = modify; - String fileName = downloadResult.getValue(); + String fileName = downloadResult.getRight(); TeamKunPluginManager.functional.add( sender instanceof Player ? ((Player) sender).getUniqueId(): null, @@ -392,26 +392,26 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが //y(yes)だった場合 unInstall(null, description.getName(), true); InstallResult ir = install(finalSender, fileName, false, false, false, true); - finalSender.sendMessage(Messages.getStatusMessage(ir.add, ir.remove, ++ir.modify)); + finalSender.sendMessage(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); }, "y", "n" ) ); - return new InstallResult(downloadResult.getValue(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } //削除 - if (!withoutRemove && new File("plugins/" + downloadResult.getValue()).exists()) - delete(finalSender, new File("plugins/" + downloadResult.getValue())); + if (!withoutRemove && new File("plugins/" + downloadResult.getRight()).exists()) + delete(finalSender, new File("plugins/" + downloadResult.getRight())); finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); finalSender.sendMessage(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); - return new InstallResult(downloadResult.getValue(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } - added.add(new InstallResult(downloadResult.getValue(), description.getName(), add, remove, modify, true)); + added.add(new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true)); //==================依存関係解決処理 ここから================== @@ -455,7 +455,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが //依存関係のインストール InstallResult dependResolve = Installer.install(null, dependUrl, true, false, true, false); //ファイルの名前がない場合は失敗としてマーク - if (dependResolve.fileName.equals("")) + if (dependResolve.getFileName().equals("")) { failedResolve.add(dependency); continue; @@ -487,7 +487,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); finalSender.sendMessage(ChatColor.YELLOW + "W: " + description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); finalSender.sendMessage(ChatColor.RED + String.join(", ", failedResolve)); - return new InstallResult(downloadResult.getValue(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } AtomicBoolean success = new AtomicBoolean(true); @@ -509,7 +509,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが //削除する場合は削除 if (!withoutRemove) - delete(finalSender, new File("plugins/" + f.fileName)); + delete(finalSender, new File("plugins/" + f.getFileName())); //プラグインをアンロード PluginUtil.unload(plugin); @@ -528,13 +528,13 @@ public void run() } //依存関係をロード - PluginUtil.load(f.fileName.substring(0, f.fileName.length() - 4)); + PluginUtil.load(f.getFileName().substring(0, f.getFileName().length() - 4)); } catch (Exception e) //例外が発生した場合 { //削除する場合は削除 if (!withoutRemove) - delete(finalSender, new File("plugins/" + f.fileName)); + delete(finalSender, new File("plugins/" + f.getFileName())); e.printStackTrace(); //失敗フラグを建てる success.set(false); @@ -568,7 +568,7 @@ public void run() finalSender.sendMessage(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); /*} }.runTaskLater(TeamKunPluginManager.plugin, 10L);*/ - return new InstallResult(downloadResult.getValue(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } private static String getDiffMessage(File f, boolean isNew) @@ -637,8 +637,8 @@ private static void depend_askToCommandSender(CommandSender sender, List { int index = integer.incrementAndGet(); - sender.sendMessage(new ComponentBuilder(ChatColor.LIGHT_PURPLE + "- [" + index + "] " + ChatColor.GREEN + pair.getKey()) - .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/kpm i " + pair.getValue())) + sender.sendMessage(new ComponentBuilder(ChatColor.LIGHT_PURPLE + "- [" + index + "] " + ChatColor.GREEN + pair.getLeft()) + .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/kpm i " + pair.getRight())) .event(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColor.GREEN + "クリックしてこのリリースをインストール").create() @@ -670,7 +670,7 @@ private static void depend_askToCommandSender(CommandSender sender, List resource = jar.get(--i); - install(sender, resource.getValue(), ignoreInstall, withoutResolveDepends, withoutRemove, false); + install(sender, resource.getRight(), ignoreInstall, withoutResolveDepends, withoutRemove, false); }, (String[]) ArrayUtils.add(IntStream.range(1, jar.size() + 1).parallel() .mapToObj(String::valueOf) @@ -687,21 +687,21 @@ private static String pickPluginJar(List> jar) String tmp = ""; for (Pair pair : jar) { - String name = pair.getKey(); + String name = pair.getLeft(); if (!name.endsWith(".jar") && name.endsWith(".zip")) continue; if (StringUtils.containsIgnoreCase(name, "plugin-") || StringUtils.containsIgnoreCase(name, "plugin.")) - result = pair.getValue(); + result = pair.getRight(); if (StringUtils.containsIgnoreCase(name, "plugin")) - tmp = pair.getValue(); + tmp = pair.getRight(); } if (result.equals("") && !tmp.equals("")) result = tmp; if (result.equals("")) - result = jar.get(0).getValue(); + result = jar.get(0).getRight(); return result; } @@ -813,15 +813,14 @@ public static CommandSender dummySender() { return new CommandSender() { - @Override - public void sendMessage(String message) + public void sendMessage(@NotNull String message) { } @Override - public void sendMessage(String[] messages) + public void sendMessage(@Nonnull @NotNull String[] messages) { } @@ -833,85 +832,79 @@ public void sendMessage(@Nullable UUID sender, @NotNull String message) } @Override - public void sendMessage(@Nullable UUID sender, @Nonnull @NotNull String... messages) + public void sendMessage(@Nullable UUID sender, @Nonnull @NotNull String[] messages) { } @Override - public Server getServer() + public @NotNull Server getServer() { return Bukkit.getServer(); } @Override - public String getName() + public @NotNull String getName() { return "DUMMY1145141919810931"; } @Override - public Spigot spigot() - { - return spigot(); - } - - @Override - public @NotNull Component name() + public @NotNull Spigot spigot() { return null; } @Override - public boolean isPermissionSet(String name) + public boolean isPermissionSet(@NotNull String name) { return false; } @Override - public boolean isPermissionSet(Permission perm) + public boolean isPermissionSet(@NotNull Permission perm) { return false; } @Override - public boolean hasPermission(String name) + public boolean hasPermission(@NotNull String name) { return false; } @Override - public boolean hasPermission(Permission perm) + public boolean hasPermission(@NotNull Permission perm) { return false; } @Override - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) + public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) { return null; } @Override - public PermissionAttachment addAttachment(Plugin plugin) + public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin) { return null; } @Override - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) + public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) { return null; } @Override - public PermissionAttachment addAttachment(Plugin plugin, int ticks) + public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) { return null; } @Override - public void removeAttachment(PermissionAttachment attachment) + public void removeAttachment(@NotNull PermissionAttachment attachment) { } @@ -923,7 +916,7 @@ public void recalculatePermissions() } @Override - public Set getEffectivePermissions() + public @NotNull Set getEffectivePermissions() { return null; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java index cd734d76..0c081b43 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java @@ -1,8 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.plugin; +import lombok.Value; + +@Value public class KnownPluginEntry { - public String name; - public String url; - public String source; + String name; + String url; + String source; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java index c75099fa..bdc87a9f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java @@ -26,7 +26,7 @@ public static void del(String source) } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException(e); } } @@ -52,14 +52,11 @@ public static boolean isLegacy() { DatabaseMetaData meta = connection.getMetaData(); ResultSet set = meta.getTables(null, null, "DEPEND", null); - boolean a = set.next(); - set.close(); - return a; + return set.next(); } catch (Exception e) { - e.printStackTrace(); - return false; + throw new RuntimeException(e); } } @@ -75,7 +72,7 @@ public static void migration() } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException(e); } initTables(); @@ -93,7 +90,7 @@ private static void initTables() } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException(e); } } @@ -111,20 +108,20 @@ public static KnownPluginEntry getKnown(String name) pstmt.setString(1, org[0]); if (org.length == 2) pstmt.setString(2, org[1]); + ResultSet set = pstmt.executeQuery(); + if (!set.next()) return null; - KnownPluginEntry entry = new KnownPluginEntry(); - entry.name = set.getString("NAME"); - entry.url = set.getString("URL"); - entry.source = set.getString("SOURCE"); - set.close(); - return entry; + + return new KnownPluginEntry( + set.getString("NAME"), + set.getString("URL"), + set.getString("SOURCE")); } catch (Exception e) { - e.printStackTrace(); - return null; + throw new RuntimeException(e); } } @@ -138,14 +135,14 @@ public static void addKnownPlugin(KnownPluginEntry entry) try (Connection connection = dataSource.getConnection(); PreparedStatement pstmt = connection.prepareStatement("INSERT INTO PLUGIN VALUES (?, ?, ?)")) { - pstmt.setString(1, entry.name); - pstmt.setString(2, entry.url); - pstmt.setString(3, entry.source); + pstmt.setString(1, entry.getName()); + pstmt.setString(2, entry.getUrl()); + pstmt.setString(3, entry.getSource()); pstmt.execute(); } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException(e); } } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java index f47e75b3..103cc8d7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java @@ -53,9 +53,7 @@ public CompactBuilder addPlugin(String name) String url = PluginResolver.asUrl(name); - if (!url.startsWith("ERROR")) - this.pre.downloadUrl = url; - else + if (url.startsWith("ERROR")) this.rs = (BuildResult[]) ArrayUtils.add(this.rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED); this.pre.downloadUrl = url; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java index 25eeaa95..55296edd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java @@ -109,13 +109,13 @@ else if (tagNF != null && !tagNF.equals("")) //URLをペアから作る。 Pair urlPair = buildAPIUrl(repoName, tagName); - switch (urlPair.getKey()) + switch (urlPair.getLeft()) { case "GITHUB_REPO_RELEASES_URL": { //APIを叩く。 - Pair json = URLUtils.getAsString(urlPair.getValue()); - switch (json.getKey()) + Pair json = URLUtils.getAsString(urlPair.getRight()); + switch (json.getLeft()) { case 404: return "ERROR ファイルが見つかりませんでした。"; @@ -124,15 +124,15 @@ else if (tagNF != null && !tagNF.equals("")) } //200ではない場合はエラー。 - if (json.getKey() != 200) + if (json.getLeft() != 200) return "ERROR 不明なエラーが発生しました。"; //APIレスポンスがエラーかどうか。 - String error = error(json.getValue()); + String error = error(json.getRight()); if (!error.equals("")) return "ERROR " + error; - JsonArray array = new Gson().fromJson(json.getValue(), JsonArray.class); + JsonArray array = new Gson().fromJson(json.getRight(), JsonArray.class); if (array.size() == 0) return "ERROR リリースが見つかりませんでした。"; @@ -162,8 +162,8 @@ else if (tagNF != null && !tagNF.equals("")) case "GITHUB_REPO_RELEASE_NAME_URL": { //APIを叩く。 - Pair json = URLUtils.getAsString(urlPair.getValue()); - switch (json.getKey()) + Pair json = URLUtils.getAsString(urlPair.getRight()); + switch (json.getLeft()) { case 404: return "ERROR ファイルが見つかりませんでした。"; @@ -172,16 +172,16 @@ else if (tagNF != null && !tagNF.equals("")) } //200ではない場合はエラー。 - if (json.getKey() != 200) + if (json.getLeft() != 200) return "ERROR 不明なエラーが発生しました。"; //APIレスポンスがエラーかどうか。 - String error = error(json.getValue()); + String error = error(json.getRight()); if (!error.equals("")) return "ERROR " + error; //アセットを上からなめる - JsonObject array = new Gson().fromJson(json.getValue(), JsonObject.class); + JsonObject array = new Gson().fromJson(json.getRight(), JsonObject.class); JsonArray asset = array.get("assets").getAsJsonArray(); //assetが一つしかなかったら返す。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java index b4896598..7256382c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java @@ -1,24 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.utils; +import lombok.Value; + +@Value public class Pair { - - private final L left; - private final R right; - - public Pair(L left, R right) - { - this.left = left; - this.right = right; - } - - public L getKey() - { - return left; - } - - public R getValue() - { - return right; - } + L left; + R right; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java index ab51c952..c099759a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java @@ -35,7 +35,7 @@ else if (Spigotmc.isMatch(query)) } if (KnownPlugins.isKnown(query)) - return PluginResolver.asUrl(KnownPlugins.getKnown(query).url); + return PluginResolver.asUrl(KnownPlugins.getKnown(query).getUrl()); else if (StringUtils.split(query, "/").length == 2) return GitHubURLBuilder.urlValidate("https://github.com/" + s, ver); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index 9ccb5ab6..55d0d885 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -230,13 +230,13 @@ public static ArrayList mathLoadOrder(ArrayList fi .forEach(stringStringPair -> { if (!want.contains(stringStringPair)) //既に処理されていた(処理待ちになかった)場合は無視 return; - if (!stringStringPair.success) + if (!stringStringPair.isSuccess()) return; PluginDescriptionFile desc; //dependとか try { - desc = loadDescription(new File("plugins/" + stringStringPair.fileName)); //読み込み順番を取得 + desc = loadDescription(new File("plugins/" + stringStringPair.getFileName())); //読み込み順番を取得 } catch (Exception e) { @@ -264,7 +264,7 @@ public static ArrayList mathLoadOrder(ArrayList fi }); want.forEach(stringStringPair -> { - if (order.contains(stringStringPair.fileName)) + if (order.contains(stringStringPair.getFileName())) return; order.add(stringStringPair); //後回しプラグインの指示 }); @@ -275,7 +275,7 @@ private static InstallResult getContainsEntry(String contain, ArrayList key { AtomicBoolean ab = new AtomicBoolean(false); keys.stream() - .filter(stringStringPair -> stringStringPair.pluginName.equals(contain)) + .filter(stringStringPair -> stringStringPair.getPluginName().equals(contain)) .forEach(stringStringPair -> ab.set(true)); return ab.get(); } @@ -296,7 +296,7 @@ private static ArrayList> removeByValue(ArrayList { - if (stringStringPair.getValue().equals(value)) + if (stringStringPair.getRight().equals(value)) copyOf.remove(stringStringPair); }); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java index 69e010e2..f09291d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java @@ -75,7 +75,7 @@ public static String toDownloadUrl(String urlName) if (slug == null) return urlName; JsonArray projectSearchResult = new Gson().fromJson( - URLUtils.getAsString("https://servermods.forgesvc.net/servermods/projects?search=" + slug).getValue(), + URLUtils.getAsString("https://servermods.forgesvc.net/servermods/projects?search=" + slug).getRight(), JsonArray.class ); @@ -97,7 +97,7 @@ public static String toDownloadUrl(String urlName) return urlName; JsonArray files = new Gson().fromJson( - URLUtils.getAsString("https://servermods.forgesvc.net/servermods/files?projectIds=" + id).getValue(), + URLUtils.getAsString("https://servermods.forgesvc.net/servermods/files?projectIds=" + id).getRight(), JsonArray.class ); From 782aab398e3f86bfd73d68b49566cb604470d915 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 03:08:33 +0900 Subject: [PATCH 006/745] fix: Version fix 1.16.5 --- pom.xml | 2 +- src/main/resources/plugin.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c2045267..6909f0b7 100644 --- a/pom.xml +++ b/pom.xml @@ -117,7 +117,7 @@ org.spigotmc spigot - 1.15.2-R0.1-SNAPSHOT + 1.16.5-R0.1-SNAPSHOT provided diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f1a5f4c6..b35a5d43 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: TeamKunPluginManager version: ${project.version} main: net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager authors: [Peyang] -api-version: 1.15 +api-version: 1.16 description: Manage your plugin! website: https://kunmc.net/ From 047748ceb0546bbc5a46d1719b75e972013b42c6 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 04:08:25 +0900 Subject: [PATCH 007/745] test: Apply junit --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 6909f0b7..ebfb5c0d 100644 --- a/pom.xml +++ b/pom.xml @@ -126,5 +126,17 @@ 1.18.22 provided + + org.junit.jupiter + junit-jupiter-api + 5.8.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + test + From 6b0e49f2643f791484ed95cccff523ce9ca67c9b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 19 Mar 2022 01:12:11 +0900 Subject: [PATCH 008/745] feat: wip: New Plugin resolver --- .../TeamKunPluginManager.java | 3 + .../resolver/PluginResolver.java | 56 +++++++++++++ .../resolver/interfaces/BaseResolver.java | 32 +++++++ .../resolver/interfaces/URLResolver.java | 75 +++++++++++++++++ .../resolver/result/ErrorResult.java | 83 +++++++++++++++++++ .../resolver/result/MultiResult.java | 15 ++++ .../resolver/result/ResolveResult.java | 35 ++++++++ .../resolver/result/SuccessResult.java | 49 +++++++++++ 8 files changed, 348 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index ebb3b185..b48ebcdc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; +import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.Session; import org.bukkit.Bukkit; @@ -23,6 +24,7 @@ public final class TeamKunPluginManager extends JavaPlugin public static Say2Functional functional; public static boolean enableBuildTree = true; public static Session session; + private static PluginResolver resolver; @Override public void onEnable() @@ -32,6 +34,7 @@ public void onEnable() plugin = this; config = getConfig(); functional = new Say2Functional(this); + resolver = new PluginResolver(); vault = new TokenVault(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java new file mode 100644 index 00000000..42662202 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -0,0 +1,56 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.Value; +import lombok.experimental.FieldDefaults; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * プラグインを解決するクラス + */ +@Getter +@Setter +public class PluginResolver +{ + private final List resolvers; + + public PluginResolver() + { + this.resolvers = new ArrayList<>(); + } + + /** + * クエリを使用してプラグインを解決する + * @param query クエリ + */ + public ResolveResult resolve(String query) + { + ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.UNKNOWN_ERROR, ResolveResult.Source.DIRECT); + + for (BaseResolver resolver : resolvers) + { + if (!resolver.isValidResolver(query)) + continue; + + ResolveResult result = resolver.resolve(query); + + if (result instanceof ErrorResult) + { + errorResult = result; + continue; + } + + return result; + } + + return errorResult; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java new file mode 100644 index 00000000..fbe95693 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -0,0 +1,32 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; + +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; + +/** + * プラグインリゾルバのインターフェース + */ +public interface BaseResolver +{ + /** + * クエリを解決します。 + * + * @param query クエリ + * @return クエリの解決結果 + */ + ResolveResult resolve(String query); + + /** + * 複数のリソースを自動で一意に特定します。 + * @param multiResult リソースのリスト。 + * @return プラグイン。 + */ + ResolveResult autoPickOnePlugin(MultiResult multiResult); + + /** + * 与えられたクエリが解決可能かどうかを返します。 + * @param query クエリ + * @return クエリが解決可能ならばtrue + */ + boolean isValidResolver(String query); +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java new file mode 100644 index 00000000..60c6cf46 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -0,0 +1,75 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; + +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.regex.Pattern; + +/** + * URLをプラグインの直リンクに変換するためのリゾルバのインタフェース + */ +public interface URLResolver extends BaseResolver +{ + /** + * 使用可能なURLのパターン + * @return パターン + */ + Pattern[] getURLPatterns(); + + @Override + default boolean isValidResolver(String query) + { + try + { + new URL(query); + } + catch (MalformedURLException e) + { + return false; + } + + Pattern[] patterns = getURLPatterns(); + if (patterns == null || patterns.length == 0) + return true; + + for (Pattern pattern : patterns) + if (pattern.matcher(query).matches()) + return true; + + return false; + } + + static String errorCodeWith(String message, int code) + { + return message + "(The server responded with " + code + ")。"; + } + + default ErrorResult processErrorResponse(int code, ResolveResult.Source source) + { + ErrorResult.ErrorCause cause = ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR; + + switch (code) + { + case 200: + return null; + case 403: + return new ErrorResult(cause + .value(errorCodeWith("サーバからリソースをダウンロードする権限がありません。", code)), source); + case 404: + return new ErrorResult(cause + .value(errorCodeWith("サーバからリソースを見つけることができません。", code)), source); + case 418: + return new ErrorResult(cause.value(errorCodeWith("ティーポットでコーヒーを淹れようとしました。", code)), source); + default: + if (code >= 500 && code < 600) + return new ErrorResult(cause + .value(errorCodeWith("サーバーがダウンしています。", code)), source); + + return new ErrorResult(cause + .value(errorCodeWith("サーバーがエラーレスポンスを返答しました。。", code)), + source); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java new file mode 100644 index 00000000..cb8bb890 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -0,0 +1,83 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.result; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +/** + * プラグイン解決中のエラーの結果。 + */ +@EqualsAndHashCode +@Getter + +public class ErrorResult implements ResolveResult +{ + /** + * エラーケース + */ + @NotNull + private final ErrorCause cause; + + /** + * プラグインの供給元 + */ + @NotNull + private final Source source; // TODO: フロントエンドに依存しないよう、メッセージプロバイダ作る。 + + public ErrorResult(@NotNull ErrorCause cause, @NotNull Source source) + { + this.cause = cause; + this.source = source; + } + /** + * エラーケース + */ + @AllArgsConstructor + public enum ErrorCause + { + /** + * リゾルバが合っていない。 + */ + RESOLVER_MISMATCH("対応するリゾルバが見つかりませんでした。"), + /** + * 不正なクエリ + */ + INVALID_QUERY("不正なクエリです。"), + /** + * プラグインがみつからない。 + * サーバが404を返した場合もこのケースになる。 + */ + PLUGIN_NOT_FOUND("プラグインが見つかりませんでした。"), + /** + * サーバに合ったプラグインのバージョンが見つからなかった + */ + MATCH_VERSION_NOT_FOUND("対応するバージョンが見つかりませんでした。"), + /** + * プラグイン自体は見つかったが、アセット(jarファイル)が見つからない。 + */ + ASSET_NOT_FOUND("アセットが見つかりませんでした。"), + /** + * サーバのレスポンスが破損している/おかしい。 + */ + SERVER_RESPONSE_MALFORMED("サーバが不正なレスポンスを返しました。"), + /** + * その他のサーバに関するエラー + */ + SERVER_RESPONSE_ERROR("サーバがエラーを返しました。"), + /** + * その他のエラー + */ + UNKNOWN_ERROR("不明なエラーが発生しました。"); + + @Getter + private String message; + + public ErrorCause value(String message) + { + this.message = message; + return this; + } + + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java new file mode 100644 index 00000000..cb92c311 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.result; + +import lombok.Value; + +/** + * 解決結果が複数ある場合に返されるクラス。 + */ +@Value +public class MultiResult implements ResolveResult +{ + /** + * The results. + */ + ResolveResult[] results; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java new file mode 100644 index 00000000..8b77d7e5 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -0,0 +1,35 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.result; + +/** + * プラグイン解決結果のインタフェース + */ +public interface ResolveResult +{ + + /** + * プラグイン供給元 + */ + enum Source + { + /** + * GitHub + */ + GITHUB, + /** + * @link https://www.spigotmc.org/resources/ + */ + SPIGOT_MC, + /** + * @link https://dev.bukkit.org/projects/plugins/ + */ + DEV_BUKKIT, + /** + * @link https://curseforge.com/bukkit-plugins/ + */ + CURSE_FORGE, + /** + * 直リンク + */ + DIRECT + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java new file mode 100644 index 00000000..2376fdd9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java @@ -0,0 +1,49 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.result; + +import lombok.Data; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * 解決成功のResolveResult実装。 + */ +@Data +public class SuccessResult implements ResolveResult +{ + /** + * プラグインのダウンロードリンク + */ + @NotNull + private final String downloadUrl; + + /** + * プラグインのファイル名 + */ + @Nullable + private final String fileName; + + /** + * プラグインのバージョン + */ + @Nullable + private final String version; + + /** + * プラグインの供給元 + */ + @NotNull + private final Source source; + + public SuccessResult(@NotNull String downloadUrl, @NotNull Source source) + { + this(downloadUrl, null, null, source); + } + + public SuccessResult(@NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull Source source) + { + this.downloadUrl = downloadUrl; + this.fileName = fileName; + this.version = version; + this.source = source; + } +} From 19ef3884025274571218aa1e0483417525492ce5 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 19 Mar 2022 01:13:29 +0900 Subject: [PATCH 009/745] feat: GitHubResolver --- .../TeamKunPluginManager.java | 2 + .../resolver/impl/GitHubResolver.java | 178 ++++++++++++++++++ .../resolver/impl/GitHubSuccessResult.java | 48 +++++ 3 files changed, 228 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index b48ebcdc..ed6cd65c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -6,6 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.Session; import org.bukkit.Bukkit; @@ -35,6 +36,7 @@ public void onEnable() config = getConfig(); functional = new Say2Functional(this); resolver = new PluginResolver(); + resolver.getResolvers().add(new GitHubResolver()); vault = new TokenVault(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java new file mode 100644 index 00000000..b7dd8918 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java @@ -0,0 +1,178 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class GitHubResolver implements URLResolver +{ + private static final String GITHUB_REPO_RELEASES_URL = "https://api.github.com/repos/%s/releases"; + private static final String GITHUB_REPO_RELEASE_NAME_URL = GITHUB_REPO_RELEASES_URL + "/tags/%s"; + + private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("^/(?[a-zA-Z\\d]" + + "(?[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38}/[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100})" + + "(?:/(?:tags|releases(?:/(?:tag/(?[^/]+)/?$|download/(?[^/]+)/" + + "(?[^/]+)))?))?/?$"); + + @Override + public ResolveResult resolve(String query) + { + URL url; + try + { + + url = new URL(query); + } + catch (MalformedURLException e) + { + return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); + } + + Matcher matcher = GITHUB_REPO_PATTERN.matcher(url.getPath()); + + String repository = null; + String owner = null; + String tag = null; + + while (matcher.find()) + { + String repositoryGroup = matcher.group("repository"); + String downloadTagGroup = matcher.group("downloadTag"); + String tagGroup = matcher.group("tag"); + String fileNameGroup = matcher.group("fileName"); + String ownerGroup = matcher.group("owner"); + + if (fileNameGroup != null && !fileNameGroup.isEmpty()) // URLが自己解決。 + return new SuccessResult(url.getPath(), ResolveResult.Source.GITHUB); + + if (!repositoryGroup.isEmpty()) + repository = repositoryGroup; + + if (downloadTagGroup != null && !downloadTagGroup.isEmpty()) + tag = downloadTagGroup; + else if (tagGroup != null && !tagGroup.isEmpty()) + tag = tagGroup; + + if (ownerGroup != null && !ownerGroup.isEmpty()) + owner = ownerGroup; + } + + if (repository == null) + return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); + + return processGitHubAPI(owner, repository, tag); + } + + @Override + public ResolveResult autoPickOnePlugin(MultiResult multiResult) + { + ResolveResult[] results = multiResult.getResults(); + + if (results.length == 0) + return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + + return results[0]; + } + + private ResolveResult processGitHubAPI(String owner, String repository, String tag) + { + String apiURL; + if (tag != null) + apiURL = String.format(GITHUB_REPO_RELEASE_NAME_URL, repository, tag); + else + apiURL = String.format(GITHUB_REPO_RELEASES_URL, repository); + + Pair response = URLUtils.getAsString(apiURL); + + ErrorResult mayError = processErrorResponse(response.getLeft(), ResolveResult.Source.GITHUB); + + if (mayError != null) + return mayError; + + String json = response.getRight(); + + Gson gson = new Gson(); + + if (tag != null) + { + JsonObject jsonObject = gson.fromJson(json, JsonObject.class); + + return buildResultSingle(owner, jsonObject); + } + + JsonArray jsonArray = gson.fromJson(json, JsonArray.class); + List results = new ArrayList<>(); + + for (JsonElement jsonElement : jsonArray) + { + ResolveResult result = buildResultSingle(owner, jsonElement.getAsJsonObject()); + + if (result instanceof ErrorResult) + continue; + + results.add(result); + } + + return new MultiResult(results.toArray(new ResolveResult[0])); + } + + private ResolveResult buildResultSingle(String owner, JsonObject object) + { + List results = new ArrayList<>(); + + String releaseName = object.get("name").getAsString(); + String body = object.get("body").getAsString(); + String version = object.get("tag_name").getAsString(); + long releaseId = object.get("id").getAsLong(); + + JsonArray assets = object.getAsJsonArray("assets"); + + if (assets.size() == 0) + return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.GITHUB); + + for (JsonElement asset : assets) + { + if (!asset.isJsonObject()) + continue; + + JsonObject assetObject = asset.getAsJsonObject(); + + String downloadURL = assetObject.get("browser_download_url").getAsString(); + String fileName = assetObject.get("name").getAsString(); + long size = assetObject.get("size").getAsLong(); + + GitHubSuccessResult result = new GitHubSuccessResult(downloadURL, fileName, version, owner, size, releaseName, body, releaseId); + + if (assets.size() == 1) + return result; + else + results.add(result); + } + + return new MultiResult(results.toArray(new GitHubSuccessResult[0])); + } + + @Override + public Pattern[] getURLPatterns() + { + return new Pattern[] { + Pattern.compile("^https?://(www\\.)?github.com/") + }; + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java new file mode 100644 index 00000000..d120eaf8 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java @@ -0,0 +1,48 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Getter +public class GitHubSuccessResult extends SuccessResult +{ + /** + * リポジトリ(プラグイン)のオーナー + */ + @NotNull + private final String owner; + + /** + * ファイルサイズ + */ + private final long size; + + /** + * リリースの名前 + */ + @NotNull + private final String releaseName; + + /** + * リリースの内容 + */ + @NotNull + private final String releaseBody; + + /** + * リリースのid + */ + private final long releaseId; + + public GitHubSuccessResult(@NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) + { + super(downloadUrl, fileName, version, Source.GITHUB); + this.owner = owner; + this.size = size; + this.releaseName = releaseName; + this.releaseBody = releaseBody; + this.releaseId = releaseId; + } +} From 77bd268c4294e9c2c42bea9073e6658ee81a2ee9 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 19 Mar 2022 20:18:48 +0900 Subject: [PATCH 010/745] feat: autoPickFirst --- .../resolver/impl/GitHubResolver.java | 7 +------ .../resolver/interfaces/BaseResolver.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java index b7dd8918..1e8801c6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java @@ -81,12 +81,7 @@ else if (tagGroup != null && !tagGroup.isEmpty()) @Override public ResolveResult autoPickOnePlugin(MultiResult multiResult) { - ResolveResult[] results = multiResult.getResults(); - - if (results.length == 0) - return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); - - return results[0]; + return autoPickFirst(multiResult, ResolveResult.Source.GITHUB); } private ResolveResult processGitHubAPI(String owner, String repository, String tag) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java index fbe95693..97772bea 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; @@ -29,4 +30,19 @@ public interface BaseResolver * @return クエリが解決可能ならばtrue */ boolean isValidResolver(String query); + + /** + * MultiResult から最初の要素を取得します。 + * @param multiResult MultiResult + * @return 最初の要素 + */ + default ResolveResult autoPickFirst(MultiResult multiResult, ResolveResult.Source source) + { + ResolveResult[] results = multiResult.getResults(); + + if (results.length == 0) + return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + + return results[0]; + } } From 181b24671285cf798d15644284ac84d665c490db Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 19 Mar 2022 21:58:50 +0900 Subject: [PATCH 011/745] feat: Host matching --- .../resolver/impl/GitHubResolver.java | 7 ++---- .../resolver/interfaces/URLResolver.java | 24 +++++++++---------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java index 1e8801c6..c7d7d5d3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java @@ -163,11 +163,8 @@ private ResolveResult buildResultSingle(String owner, JsonObject object) } @Override - public Pattern[] getURLPatterns() + public String[] getHosts() { - return new Pattern[] { - Pattern.compile("^https?://(www\\.)?github.com/") - }; + return new String[] { "github.com", "www.github.com" }; } - } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 60c6cf46..88805deb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -13,31 +13,29 @@ public interface URLResolver extends BaseResolver { /** - * 使用可能なURLのパターン - * @return パターン + * 使用可能なURLのホスト + * @return ホスト */ - Pattern[] getURLPatterns(); + String[] getHosts(); @Override default boolean isValidResolver(String query) { try { - new URL(query); + URL url = new URL(query); + + if (getHosts().length == 0) + return true; + + for (String host : getHosts()) + if (url.getHost().equalsIgnoreCase(host)) + return true; } catch (MalformedURLException e) { return false; } - - Pattern[] patterns = getURLPatterns(); - if (patterns == null || patterns.length == 0) - return true; - - for (Pattern pattern : patterns) - if (pattern.matcher(query).matches()) - return true; - return false; } From 4646997443a8e6a543a03f796bdd3e410cedce4c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 02:11:10 +0900 Subject: [PATCH 012/745] feat: Marketplace result --- .../resolver/impl/GitHubResolver.java | 34 +++++++++---------- .../resolver/impl/GitHubSuccessResult.java | 33 ++++++++++++++++-- .../resolver/result/MarketplaceResult.java | 25 ++++++++++++++ 3 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java index c7d7d5d3..2636c25e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java @@ -25,29 +25,22 @@ public class GitHubResolver implements URLResolver private static final String GITHUB_REPO_RELEASE_NAME_URL = GITHUB_REPO_RELEASES_URL + "/tags/%s"; private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("^/(?[a-zA-Z\\d]" + - "(?[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38}/[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100})" + + "(?[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38}/(?[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100}))" + "(?:/(?:tags|releases(?:/(?:tag/(?[^/]+)/?$|download/(?[^/]+)/" + "(?[^/]+)))?))?/?$"); @Override public ResolveResult resolve(String query) { - URL url; - try - { + Matcher matcher = urlMatcher(GITHUB_REPO_PATTERN, query); - url = new URL(query); - } - catch (MalformedURLException e) - { + if (matcher == null) return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); - } - - Matcher matcher = GITHUB_REPO_PATTERN.matcher(url.getPath()); String repository = null; String owner = null; String tag = null; + String repositoryName = null; while (matcher.find()) { @@ -56,9 +49,10 @@ public ResolveResult resolve(String query) String tagGroup = matcher.group("tag"); String fileNameGroup = matcher.group("fileName"); String ownerGroup = matcher.group("owner"); + String repoNameGroup = matcher.group("repoName"); if (fileNameGroup != null && !fileNameGroup.isEmpty()) // URLが自己解決。 - return new SuccessResult(url.getPath(), ResolveResult.Source.GITHUB); + return new SuccessResult(query, ResolveResult.Source.GITHUB); if (!repositoryGroup.isEmpty()) repository = repositoryGroup; @@ -70,12 +64,15 @@ else if (tagGroup != null && !tagGroup.isEmpty()) if (ownerGroup != null && !ownerGroup.isEmpty()) owner = ownerGroup; + + if (repoNameGroup != null && !repoNameGroup.isEmpty()) + repositoryName = repoNameGroup; } if (repository == null) return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); - return processGitHubAPI(owner, repository, tag); + return processGitHubAPI(owner, repositoryName, repository, tag); } @Override @@ -84,7 +81,7 @@ public ResolveResult autoPickOnePlugin(MultiResult multiResult) return autoPickFirst(multiResult, ResolveResult.Source.GITHUB); } - private ResolveResult processGitHubAPI(String owner, String repository, String tag) + private ResolveResult processGitHubAPI(String owner, String repositoryName, String repository, String tag) { String apiURL; if (tag != null) @@ -107,7 +104,7 @@ private ResolveResult processGitHubAPI(String owner, String repository, String t { JsonObject jsonObject = gson.fromJson(json, JsonObject.class); - return buildResultSingle(owner, jsonObject); + return buildResultSingle(owner, repositoryName, jsonObject); } JsonArray jsonArray = gson.fromJson(json, JsonArray.class); @@ -115,7 +112,7 @@ private ResolveResult processGitHubAPI(String owner, String repository, String t for (JsonElement jsonElement : jsonArray) { - ResolveResult result = buildResultSingle(owner, jsonElement.getAsJsonObject()); + ResolveResult result = buildResultSingle(owner, repositoryName, jsonElement.getAsJsonObject()); if (result instanceof ErrorResult) continue; @@ -126,7 +123,7 @@ private ResolveResult processGitHubAPI(String owner, String repository, String t return new MultiResult(results.toArray(new ResolveResult[0])); } - private ResolveResult buildResultSingle(String owner, JsonObject object) + private ResolveResult buildResultSingle(String owner, String repositoryName, JsonObject object) { List results = new ArrayList<>(); @@ -134,6 +131,7 @@ private ResolveResult buildResultSingle(String owner, JsonObject object) String body = object.get("body").getAsString(); String version = object.get("tag_name").getAsString(); long releaseId = object.get("id").getAsLong(); + String htmlUrl = object.get("html_url").getAsString(); JsonArray assets = object.getAsJsonArray("assets"); @@ -151,7 +149,7 @@ private ResolveResult buildResultSingle(String owner, JsonObject object) String fileName = assetObject.get("name").getAsString(); long size = assetObject.get("size").getAsLong(); - GitHubSuccessResult result = new GitHubSuccessResult(downloadURL, fileName, version, owner, size, releaseName, body, releaseId); + GitHubSuccessResult result = new GitHubSuccessResult(downloadURL, fileName, version, repositoryName, htmlUrl, owner, size, releaseName, body, releaseId); if (assets.size() == 1) return result; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java index d120eaf8..8c9ba1de 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java @@ -1,12 +1,13 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @Getter -public class GitHubSuccessResult extends SuccessResult +public class GitHubSuccessResult extends SuccessResult implements MarketplaceResult { /** * リポジトリ(プラグイン)のオーナー @@ -31,18 +32,44 @@ public class GitHubSuccessResult extends SuccessResult @NotNull private final String releaseBody; + /** + * リポジトリの名前 + */ + @NotNull + private final String repoName; + /** * リリースのid */ private final long releaseId; - public GitHubSuccessResult(@NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) + public GitHubSuccessResult(@NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String repoName, @NotNull String htmlPage, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) { super(downloadUrl, fileName, version, Source.GITHUB); this.owner = owner; this.size = size; + this.releaseId = releaseId; + this.releaseName = releaseName; this.releaseBody = releaseBody; - this.releaseId = releaseId; + this.repoName = repoName; + } + + @Override + public String getTitle() + { + return repoName + " - " + releaseName; + } + + @Override + public String getUrl() + { + return "https://github.com/" + owner + "/" + repoName; + } + + @Override + public String getDescription() + { + return releaseBody; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java new file mode 100644 index 00000000..1f52af46 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.result; + +/** + * 紹介文付きのリソースの解決結果を格納。 + */ +public interface MarketplaceResult +{ + /** + * 掲載されているタイトル/名前 + * @return 掲載されているタイトル/名前 + */ + String getTitle(); + + /** + * 掲載されているURL + * @return 掲載されているURL + */ + String getUrl(); + + /** + * 掲載されている紹介文 + * @return 掲載されている紹介文 + */ + String getDescription(); +} From 845f7881276a903622206f520bca3adf7a6c7767 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 04:02:10 +0900 Subject: [PATCH 013/745] feat: VersionedResult --- .../resolver/result/VersionedResult.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java new file mode 100644 index 00000000..5f50f1c9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.result; + +import java.util.List; + +/** + * プラグインの対応するバージョンを格納するインターフェース。 + */ +public interface VersionedResult +{ + /** + * プラグインの対応する一覧。 + * + */ + List getVersions(); +} From 73ef3adba1f1fd09d1de2419b2655a05a85e06cc Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 04:02:22 +0900 Subject: [PATCH 014/745] feat: urlMatcher --- .../resolver/interfaces/URLResolver.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 88805deb..60b026ce 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -5,6 +5,7 @@ import java.net.MalformedURLException; import java.net.URL; +import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -44,6 +45,21 @@ static String errorCodeWith(String message, int code) return message + "(The server responded with " + code + ")。"; } + default Matcher urlMatcher(Pattern pattern, String urlString) + { + URL url; + try + { + url = new URL(urlString); + } + catch (MalformedURLException e) + { + return null; + } + + return pattern.matcher(url.getPath()); + } + default ErrorResult processErrorResponse(int code, ResolveResult.Source source) { ErrorResult.ErrorCause cause = ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR; From a492308c57d93ba2e9bc319a55802674083bc88d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 04:02:39 +0900 Subject: [PATCH 015/745] refactor: MATCH_VERSION_NOT_FOUND => MATCH_PLUGIN_NOT_FOUND --- .../lab/teamkunpluginmanager/resolver/result/ErrorResult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index cb8bb890..18489ac6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -52,7 +52,7 @@ public enum ErrorCause /** * サーバに合ったプラグインのバージョンが見つからなかった */ - MATCH_VERSION_NOT_FOUND("対応するバージョンが見つかりませんでした。"), + MATCH_PLUGIN_NOT_FOUND("対応するバージョンが見つかりませんでした。"), /** * プラグイン自体は見つかったが、アセット(jarファイル)が見つからない。 */ From 90b8f27070108e915f51dacc2d3bd4f5f30b2b15 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 04:04:12 +0900 Subject: [PATCH 016/745] feat: SpigotMCResolver --- .../TeamKunPluginManager.java | 2 + .../resolver/impl/SpigotMCResolver.java | 136 ++++++++++++++++++ .../resolver/impl/SpigotMCSuccessResult.java | 38 +++++ 3 files changed, 176 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index ed6cd65c..7b64cfbd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -7,6 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.Session; import org.bukkit.Bukkit; @@ -37,6 +38,7 @@ public void onEnable() functional = new Say2Functional(this); resolver = new PluginResolver(); resolver.getResolvers().add(new GitHubResolver()); + resolver.getResolvers().add(new SpigotMCResolver()); vault = new TokenVault(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java new file mode 100644 index 00000000..8d51d957 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -0,0 +1,136 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Base64; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +public class SpigotMCResolver implements URLResolver +{ + private static final Pattern PATTERN = Pattern.compile("/resources/([\\w-]+\\.?(?[\\d]+))(?:/|/updates/?|/downloads/?|(?:update/?\\?update=|download/?\\?version=)(?\\d+))?"); + + @Override + public ResolveResult resolve(String query) + { + Matcher matcher = urlMatcher(PATTERN, query); + + String id = null; + String version = null; + + while (matcher.find()) + { + String idGroup = matcher.group("resourceId"); + String versionGroup = matcher.group("version"); + + if (idGroup != null && !idGroup.isEmpty()) + id = idGroup; + if (versionGroup != null && !versionGroup.isEmpty()) + version = versionGroup; + } + + if (id == null) + return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); + + String spigotAPIUrl = "https://apple.api.spiget.org/v2/resources/" + id; + + Pair data = URLUtils.getAsString(spigotAPIUrl); + + + ErrorResult mayError = processErrorResponse(data.getLeft(), ResolveResult.Source.SPIGOT_MC); + + if (mayError != null) + return mayError; + + String json = data.getRight(); + Gson gson = new Gson(); + JsonObject jsonObject = gson.fromJson(json, JsonObject.class); + + return buildResult(jsonObject, version); + } + + private ResolveResult buildResult(JsonObject jsonObject, @Nullable String version) + { + boolean external = jsonObject.get("external").getAsBoolean(); + if (external) + return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("SpigotMC ではホストされていません。"), + ResolveResult.Source.SPIGOT_MC); + + String description = b64Decode(jsonObject.get("description").getAsString()); + String name = jsonObject.get("name").getAsString(); + List testedVersions = StreamSupport.stream(jsonObject.get("testedVersions").getAsJsonArray().spliterator(), false) + .map(JsonElement::getAsString) + .collect(Collectors.toList()); + long id = jsonObject.get("id").getAsLong(); + + boolean premium = jsonObject.get("premium").getAsBoolean(); + if (premium) + return new ErrorResult(ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("このプラグインはプレミアムプラグインです。"), + ResolveResult.Source.SPIGOT_MC); + + long[] versions = StreamSupport.stream(jsonObject.get("versions").getAsJsonArray().spliterator(), false) + .mapToLong(e -> e.getAsJsonObject().get("id").getAsLong()) + .toArray(); + + + if (versions.length == 0) + return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.SPIGOT_MC); + + + if (version == null) + { + List results = new ArrayList<>(); + for (long v : versions) + results.add(new SpigotMCSuccessResult(String.valueOf(v), name, id, description, testedVersions)); + + return new MultiResult(results.toArray(new SpigotMCSuccessResult[0])); + } + + for (long v : versions) + if (String.valueOf(v).equals(version)) + return new SpigotMCSuccessResult(version, name, id, description, testedVersions); + + return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("指定されたバージョンのプラグインが見つかりませんでした。"), + ResolveResult.Source.SPIGOT_MC); + } + + private String b64Decode(String str) + { + try + { + return new String(Base64.getDecoder().decode(str)); + } + catch (IllegalArgumentException e) + { + System.out.println("[SpigotMCResolver] SpigotMCから無効なレスポンスが返答されました。: " + e.getMessage()); + e.printStackTrace(); + + return "Failed to decode Base64 string."; + } + } + + @Override + public ResolveResult autoPickOnePlugin(MultiResult multiResult) + { + return autoPickFirst(multiResult, ResolveResult.Source.SPIGOT_MC); + } + + @Override + public String[] getHosts() + { + return new String[]{"spigotmc.org", "www.spigotmc.org"}; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java new file mode 100644 index 00000000..7ec05aba --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java @@ -0,0 +1,38 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.VersionedResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +@Getter +public class SpigotMCSuccessResult extends SuccessResult implements MarketplaceResult, VersionedResult +{ + @NotNull + private final String title; + + @NotNull + private final String url; + + @NotNull + private final String description; + + @NotNull + private final List versions; + + public SpigotMCSuccessResult(@Nullable String version, @NotNull String title, long id, @NotNull String description, @NotNull List versions) + { + super("https://apple.api.spiget.org/v2/resources/" + id + + (version != null ? "versions/" + version : "") + "/download", + null, version, Source.SPIGOT_MC); + this.title = title; + this.description = description; + this.url = "https://www.spigotmc.org/resources/" + id; + this.versions = versions; + + } +} From f3505dc7697fbdf82aa76be0d087a55a23e29915 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 07:59:53 +0900 Subject: [PATCH 017/745] fix: Comment of match_plugin_not_found --- .../lab/teamkunpluginmanager/resolver/result/ErrorResult.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index 18489ac6..f7c892f2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -50,9 +50,9 @@ public enum ErrorCause */ PLUGIN_NOT_FOUND("プラグインが見つかりませんでした。"), /** - * サーバに合ったプラグインのバージョンが見つからなかった + * サーバに合ったプラグインが見つからなかった */ - MATCH_PLUGIN_NOT_FOUND("対応するバージョンが見つかりませんでした。"), + MATCH_PLUGIN_NOT_FOUND("対応するプラグインが見つかりませんでした。"), /** * プラグイン自体は見つかったが、アセット(jarファイル)が見つからない。 */ From 69aeaaa9030760f63a767d6568da240e575d726b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 08:22:50 +0900 Subject: [PATCH 018/745] feat: CurseForge and DevBukkit resolver --- .../TeamKunPluginManager.java | 2 + .../resolver/impl/CurseBukkitResolver.java | 139 ++++++++++++++++++ .../impl/CurseBukkitSuccessResult.java | 65 ++++++++ 3 files changed, 206 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 7b64cfbd..f78f0e0b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -6,6 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; @@ -39,6 +40,7 @@ public void onEnable() resolver = new PluginResolver(); resolver.getResolvers().add(new GitHubResolver()); resolver.getResolvers().add(new SpigotMCResolver()); + resolver.getResolvers().add(new CurseBukkitResolver()); vault = new TokenVault(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java new file mode 100644 index 00000000..7f0e72c7 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -0,0 +1,139 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class CurseBukkitResolver implements URLResolver +{ + private static final String basePatterns = "(?\\w+)(/files(/(?\\d+))?(/download)?)?/?$"; + private static final Pattern BUKKIT_PATTERN = Pattern.compile("^/projects/" + basePatterns); + private static final Pattern CURSE_PATTERN = Pattern.compile("^/minecraft/bukkit-plugins/" + basePatterns); + private static final String BUKKIT_API_VERSION = StringUtils.split(Bukkit.getVersion(), "-")[0]; + @Override + public ResolveResult resolve(String query) + { + boolean bukkitFlag = StringUtils.containsIgnoreCase(query, "bukkit.org"); + + ResolveResult.Source errorSource = bukkitFlag ? ResolveResult.Source.DEV_BUKKIT : ResolveResult.Source.CURSE_FORGE; + + Matcher matcher; + if (bukkitFlag) + matcher = urlMatcher(BUKKIT_PATTERN, query); + else + matcher = urlMatcher(CURSE_PATTERN, query); + + String slug = null; + String version = null; + + while (matcher.find()) + { + String slugGroup = matcher.group("slug"); + String versionGroup = matcher.group("version"); + + if (slugGroup != null && !slugGroup.isEmpty()) + slug = slugGroup; + if (versionGroup != null && !versionGroup.isEmpty()) + version = versionGroup; + } + + if (slug == null) + return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, errorSource); + + Pair projectSearchResponse = URLUtils.getAsString("https://servermods.forgesvc.net/servermods/projects?search=" + slug); + + if (projectSearchResponse.getLeft() != 200) + return processErrorResponse(projectSearchResponse.getLeft(), errorSource); + + JsonArray projectSearchResult = new Gson().fromJson(projectSearchResponse.getRight(), JsonArray.class); + + String name = null; + long projectId = -1; + for (JsonElement elm : projectSearchResult) + { + JsonObject obj = (JsonObject) elm; + + if (obj.get("slug").getAsString().equalsIgnoreCase(slug)) + { + projectId = obj.get("id").getAsLong(); + name = obj.get("name").getAsString(); + break; + } + } + + if (projectId == -1) + return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, errorSource); + + return processFiles(slug, name, projectId, version, errorSource); + } + + private ResolveResult processFiles(String slug, String name, long projectId, String version, ResolveResult.Source source) + { + Pair projectFilesResponse = URLUtils.getAsString("https://servermods.forgesvc.net/servermods/files?projectIds=" + projectId); + + ErrorResult mayError = processErrorResponse(projectFilesResponse.getLeft(), source); + if (mayError != null) + return mayError; + + JsonArray projectFilesResult = new Gson().fromJson(projectFilesResponse.getRight(), JsonArray.class); + if (projectFilesResult.size() == 0) + return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND, source); + + JsonObject pickedPlugin = pickUpValidVersion(projectFilesResult, version); + if (pickedPlugin == null) + return new ErrorResult(ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, source); + + String downloadUrl = pickedPlugin.get("downloadUrl").getAsString(); + String fileName = pickedPlugin.get("fileName").getAsString(); + String versionName = pickedPlugin.get("name").getAsString(); + + return new CurseBukkitSuccessResult(downloadUrl, projectId, fileName, versionName, source, slug, name); + } + + private static JsonObject pickUpValidVersion(JsonArray versions, @Nullable String version) + { + JsonObject file = null; + + for (JsonElement projectFile : versions) + { + JsonObject projectFileObject = projectFile.getAsJsonObject(); + + if (version != null && projectFileObject.get("fileUrl").getAsString().endsWith(version)) + return projectFileObject; + + if (projectFileObject.get("gameVersion").getAsString().contains(BUKKIT_API_VERSION)) + file = projectFileObject; + } + + return file; + } + + @Override + public ResolveResult autoPickOnePlugin(MultiResult multiResult) + { + return null; + } + + @Override + public String[] getHosts() + { + return new String[] { + "dev.bukkit.org", + "www.curseforge.com", + "curseforge.com", + }; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java new file mode 100644 index 00000000..cad3c242 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -0,0 +1,65 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * CurseForge または Bukkit.org の成功結果を表すクラス + */ +@Getter +public class CurseBukkitSuccessResult extends SuccessResult implements MarketplaceResult +{ + @NotNull + private final String title; + + @NotNull + private final String slug; + + private final long id; + + public CurseBukkitSuccessResult(@NotNull String downloadUrl, long id, @Nullable String fileName, @Nullable String version, @NotNull Source source, @NotNull String slug, @NotNull String title) + { + super(downloadUrl, fileName, version, source); + + if (source != Source.CURSE_FORGE && source != Source.DEV_BUKKIT) + throw new IllegalArgumentException("source must be CurseForge or DevBukkit"); + + this.id = id; + this.slug = slug; + this.title = title; + } + + @Override + public String getUrl() + { + if (this.getSource() == Source.CURSE_FORGE) + return "https://www.curseforge.com/minecraft/bukkit-plugins/" + this.slug; + else + return "https://dev.bukkit.org/projects/" + this.slug; + } + + private String description = null; + + @Override + public String getDescription() + { + if (this.description != null) + return this.description; + + Pair description = + URLUtils.getAsString("https://addons-ecs.forgesvc.net/api/v2/addon/" + this.id +"/description"); + + if (description.getLeft() != 200) + return "Failed to get description"; + + this.description = description.getRight(); + return this.description; + } + + +} From d3a2ed92d2bc681c36c0b7c8390cf322e726ff36 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 22:01:32 +0900 Subject: [PATCH 019/745] feat: KnownPluginsResolver --- .../TeamKunPluginManager.java | 2 ++ .../resolver/impl/KnownPluginsResolver.java | 36 +++++++++++++++++++ .../resolver/result/ResolveResult.java | 4 +++ 3 files changed, 42 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index f78f0e0b..1d8ea283 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -8,6 +8,7 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.KnownPluginsResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.Session; @@ -41,6 +42,7 @@ public void onEnable() resolver.getResolvers().add(new GitHubResolver()); resolver.getResolvers().add(new SpigotMCResolver()); resolver.getResolvers().add(new CurseBukkitResolver()); + resolver.getResolvers().add(new KnownPluginsResolver()); vault = new TokenVault(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java new file mode 100644 index 00000000..d334fa65 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java @@ -0,0 +1,36 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; +import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; + +public class KnownPluginsResolver implements BaseResolver +{ + + @Override + public ResolveResult resolve(String query) + { + KnownPluginEntry entry = KnownPlugins.getKnown(query); + + if (entry == null) + return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); + + return new SuccessResult(entry.getUrl(), null, null, ResolveResult.Source.LOCAL_KNOWN); + } + + @Override + public ResolveResult autoPickOnePlugin(MultiResult multiResult) + { + throw new UnsupportedOperationException("Why you call me?"); + } + + @Override + public boolean isValidResolver(String query) + { + return true; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java index 8b77d7e5..c1c357bc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -27,6 +27,10 @@ enum Source * @link https://curseforge.com/bukkit-plugins/ */ CURSE_FORGE, + /** + * ローカルの既知プラグイン + */ + LOCAL_KNOWN, /** * 直リンク */ From bf8cc9d14fd38298ffebb0f6709160444d5c6993 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 22:07:29 +0900 Subject: [PATCH 020/745] perf: Optimization of URLResolver --- .../resolver/PluginResolver.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 42662202..e6e961ae 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -6,10 +6,13 @@ import lombok.Value; import lombok.experimental.FieldDefaults; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import org.jetbrains.annotations.NotNull; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -35,9 +38,17 @@ public ResolveResult resolve(String query) { ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.UNKNOWN_ERROR, ResolveResult.Source.DIRECT); + URL url = toURL(query); + for (BaseResolver resolver : resolvers) { - if (!resolver.isValidResolver(query)) + if (resolver instanceof URLResolver) + { + URLResolver urlResolver = (URLResolver) resolver; + if (url != null && !isValidURLResolver(url, urlResolver)) + continue; + } + else if (!resolver.isValidResolver(query)) continue; ResolveResult result = resolver.resolve(query); @@ -53,4 +64,28 @@ public ResolveResult resolve(String query) return errorResult; } + + private static boolean isValidURLResolver(URL url, URLResolver resolver) + { + for (String host: resolver.getHosts()) + { + if (url.getHost().equalsIgnoreCase(host)) + return true; + } + + return false; + } + + private static URL toURL(String url) + { + try + { + return new URL(url); + } + catch (MalformedURLException e) + { + return null; + } + } + } From a9f90d2c348f73c073a98d63b49497c02b147a4a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 20 Mar 2022 22:11:05 +0900 Subject: [PATCH 021/745] fix: Mismatch logic --- .../lab/teamkunpluginmanager/resolver/PluginResolver.java | 7 +++++-- .../resolver/result/ResolveResult.java | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index e6e961ae..5a2af1cc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -36,7 +36,7 @@ public PluginResolver() */ public ResolveResult resolve(String query) { - ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.UNKNOWN_ERROR, ResolveResult.Source.DIRECT); + ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.UNKNOWN); URL url = toURL(query); @@ -55,7 +55,10 @@ else if (!resolver.isValidResolver(query)) if (result instanceof ErrorResult) { - errorResult = result; + ErrorResult error = (ErrorResult) result; + + if (error.getCause() != ErrorResult.ErrorCause.RESOLVER_MISMATCH) + errorResult = result; continue; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java index c1c357bc..df18e039 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -34,6 +34,10 @@ enum Source /** * 直リンク */ - DIRECT + DIRECT, + /** + * 不明 + */ + UNKNOWN } } From 45e5739066b5402cab85aed18bc46424c2f5909e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 02:55:15 +0900 Subject: [PATCH 022/745] feat: Impl resolver --- .../TeamKunPluginManager.java | 8 +-- .../resolver/PluginResolver.java | 54 ++++++++++++++----- .../resolver/QueryContext.java | 16 ++++++ .../resolver/QueryParser.java | 32 +++++++++++ .../resolver/result/PipeResult.java | 14 +++++ 5 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 1d8ea283..ed0b1fac 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -39,10 +39,10 @@ public void onEnable() config = getConfig(); functional = new Say2Functional(this); resolver = new PluginResolver(); - resolver.getResolvers().add(new GitHubResolver()); - resolver.getResolvers().add(new SpigotMCResolver()); - resolver.getResolvers().add(new CurseBukkitResolver()); - resolver.getResolvers().add(new KnownPluginsResolver()); + resolver.addResolver(new GitHubResolver(), "github", "gh"); + resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); + resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge"); + resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); vault = new TokenVault(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 5a2af1cc..ab464444 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -1,33 +1,38 @@ package net.kunmc.lab.teamkunpluginmanager.resolver; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.Value; -import lombok.experimental.FieldDefaults; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import org.jetbrains.annotations.NotNull; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * プラグインを解決するクラス */ -@Getter -@Setter public class PluginResolver { - private final List resolvers; + private final HashMap resolvers; // TODO: LIST public PluginResolver() { - this.resolvers = new ArrayList<>(); + this.resolvers = new HashMap<>(); + } + + public void addResolver(BaseResolver resolver, String... names) + { + for (String name : names) + { + if (name.equalsIgnoreCase("http") || name.equalsIgnoreCase("https")) + throw new IllegalArgumentException("HTTP and HTTPS are reserved names."); + + resolvers.put(name.toLowerCase(), resolver); + } } /** @@ -36,9 +41,30 @@ public PluginResolver() */ public ResolveResult resolve(String query) { - ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.UNKNOWN); + QueryContext context = QueryParser.parseQuery(query); + + if (context.getResolverName() == null) + return actuallyResolve(new ArrayList<>(resolvers.values()), context); + + BaseResolver resolver = resolvers.get(context.getResolverName().toLowerCase()); + + if (resolver == null || !resolver.isValidResolver(query)) + return new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); + + return resolver.resolve(query); + } + + private ResolveResult actuallyResolve(List resolvers, QueryContext queryContext) + { + URL url = null; + + String resolverName = queryContext.getResolverName(); + if (resolverName != null) + url = toURL(queryContext.getQuery()); + + ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); - URL url = toURL(query); + String queryString = queryContext.getQuery(); for (BaseResolver resolver : resolvers) { @@ -48,10 +74,10 @@ public ResolveResult resolve(String query) if (url != null && !isValidURLResolver(url, urlResolver)) continue; } - else if (!resolver.isValidResolver(query)) + else if (!resolver.isValidResolver(queryString)) continue; - ResolveResult result = resolver.resolve(query); + ResolveResult result = resolver.resolve(queryString); if (result instanceof ErrorResult) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java new file mode 100644 index 00000000..feaf1d98 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver; + +import lombok.Value; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Value +class QueryContext +{ + @Nullable + String resolverName; + @NotNull + String query; + @Nullable + String version; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java new file mode 100644 index 00000000..00c32397 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java @@ -0,0 +1,32 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver; + +import org.apache.commons.lang.StringUtils; +import org.jetbrains.annotations.NotNull; + +public class QueryParser +{ + private static final String resolverNameQuerySeparator = ">"; + private static final String queryVersionSeparator = "="; + + public static QueryContext parseQuery(@NotNull String query) + { + if (query.isEmpty()) + throw new IllegalArgumentException("Query cannot be empty"); + + String[] queryParts = StringUtils.split(query, resolverNameQuerySeparator, 2); + + String resolverName = null; + if (queryParts.length >= 2) + resolverName = queryParts[0]; + + String version = null; + + int versionSeparatorIndex = queryParts[1].lastIndexOf(queryVersionSeparator); + if (versionSeparatorIndex != -1) + version = queryParts[1].substring(versionSeparatorIndex + 1); + + String plainQuery = queryParts[1].substring(0, versionSeparatorIndex); + + return new QueryContext(resolverName, plainQuery, version); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java new file mode 100644 index 00000000..01f20e66 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java @@ -0,0 +1,14 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.result; + +import lombok.Value; +import org.jetbrains.annotations.NotNull; + +/** + * 次のリゾルバに処理を任せる. + */ +@Value +public class PipeResult implements ResolveResult +{ + @NotNull + String query; +} From 723390c2bb7be7d51612f6f19e679b0195904084 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 03:06:11 +0900 Subject: [PATCH 023/745] feat: Multi result --- .../resolver/PluginResolver.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index ab464444..41a03637 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -8,16 +8,18 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * プラグインを解決するクラス */ public class PluginResolver { - private final HashMap resolvers; // TODO: LIST + private final HashMap> resolvers; public PluginResolver() { @@ -31,7 +33,12 @@ public void addResolver(BaseResolver resolver, String... names) if (name.equalsIgnoreCase("http") || name.equalsIgnoreCase("https")) throw new IllegalArgumentException("HTTP and HTTPS are reserved names."); - resolvers.put(name.toLowerCase(), resolver); + List resolverList = resolvers.get(name.toLowerCase()); + + if (resolverList == null) + resolvers.put(name.toLowerCase(), new ArrayList<>(Collections.singletonList(resolver))); + else + resolverList.add(resolver); } } @@ -44,14 +51,16 @@ public ResolveResult resolve(String query) QueryContext context = QueryParser.parseQuery(query); if (context.getResolverName() == null) - return actuallyResolve(new ArrayList<>(resolvers.values()), context); - - BaseResolver resolver = resolvers.get(context.getResolverName().toLowerCase()); + { + return actuallyResolve(resolvers.values().stream() + .flatMap(List::stream) + .collect(Collectors.toList()), context); + } - if (resolver == null || !resolver.isValidResolver(query)) + if (!resolvers.containsKey(context.getResolverName().toLowerCase())) return new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); - return resolver.resolve(query); + return actuallyResolve(resolvers.get(context.getResolverName().toLowerCase()), context); } private ResolveResult actuallyResolve(List resolvers, QueryContext queryContext) From 34b91fc66dda5fd6bb3fb98c0d19242806786ec0 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 04:30:24 +0900 Subject: [PATCH 024/745] fix: Skip version --- .../teamkunpluginmanager/resolver/PluginResolver.java | 10 ++++++++++ .../lab/teamkunpluginmanager/resolver/QueryParser.java | 10 +++++++--- .../kunmc/lab/teamkunpluginmanager/utils/URLUtils.java | 9 ++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 41a03637..f3100831 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -67,6 +67,8 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext { URL url = null; + List finishedResolvers = new ArrayList<>(); + String resolverName = queryContext.getResolverName(); if (resolverName != null) url = toURL(queryContext.getQuery()); @@ -77,6 +79,11 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext for (BaseResolver resolver : resolvers) { + if (finishedResolvers.contains(resolver)) + continue; + + finishedResolvers.add(resolver); + if (resolver instanceof URLResolver) { URLResolver urlResolver = (URLResolver) resolver; @@ -92,8 +99,11 @@ else if (!resolver.isValidResolver(queryString)) { ErrorResult error = (ErrorResult) result; + if (error.getCause() != ErrorResult.ErrorCause.PLUGIN_NOT_FOUND && error.getCause() != ErrorResult.ErrorCause.INVALID_QUERY) + return error; if (error.getCause() != ErrorResult.ErrorCause.RESOLVER_MISMATCH) errorResult = result; + continue; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java index 00c32397..d39d298d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java @@ -21,11 +21,15 @@ public static QueryContext parseQuery(@NotNull String query) String version = null; - int versionSeparatorIndex = queryParts[1].lastIndexOf(queryVersionSeparator); + String part = queryParts[queryParts.length - 1]; + + int versionSeparatorIndex = part.lastIndexOf(queryVersionSeparator); if (versionSeparatorIndex != -1) - version = queryParts[1].substring(versionSeparatorIndex + 1); + version = part.substring(versionSeparatorIndex + 1); - String plainQuery = queryParts[1].substring(0, versionSeparatorIndex); + String plainQuery = part; + if (version != null) + plainQuery = part.substring(0, versionSeparatorIndex); return new QueryContext(resolverName, plainQuery, version); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java index d3d05268..1cd55e49 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java @@ -86,7 +86,14 @@ public static Pair getAsString(String urlString) connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); connection.connect(); - return new Pair<>(connection.getResponseCode(), IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8)); + try + { + return new Pair<>(connection.getResponseCode(), IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8)); + } + catch (IOException e) + { + return new Pair<>(connection.getResponseCode(), null); + } } catch (Exception e) From 740dfe17aa9e4e7d7d0bbdbc4ad89ae7f2074274 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 04:31:16 +0900 Subject: [PATCH 025/745] fix: download url --- .../resolver/impl/SpigotMCSuccessResult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java index 7ec05aba..e691e5df 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java @@ -27,7 +27,7 @@ public class SpigotMCSuccessResult extends SuccessResult implements MarketplaceR public SpigotMCSuccessResult(@Nullable String version, @NotNull String title, long id, @NotNull String description, @NotNull List versions) { super("https://apple.api.spiget.org/v2/resources/" + id + - (version != null ? "versions/" + version : "") + "/download", + (version != null ? "/versions/" + version : "") + "/download", null, version, Source.SPIGOT_MC); this.title = title; this.description = description; From f5e1e57faff9dcae290c29e2bffceef6abbe8234 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 04:38:47 +0900 Subject: [PATCH 026/745] fix: Invalid regex --- .../lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java index 2636c25e..6896ac54 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java @@ -25,7 +25,7 @@ public class GitHubResolver implements URLResolver private static final String GITHUB_REPO_RELEASE_NAME_URL = GITHUB_REPO_RELEASES_URL + "/tags/%s"; private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("^/(?[a-zA-Z\\d]" + - "(?[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38}/(?[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100}))" + + "(?[a-zA-Z\\d]|-(?=[a-zA-Z\\d]){0,38})/(?[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100}))" + "(?:/(?:tags|releases(?:/(?:tag/(?[^/]+)/?$|download/(?[^/]+)/" + "(?[^/]+)))?))?/?$"); From 97e39cff9ce63d57197b244aa2649b261c7c0f27 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 04:40:58 +0900 Subject: [PATCH 027/745] feat: Vault check --- .../java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java index 1cd55e49..e278c9fd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java @@ -79,7 +79,7 @@ public static Pair getAsString(String urlString) URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); - if (url.getHost().equals("api.github.com")) + if (url.getHost().equals("api.github.com") && !TeamKunPluginManager.vault.getToken().isEmpty()) connection.setRequestProperty("Authorization", "token " + TeamKunPluginManager.vault.getToken()); if (url.getHost().equals("file.io")) connection.setRequestProperty("Referer", "https://www.file.io/"); From 94df0dd3c017fa55118972b0d05269fafd1ca277 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 04:41:10 +0900 Subject: [PATCH 028/745] fix: Invalid regex of owner --- .../teamkunpluginmanager/resolver/impl/GitHubResolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java index 6896ac54..7094f49d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java @@ -24,8 +24,8 @@ public class GitHubResolver implements URLResolver private static final String GITHUB_REPO_RELEASES_URL = "https://api.github.com/repos/%s/releases"; private static final String GITHUB_REPO_RELEASE_NAME_URL = GITHUB_REPO_RELEASES_URL + "/tags/%s"; - private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("^/(?[a-zA-Z\\d]" + - "(?[a-zA-Z\\d]|-(?=[a-zA-Z\\d]){0,38})/(?[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100}))" + + private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("^/(?(?[a-zA-Z\\d]" + + "(?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38})/(?[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100}))" + "(?:/(?:tags|releases(?:/(?:tag/(?[^/]+)/?$|download/(?[^/]+)/" + "(?[^/]+)))?))?/?$"); From 9bb5898ba93fbb28b45aca64469b23045298517a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 18:00:45 +0900 Subject: [PATCH 029/745] fix: Version separate --- .../lab/teamkunpluginmanager/resolver/QueryParser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java index d39d298d..de4217b6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java @@ -6,7 +6,7 @@ public class QueryParser { private static final String resolverNameQuerySeparator = ">"; - private static final String queryVersionSeparator = "="; + private static final String versionEqualQuerySeparator = "=="; public static QueryContext parseQuery(@NotNull String query) { @@ -23,9 +23,9 @@ public static QueryContext parseQuery(@NotNull String query) String part = queryParts[queryParts.length - 1]; - int versionSeparatorIndex = part.lastIndexOf(queryVersionSeparator); + int versionSeparatorIndex = part.lastIndexOf(versionEqualQuerySeparator); if (versionSeparatorIndex != -1) - version = part.substring(versionSeparatorIndex + 1); + version = part.substring(versionSeparatorIndex + 2); String plainQuery = part; if (version != null) From 581f691efb9373dbf2aa03d010b49e934cc11391 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 18:56:49 +0900 Subject: [PATCH 030/745] refactor: GitHubResolver => GitHubURLResolver --- .../kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java | 4 ++-- .../impl/{GitHubResolver.java => GitHubURLResolver.java} | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/{GitHubResolver.java => GitHubURLResolver.java} (98%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index ed0b1fac..6108cc71 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -7,7 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.KnownPluginsResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; @@ -39,7 +39,7 @@ public void onEnable() config = getConfig(); functional = new Say2Functional(this); resolver = new PluginResolver(); - resolver.addResolver(new GitHubResolver(), "github", "gh"); + resolver.addResolver(new GitHubURLResolver(), "github", "gh"); resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge"); resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java similarity index 98% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 7094f49d..153ceef0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -12,14 +12,12 @@ import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class GitHubResolver implements URLResolver +public class GitHubURLResolver implements URLResolver { private static final String GITHUB_REPO_RELEASES_URL = "https://api.github.com/repos/%s/releases"; private static final String GITHUB_REPO_RELEASE_NAME_URL = GITHUB_REPO_RELEASES_URL + "/tags/%s"; From 8a364b8f297feef9fa89be4e19a92bfcd90721d3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:19:50 +0900 Subject: [PATCH 031/745] refactor: String -> QueryContext --- .../resolver/PluginResolver.java | 12 ++--- .../resolver/QueryContext.java | 47 +++++++++++++++++-- .../resolver/QueryParser.java | 36 -------------- .../resolver/impl/CurseBukkitResolver.java | 12 +++-- .../resolver/impl/GitHubURLResolver.java | 7 +-- .../resolver/impl/KnownPluginsResolver.java | 8 ++-- .../resolver/impl/SpigotMCResolver.java | 5 +- .../resolver/interfaces/BaseResolver.java | 6 ++- .../resolver/interfaces/URLResolver.java | 5 +- .../resolver/result/PipeResult.java | 3 +- 10 files changed, 77 insertions(+), 64 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index f3100831..9d03b9ef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -3,6 +3,7 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.PipeResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import java.net.MalformedURLException; @@ -11,7 +12,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; /** @@ -48,7 +48,7 @@ public void addResolver(BaseResolver resolver, String... names) */ public ResolveResult resolve(String query) { - QueryContext context = QueryParser.parseQuery(query); + QueryContext context = QueryContext.fromString(query); if (context.getResolverName() == null) { @@ -75,8 +75,6 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); - String queryString = queryContext.getQuery(); - for (BaseResolver resolver : resolvers) { if (finishedResolvers.contains(resolver)) @@ -90,10 +88,10 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext if (url != null && !isValidURLResolver(url, urlResolver)) continue; } - else if (!resolver.isValidResolver(queryString)) + else if (!resolver.isValidResolver(queryContext)) continue; - ResolveResult result = resolver.resolve(queryString); + ResolveResult result = resolver.resolve(queryContext); if (result instanceof ErrorResult) { @@ -106,6 +104,8 @@ else if (!resolver.isValidResolver(queryString)) continue; } + else if (result instanceof PipeResult) + continue; return result; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java index feaf1d98..bfe4ba2e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java @@ -1,11 +1,17 @@ package net.kunmc.lab.teamkunpluginmanager.resolver; -import lombok.Value; +import lombok.Builder; +import lombok.Data; +import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -@Value -class QueryContext +/** + * 複数の情報を含んだクエリ + */ +@Data +@Builder +public class QueryContext { @Nullable String resolverName; @@ -13,4 +19,39 @@ class QueryContext String query; @Nullable String version; + + private static final String resolverNameQuerySeparator = ">"; + private static final String versionEqualQuerySeparator = "=="; + + /** + * クエリ文字列からQueryContextをパースする + * + * @param query クエリ文字列 + * @return QueryContext + */ + public static QueryContext fromString(@NotNull String query) + { + if (query.isEmpty()) + throw new IllegalArgumentException("Query cannot be empty"); + + String[] queryParts = StringUtils.split(query, resolverNameQuerySeparator, 2); + + String resolverName = null; + if (queryParts.length >= 2) + resolverName = queryParts[0]; + + String version = null; + + String part = queryParts[queryParts.length - 1]; + + int versionSeparatorIndex = part.lastIndexOf(versionEqualQuerySeparator); + if (versionSeparatorIndex != -1) + version = part.substring(versionSeparatorIndex + 2); + + String plainQuery = part; + if (version != null) + plainQuery = part.substring(0, versionSeparatorIndex); + + return new QueryContext(resolverName, plainQuery, version); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java deleted file mode 100644 index de4217b6..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryParser.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver; - -import org.apache.commons.lang.StringUtils; -import org.jetbrains.annotations.NotNull; - -public class QueryParser -{ - private static final String resolverNameQuerySeparator = ">"; - private static final String versionEqualQuerySeparator = "=="; - - public static QueryContext parseQuery(@NotNull String query) - { - if (query.isEmpty()) - throw new IllegalArgumentException("Query cannot be empty"); - - String[] queryParts = StringUtils.split(query, resolverNameQuerySeparator, 2); - - String resolverName = null; - if (queryParts.length >= 2) - resolverName = queryParts[0]; - - String version = null; - - String part = queryParts[queryParts.length - 1]; - - int versionSeparatorIndex = part.lastIndexOf(versionEqualQuerySeparator); - if (versionSeparatorIndex != -1) - version = part.substring(versionSeparatorIndex + 2); - - String plainQuery = part; - if (version != null) - plainQuery = part.substring(0, versionSeparatorIndex); - - return new QueryContext(resolverName, plainQuery, version); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 7f0e72c7..9ff916e9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -4,6 +4,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; @@ -23,18 +24,19 @@ public class CurseBukkitResolver implements URLResolver private static final Pattern BUKKIT_PATTERN = Pattern.compile("^/projects/" + basePatterns); private static final Pattern CURSE_PATTERN = Pattern.compile("^/minecraft/bukkit-plugins/" + basePatterns); private static final String BUKKIT_API_VERSION = StringUtils.split(Bukkit.getVersion(), "-")[0]; + @Override - public ResolveResult resolve(String query) + public ResolveResult resolve(QueryContext query) { - boolean bukkitFlag = StringUtils.containsIgnoreCase(query, "bukkit.org"); + boolean bukkitFlag = StringUtils.containsIgnoreCase(query.getQuery(), "bukkit.org"); - ResolveResult.Source errorSource = bukkitFlag ? ResolveResult.Source.DEV_BUKKIT : ResolveResult.Source.CURSE_FORGE; + ResolveResult.Source errorSource = bukkitFlag ? ResolveResult.Source.DEV_BUKKIT: ResolveResult.Source.CURSE_FORGE; Matcher matcher; if (bukkitFlag) - matcher = urlMatcher(BUKKIT_PATTERN, query); + matcher = urlMatcher(BUKKIT_PATTERN, query.getQuery()); else - matcher = urlMatcher(CURSE_PATTERN, query); + matcher = urlMatcher(CURSE_PATTERN, query.getQuery()); String slug = null; String version = null; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 153ceef0..5de7c3fe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -4,6 +4,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; @@ -28,9 +29,9 @@ public class GitHubURLResolver implements URLResolver "(?[^/]+)))?))?/?$"); @Override - public ResolveResult resolve(String query) + public ResolveResult resolve(QueryContext query) { - Matcher matcher = urlMatcher(GITHUB_REPO_PATTERN, query); + Matcher matcher = urlMatcher(GITHUB_REPO_PATTERN, query.getQuery()); if (matcher == null) return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); @@ -50,7 +51,7 @@ public ResolveResult resolve(String query) String repoNameGroup = matcher.group("repoName"); if (fileNameGroup != null && !fileNameGroup.isEmpty()) // URLが自己解決。 - return new SuccessResult(query, ResolveResult.Source.GITHUB); + return new SuccessResult(query.getQuery(), ResolveResult.Source.GITHUB); if (!repositoryGroup.isEmpty()) repository = repositoryGroup; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java index d334fa65..51f5c04e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java @@ -2,6 +2,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; @@ -10,11 +11,10 @@ public class KnownPluginsResolver implements BaseResolver { - @Override - public ResolveResult resolve(String query) + public ResolveResult resolve(QueryContext query) { - KnownPluginEntry entry = KnownPlugins.getKnown(query); + KnownPluginEntry entry = KnownPlugins.getKnown(query.getQuery()); if (entry == null) return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); @@ -29,7 +29,7 @@ public ResolveResult autoPickOnePlugin(MultiResult multiResult) } @Override - public boolean isValidResolver(String query) + public boolean isValidResolver(QueryContext query) { return true; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 8d51d957..993cf801 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -3,6 +3,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; @@ -24,9 +25,9 @@ public class SpigotMCResolver implements URLResolver private static final Pattern PATTERN = Pattern.compile("/resources/([\\w-]+\\.?(?[\\d]+))(?:/|/updates/?|/downloads/?|(?:update/?\\?update=|download/?\\?version=)(?\\d+))?"); @Override - public ResolveResult resolve(String query) + public ResolveResult resolve(QueryContext query) { - Matcher matcher = urlMatcher(PATTERN, query); + Matcher matcher = urlMatcher(PATTERN, query.getQuery()); String id = null; String version = null; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java index 97772bea..b63f9746 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; @@ -15,7 +16,7 @@ public interface BaseResolver * @param query クエリ * @return クエリの解決結果 */ - ResolveResult resolve(String query); + ResolveResult resolve(QueryContext query); /** * 複数のリソースを自動で一意に特定します。 @@ -26,10 +27,11 @@ public interface BaseResolver /** * 与えられたクエリが解決可能かどうかを返します。 + * * @param query クエリ * @return クエリが解決可能ならばtrue */ - boolean isValidResolver(String query); + boolean isValidResolver(QueryContext query); /** * MultiResult から最初の要素を取得します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 60b026ce..76e05cc1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; @@ -20,11 +21,11 @@ public interface URLResolver extends BaseResolver String[] getHosts(); @Override - default boolean isValidResolver(String query) + default boolean isValidResolver(QueryContext query) { try { - URL url = new URL(query); + URL url = new URL(query.getQuery()); if (getHosts().length == 0) return true; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java index 01f20e66..a3a26ccc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import org.jetbrains.annotations.NotNull; /** @@ -10,5 +11,5 @@ public class PipeResult implements ResolveResult { @NotNull - String query; + QueryContext query; } From de5ef54605a005da4af585b2ee6d01d9dfb4b9b9 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:20:20 +0900 Subject: [PATCH 032/745] feat: Version specify of github --- .../resolver/impl/GitHubURLResolver.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 5de7c3fe..d7780ea5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -12,6 +12,7 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -71,7 +72,7 @@ else if (tagGroup != null && !tagGroup.isEmpty()) if (repository == null) return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); - return processGitHubAPI(owner, repositoryName, repository, tag); + return processGitHubAPI(owner, repositoryName, repository, tag, query.getVersion()); } @Override @@ -80,7 +81,7 @@ public ResolveResult autoPickOnePlugin(MultiResult multiResult) return autoPickFirst(multiResult, ResolveResult.Source.GITHUB); } - private ResolveResult processGitHubAPI(String owner, String repositoryName, String repository, String tag) + private ResolveResult processGitHubAPI(String owner, String repositoryName, String repository, String tag, @Nullable String version) { String apiURL; if (tag != null) @@ -103,26 +104,37 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri { JsonObject jsonObject = gson.fromJson(json, JsonObject.class); - return buildResultSingle(owner, repositoryName, jsonObject); + return buildResultSingle(owner, repositoryName, jsonObject, version); } JsonArray jsonArray = gson.fromJson(json, JsonArray.class); List results = new ArrayList<>(); + boolean isFound = false; for (JsonElement jsonElement : jsonArray) { - ResolveResult result = buildResultSingle(owner, repositoryName, jsonElement.getAsJsonObject()); + ResolveResult result = buildResultSingle(owner, repositoryName, jsonElement.getAsJsonObject(), version); if (result instanceof ErrorResult) + { + if (((ErrorResult) result).getCause() == ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND) + isFound = true; continue; + } results.add(result); } + if (results.isEmpty() && isFound) + return new ErrorResult( + ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("指定されたバージョンが見つかりませんでした。"), + ResolveResult.Source.GITHUB + ); + return new MultiResult(results.toArray(new ResolveResult[0])); } - private ResolveResult buildResultSingle(String owner, String repositoryName, JsonObject object) + private ResolveResult buildResultSingle(String owner, String repositoryName, JsonObject object, @Nullable String queryVersion) { List results = new ArrayList<>(); @@ -132,6 +144,10 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso long releaseId = object.get("id").getAsLong(); String htmlUrl = object.get("html_url").getAsString(); + if (queryVersion != null && !queryVersion.equalsIgnoreCase(version) && + ("v" + queryVersion).equalsIgnoreCase(queryVersion) && !queryVersion.equalsIgnoreCase("v" + queryVersion)) + return new ErrorResult(ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + JsonArray assets = object.getAsJsonArray("assets"); if (assets.size() == 0) From 26315d73601a75671c80a047d4eaa2c4d73cbb28 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:52:54 +0900 Subject: [PATCH 033/745] fix: Version specify of github --- .../teamkunpluginmanager/resolver/impl/GitHubURLResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index d7780ea5..ca3ea4b4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -145,7 +145,7 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso String htmlUrl = object.get("html_url").getAsString(); if (queryVersion != null && !queryVersion.equalsIgnoreCase(version) && - ("v" + queryVersion).equalsIgnoreCase(queryVersion) && !queryVersion.equalsIgnoreCase("v" + queryVersion)) + !("v" + queryVersion).equalsIgnoreCase(queryVersion) && !queryVersion.equalsIgnoreCase("v" + queryVersion)) return new ErrorResult(ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); JsonArray assets = object.getAsJsonArray("assets"); From 1fa11ecde2fbc3d6efcd6bb7a0ce92a41514923b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:53:11 +0900 Subject: [PATCH 034/745] feat: OmittedGitHubResolver --- .../resolver/impl/OmittedGitHubResolver.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java new file mode 100644 index 00000000..92d1844a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java @@ -0,0 +1,33 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.PipeResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import org.apache.commons.lang.StringUtils; + +public class OmittedGitHubResolver implements BaseResolver +{ + private static final String DELIMITER = "/"; + + @Override + public ResolveResult resolve(QueryContext query) + { + query.setQuery("https://github.com/" + query.getQuery()); + return new PipeResult(query); + } + + @Override + public ResolveResult autoPickOnePlugin(MultiResult multiResult) + { + throw new UnsupportedOperationException("Why you call me?"); + } + + @Override + public boolean isValidResolver(QueryContext query) + { + String[] split = StringUtils.split(query.getQuery(), DELIMITER); + return split.length == 2 && !StringUtils.isEmpty(split[0]) && !StringUtils.isEmpty(split[1]); + } +} From 86bf2e1b6786f59285ce7936917d3a9e8b79de4b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 21:55:57 +0900 Subject: [PATCH 035/745] fix: Null check --- .../resolver/impl/CurseBukkitResolver.java | 6 ++++-- .../resolver/impl/SpigotMCResolver.java | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 9ff916e9..25f6b10a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -11,7 +11,6 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.Nullable; @@ -23,7 +22,7 @@ public class CurseBukkitResolver implements URLResolver private static final String basePatterns = "(?\\w+)(/files(/(?\\d+))?(/download)?)?/?$"; private static final Pattern BUKKIT_PATTERN = Pattern.compile("^/projects/" + basePatterns); private static final Pattern CURSE_PATTERN = Pattern.compile("^/minecraft/bukkit-plugins/" + basePatterns); - private static final String BUKKIT_API_VERSION = StringUtils.split(Bukkit.getVersion(), "-")[0]; + private static final String BUKKIT_API_VERSION = StringUtils.split("1.16.5", "-")[0]; @Override public ResolveResult resolve(QueryContext query) @@ -38,6 +37,9 @@ public ResolveResult resolve(QueryContext query) else matcher = urlMatcher(CURSE_PATTERN, query.getQuery()); + if (matcher == null) + return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, errorSource); + String slug = null; String version = null; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 993cf801..19c8b72d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -29,6 +29,9 @@ public ResolveResult resolve(QueryContext query) { Matcher matcher = urlMatcher(PATTERN, query.getQuery()); + if (matcher == null) + return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); + String id = null; String version = null; From 568c9c061958d714180dc58e9b9657b4ab4e4565 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 21 Mar 2022 22:16:13 +0900 Subject: [PATCH 036/745] fix: Keyword of dev bukit --- .../kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 6108cc71..80f3e4bf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -41,7 +41,7 @@ public void onEnable() resolver = new PluginResolver(); resolver.addResolver(new GitHubURLResolver(), "github", "gh"); resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); - resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge"); + resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); vault = new TokenVault(); From ebd3bdfb21aa41d723692d3a5ba45fb3f09c53b2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 22 Mar 2022 00:51:42 +0900 Subject: [PATCH 037/745] feat: On error resolver --- .../resolver/PluginResolver.java | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 9d03b9ef..7a388eb9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -20,10 +20,12 @@ public class PluginResolver { private final HashMap> resolvers; + private final List onNotFoundResolvers; public PluginResolver() { this.resolvers = new HashMap<>(); + this.onNotFoundResolvers = new ArrayList<>(); } public void addResolver(BaseResolver resolver, String... names) @@ -42,8 +44,14 @@ public void addResolver(BaseResolver resolver, String... names) } } + public void addOnNotFoundResolver(BaseResolver resolver) + { + onNotFoundResolvers.add(resolver); + } + /** * クエリを使用してプラグインを解決する + * * @param query クエリ */ public ResolveResult resolve(String query) @@ -67,14 +75,28 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext { URL url = null; - List finishedResolvers = new ArrayList<>(); - String resolverName = queryContext.getResolverName(); if (resolverName != null) url = toURL(queryContext.getQuery()); - ResolveResult errorResult = new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); + ResolveResult result = resolves(resolvers, queryContext, url); + + + if (result instanceof ErrorResult) + { + ErrorResult error = (ErrorResult) result; + if (error.getCause() != ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND) + result = resolves(onNotFoundResolvers, queryContext, url); + } + + return result; + } + + private ResolveResult resolves(List resolvers, QueryContext queryContext, URL url) + { + List finishedResolvers = new ArrayList<>(); + ErrorResult errorResult = new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); for (BaseResolver resolver : resolvers) { if (finishedResolvers.contains(resolver)) @@ -82,30 +104,21 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext finishedResolvers.add(resolver); - if (resolver instanceof URLResolver) - { - URLResolver urlResolver = (URLResolver) resolver; - if (url != null && !isValidURLResolver(url, urlResolver)) - continue; - } - else if (!resolver.isValidResolver(queryContext)) - continue; - - ResolveResult result = resolver.resolve(queryContext); + ResolveResult result = actuallyResolve(resolver, queryContext, url); - if (result instanceof ErrorResult) + if (result == null || result instanceof PipeResult) + continue; + else if (result instanceof ErrorResult) { ErrorResult error = (ErrorResult) result; if (error.getCause() != ErrorResult.ErrorCause.PLUGIN_NOT_FOUND && error.getCause() != ErrorResult.ErrorCause.INVALID_QUERY) return error; if (error.getCause() != ErrorResult.ErrorCause.RESOLVER_MISMATCH) - errorResult = result; + errorResult = (ErrorResult) result; continue; } - else if (result instanceof PipeResult) - continue; return result; } @@ -113,9 +126,23 @@ else if (result instanceof PipeResult) return errorResult; } + private ResolveResult actuallyResolve(BaseResolver resolver, QueryContext queryContext, URL url) + { + if (resolver instanceof URLResolver) + { + URLResolver urlResolver = (URLResolver) resolver; + if (url != null && !isValidURLResolver(url, urlResolver)) + return null; + } + else if (!resolver.isValidResolver(queryContext)) + return null; + + return resolver.resolve(queryContext); + } + private static boolean isValidURLResolver(URL url, URLResolver resolver) { - for (String host: resolver.getHosts()) + for (String host : resolver.getHosts()) { if (url.getHost().equalsIgnoreCase(host)) return true; From 3076fbbabaa9795a82c6cbd72617d1c6b534dd6c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 22 Mar 2022 22:57:00 +0900 Subject: [PATCH 038/745] feat: Bruteforce github resolver --- .../TeamKunPluginManager.java | 9 ++- .../impl/BruteforceGitHubResolver.java | 71 +++++++++++++++++ .../resolver/PluginResolverTest.java | 79 +++++++++++++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java create mode 100644 src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 80f3e4bf..b3a62861 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -6,9 +6,11 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.BruteforceGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.KnownPluginsResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.Session; @@ -39,11 +41,16 @@ public void onEnable() config = getConfig(); functional = new Say2Functional(this); resolver = new PluginResolver(); - resolver.addResolver(new GitHubURLResolver(), "github", "gh"); + + GitHubURLResolver githubResolver = new GitHubURLResolver(); + resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); + resolver.addResolver(githubResolver, "github", "gh"); resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); + resolver.addOnNotFoundResolver(new BruteforceGitHubResolver(this, githubResolver)); + vault = new TokenVault(); Bukkit.getPluginCommand("kunpluginmanager").setExecutor(new CommandMain()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java new file mode 100644 index 00000000..05a3a8a5 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java @@ -0,0 +1,71 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; + +import java.util.List; + +@AllArgsConstructor +public class BruteforceGitHubResolver implements BaseResolver +{ + private final TeamKunPluginManager plugin; + private final GitHubURLResolver gitHubURLResolver; + + @Override + public ResolveResult resolve(QueryContext query) + { + + Object obj = plugin.getConfig().get("gitHubName"); + + if (obj instanceof String) // Legacy support + { + query.setQuery("https://github.com/" + obj + "/" + query.getQuery()); + return gitHubURLResolver.resolve(query); + } + + if (!(obj instanceof List) && !(obj instanceof String[])) + throw new IllegalArgumentException("Invalid config: gitHubName: config must be a string or a list of strings"); + + ResolveResult result = new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + + for (String str : plugin.getConfig().getStringList("gitHubName")) + { + + query.setQuery("https://github.com/" + str + "/" + query.getQuery()); + result = gitHubURLResolver.resolve(query); + + if (result instanceof ErrorResult) + { + ErrorResult error = (ErrorResult) result; + + if (error.getCause() == ErrorResult.ErrorCause.INVALID_QUERY) + return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + + if (error.getCause() != ErrorResult.ErrorCause.PLUGIN_NOT_FOUND) + return error; + continue; + } + + return result; + } + + return result; + } + + @Override + public ResolveResult autoPickOnePlugin(MultiResult multiResult) + { + return null; + } + + @Override + public boolean isValidResolver(QueryContext query) + { + return true; + } +} diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java new file mode 100644 index 00000000..c94e6a08 --- /dev/null +++ b/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java @@ -0,0 +1,79 @@ +package net.kunmc.lab.teamkunpluginmanager.resolver; + +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.TokenVault; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class PluginResolverTest +{ + public static void printResult(ResolveResult result, boolean first) + { + if (result instanceof SuccessResult) + { + SuccessResult successResult = (SuccessResult) result; + System.out.println(successResult.getFileName() + ":" + successResult.getDownloadUrl() + " @" + successResult.getVersion()); + + if (result instanceof GitHubSuccessResult) + { + GitHubSuccessResult gitHubSuccessResult = (GitHubSuccessResult) result; + System.out.println("GitHub: " + gitHubSuccessResult.getOwner() + "/" + gitHubSuccessResult.getRepoName()); + System.out.println("GitHub: " + gitHubSuccessResult.getTitle() + ": " + gitHubSuccessResult.getReleaseName()); + System.out.println("GitHub: " + gitHubSuccessResult.getUrl()); + } + } + else if (result instanceof ErrorResult) + { + ErrorResult errorResult = (ErrorResult) result; + System.out.println(errorResult.getCause()); + System.out.println(errorResult.getCause().getMessage()); + System.out.println(errorResult.getSource()); + } + else if (result instanceof MultiResult) + { + MultiResult multiResult = (MultiResult) result; + for (ResolveResult resolveResult : multiResult.getResults()) + printResult(resolveResult, false); + } + } + + @Before + public void init() + { + TeamKunPluginManager.vault = new TokenVault(); + } + + @Ignore + @Test + public void resolveTest() + { + + PluginResolver resolver = new PluginResolver(); + resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); + resolver.addResolver(new GitHubURLResolver(), "github", "gh"); + resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); + // resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); + + // resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); + + + ResolveResult result; + // result = resolver.resolve("https://www.spigotmc.org/resources/coreprotect.8631/"); + // printResult(result, true); + + // result = resolver.resolve("spigot>https://github.com/TeamKUN/TeamKUNPluginManager==v1.0"); + //result = resolver.resolve("TeamKUN/TeamKUNPluginManager==v1.0"); + result = resolver.resolve("bukkit>coreprotect==v1.0"); + + printResult(result, true); + } +} From 7aa82b58929e2bae852398800573cf33a64ebbe2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:49:29 +0900 Subject: [PATCH 039/745] fix: Change word sentence --- .../TeamKunPluginManager.java | 2 +- .../resolver/result/ErrorResult.java | 18 ++++++++++----- .../resolver/result/ResolveResult.java | 22 +++++++++++++------ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index b3a62861..546f43b4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -30,7 +30,7 @@ public final class TeamKunPluginManager extends JavaPlugin public static Say2Functional functional; public static boolean enableBuildTree = true; public static Session session; - private static PluginResolver resolver; + public static PluginResolver resolver; @Override public void onEnable() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index f7c892f2..9c3e08d3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; -import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -33,7 +32,6 @@ public ErrorResult(@NotNull ErrorCause cause, @NotNull Source source) /** * エラーケース */ - @AllArgsConstructor public enum ErrorCause { /** @@ -52,11 +50,11 @@ public enum ErrorCause /** * サーバに合ったプラグインが見つからなかった */ - MATCH_PLUGIN_NOT_FOUND("対応するプラグインが見つかりませんでした。"), + MATCH_PLUGIN_NOT_FOUND("サーバに対応するプラグインが見つかりませんでした。"), /** * プラグイン自体は見つかったが、アセット(jarファイル)が見つからない。 */ - ASSET_NOT_FOUND("アセットが見つかりませんでした。"), + ASSET_NOT_FOUND("プラグインは見つかりましたが、ファイルが見つかりませんでした。"), /** * サーバのレスポンスが破損している/おかしい。 */ @@ -64,7 +62,7 @@ public enum ErrorCause /** * その他のサーバに関するエラー */ - SERVER_RESPONSE_ERROR("サーバがエラーを返しました。"), + SERVER_RESPONSE_ERROR("サーバがエラーを返答しました。"), /** * その他のエラー */ @@ -73,9 +71,19 @@ public enum ErrorCause @Getter private String message; + @Getter + private boolean messageChanged; + + ErrorCause(String message) + { + this.message = message; + this.messageChanged = false; + } + public ErrorCause value(String message) { this.message = message; + this.messageChanged = true; return this; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java index df18e039..70044bc0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -1,5 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * プラグイン解決結果のインタフェース */ @@ -9,35 +12,40 @@ public interface ResolveResult /** * プラグイン供給元 */ + @AllArgsConstructor enum Source { /** * GitHub */ - GITHUB, + GITHUB("GitHub"), /** * @link https://www.spigotmc.org/resources/ */ - SPIGOT_MC, + SPIGOT_MC("Spigot-MC"), /** * @link https://dev.bukkit.org/projects/plugins/ */ - DEV_BUKKIT, + DEV_BUKKIT("Bukkit-Project"), /** * @link https://curseforge.com/bukkit-plugins/ */ - CURSE_FORGE, + CURSE_FORGE("CurseForge"), /** * ローカルの既知プラグイン */ - LOCAL_KNOWN, + LOCAL_KNOWN("Alias"), /** * 直リンク */ - DIRECT, + DIRECT("Direct"), /** * 不明 */ - UNKNOWN + UNKNOWN("Unknown"); + + @Getter + private final String name; + } } From 99be8be85d5e33cd375f19282fd714001171aaad Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 02:24:02 +0900 Subject: [PATCH 040/745] feat: getResolver() for results --- .../resolver/PluginResolver.java | 4 +-- .../impl/BruteforceGitHubResolver.java | 4 +-- .../resolver/impl/CurseBukkitResolver.java | 12 ++++----- .../impl/CurseBukkitSuccessResult.java | 4 +-- .../resolver/impl/GitHubSuccessResult.java | 5 ++-- .../resolver/impl/GitHubURLResolver.java | 17 ++++++------ .../resolver/impl/KnownPluginsResolver.java | 4 +-- .../resolver/impl/OmittedGitHubResolver.java | 2 +- .../resolver/impl/SpigotMCResolver.java | 27 ++++++++++--------- .../resolver/impl/SpigotMCSuccessResult.java | 10 ++++--- .../resolver/interfaces/BaseResolver.java | 2 +- .../resolver/interfaces/URLResolver.java | 13 ++++----- .../resolver/result/ErrorResult.java | 12 ++++++++- .../resolver/result/MultiResult.java | 5 ++++ .../resolver/result/PipeResult.java | 9 +++++++ .../resolver/result/ResolveResult.java | 7 +++++ .../resolver/result/SuccessResult.java | 14 +++++++--- 17 files changed, 99 insertions(+), 52 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 7a388eb9..0c80db75 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -66,7 +66,7 @@ public ResolveResult resolve(String query) } if (!resolvers.containsKey(context.getResolverName().toLowerCase())) - return new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); + return new ErrorResult(null, ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); return actuallyResolve(resolvers.get(context.getResolverName().toLowerCase()), context); } @@ -96,7 +96,7 @@ private ResolveResult resolves(List resolvers, QueryContext queryC { List finishedResolvers = new ArrayList<>(); - ErrorResult errorResult = new ErrorResult(ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); + ErrorResult errorResult = new ErrorResult(null, ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); for (BaseResolver resolver : resolvers) { if (finishedResolvers.contains(resolver)) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java index 05a3a8a5..a00cd5d0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java @@ -31,7 +31,7 @@ public ResolveResult resolve(QueryContext query) if (!(obj instanceof List) && !(obj instanceof String[])) throw new IllegalArgumentException("Invalid config: gitHubName: config must be a string or a list of strings"); - ResolveResult result = new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + ResolveResult result = new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); for (String str : plugin.getConfig().getStringList("gitHubName")) { @@ -44,7 +44,7 @@ public ResolveResult resolve(QueryContext query) ErrorResult error = (ErrorResult) result; if (error.getCause() == ErrorResult.ErrorCause.INVALID_QUERY) - return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); if (error.getCause() != ErrorResult.ErrorCause.PLUGIN_NOT_FOUND) return error; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 25f6b10a..1d882b96 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -38,7 +38,7 @@ public ResolveResult resolve(QueryContext query) matcher = urlMatcher(CURSE_PATTERN, query.getQuery()); if (matcher == null) - return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, errorSource); + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, errorSource); String slug = null; String version = null; @@ -55,7 +55,7 @@ public ResolveResult resolve(QueryContext query) } if (slug == null) - return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, errorSource); + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, errorSource); Pair projectSearchResponse = URLUtils.getAsString("https://servermods.forgesvc.net/servermods/projects?search=" + slug); @@ -79,7 +79,7 @@ public ResolveResult resolve(QueryContext query) } if (projectId == -1) - return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, errorSource); + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, errorSource); return processFiles(slug, name, projectId, version, errorSource); } @@ -94,17 +94,17 @@ private ResolveResult processFiles(String slug, String name, long projectId, Str JsonArray projectFilesResult = new Gson().fromJson(projectFilesResponse.getRight(), JsonArray.class); if (projectFilesResult.size() == 0) - return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND, source); + return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND, source); JsonObject pickedPlugin = pickUpValidVersion(projectFilesResult, version); if (pickedPlugin == null) - return new ErrorResult(ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, source); + return new ErrorResult(this, ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, source); String downloadUrl = pickedPlugin.get("downloadUrl").getAsString(); String fileName = pickedPlugin.get("fileName").getAsString(); String versionName = pickedPlugin.get("name").getAsString(); - return new CurseBukkitSuccessResult(downloadUrl, projectId, fileName, versionName, source, slug, name); + return new CurseBukkitSuccessResult(this, downloadUrl, projectId, fileName, versionName, source, slug, name); } private static JsonObject pickUpValidVersion(JsonArray versions, @Nullable String version) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index cad3c242..d9ab74d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -22,9 +22,9 @@ public class CurseBukkitSuccessResult extends SuccessResult implements Marketpla private final long id; - public CurseBukkitSuccessResult(@NotNull String downloadUrl, long id, @Nullable String fileName, @Nullable String version, @NotNull Source source, @NotNull String slug, @NotNull String title) + public CurseBukkitSuccessResult(@NotNull CurseBukkitResolver resolver, @NotNull String downloadUrl, long id, @Nullable String fileName, @Nullable String version, @NotNull Source source, @NotNull String slug, @NotNull String title) { - super(downloadUrl, fileName, version, source); + super(resolver, downloadUrl, fileName, version, source); if (source != Source.CURSE_FORGE && source != Source.DEV_BUKKIT) throw new IllegalArgumentException("source must be CurseForge or DevBukkit"); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java index 8c9ba1de..b72ce3b9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; @@ -43,9 +44,9 @@ public class GitHubSuccessResult extends SuccessResult implements MarketplaceRes */ private final long releaseId; - public GitHubSuccessResult(@NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String repoName, @NotNull String htmlPage, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) + public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String repoName, @NotNull String htmlPage, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) { - super(downloadUrl, fileName, version, Source.GITHUB); + super(resolver, downloadUrl, fileName, version, Source.GITHUB); this.owner = owner; this.size = size; this.releaseId = releaseId; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index ca3ea4b4..019eb20a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -35,7 +35,7 @@ public ResolveResult resolve(QueryContext query) Matcher matcher = urlMatcher(GITHUB_REPO_PATTERN, query.getQuery()); if (matcher == null) - return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); String repository = null; String owner = null; @@ -52,7 +52,7 @@ public ResolveResult resolve(QueryContext query) String repoNameGroup = matcher.group("repoName"); if (fileNameGroup != null && !fileNameGroup.isEmpty()) // URLが自己解決。 - return new SuccessResult(query.getQuery(), ResolveResult.Source.GITHUB); + return new SuccessResult(this, query.getQuery(), ResolveResult.Source.GITHUB); if (!repositoryGroup.isEmpty()) repository = repositoryGroup; @@ -70,7 +70,7 @@ else if (tagGroup != null && !tagGroup.isEmpty()) } if (repository == null) - return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); return processGitHubAPI(owner, repositoryName, repository, tag, query.getVersion()); } @@ -127,11 +127,12 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri if (results.isEmpty() && isFound) return new ErrorResult( + this, ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("指定されたバージョンが見つかりませんでした。"), ResolveResult.Source.GITHUB ); - return new MultiResult(results.toArray(new ResolveResult[0])); + return new MultiResult(this, results.toArray(new ResolveResult[0])); } private ResolveResult buildResultSingle(String owner, String repositoryName, JsonObject object, @Nullable String queryVersion) @@ -146,12 +147,12 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso if (queryVersion != null && !queryVersion.equalsIgnoreCase(version) && !("v" + queryVersion).equalsIgnoreCase(queryVersion) && !queryVersion.equalsIgnoreCase("v" + queryVersion)) - return new ErrorResult(ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); JsonArray assets = object.getAsJsonArray("assets"); if (assets.size() == 0) - return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.GITHUB); for (JsonElement asset : assets) { @@ -164,7 +165,7 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso String fileName = assetObject.get("name").getAsString(); long size = assetObject.get("size").getAsLong(); - GitHubSuccessResult result = new GitHubSuccessResult(downloadURL, fileName, version, repositoryName, htmlUrl, owner, size, releaseName, body, releaseId); + GitHubSuccessResult result = new GitHubSuccessResult(this, downloadURL, fileName, version, repositoryName, htmlUrl, owner, size, releaseName, body, releaseId); if (assets.size() == 1) return result; @@ -172,7 +173,7 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso results.add(result); } - return new MultiResult(results.toArray(new GitHubSuccessResult[0])); + return new MultiResult(this, results.toArray(new GitHubSuccessResult[0])); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java index 51f5c04e..4057e0d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java @@ -17,9 +17,9 @@ public ResolveResult resolve(QueryContext query) KnownPluginEntry entry = KnownPlugins.getKnown(query.getQuery()); if (entry == null) - return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); - return new SuccessResult(entry.getUrl(), null, null, ResolveResult.Source.LOCAL_KNOWN); + return new SuccessResult(this, entry.getUrl(), null, null, ResolveResult.Source.LOCAL_KNOWN); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java index 92d1844a..b884553f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java @@ -15,7 +15,7 @@ public class OmittedGitHubResolver implements BaseResolver public ResolveResult resolve(QueryContext query) { query.setQuery("https://github.com/" + query.getQuery()); - return new PipeResult(query); + return new PipeResult(this, query); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 19c8b72d..1e56f6a3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -30,7 +30,7 @@ public ResolveResult resolve(QueryContext query) Matcher matcher = urlMatcher(PATTERN, query.getQuery()); if (matcher == null) - return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); String id = null; String version = null; @@ -47,7 +47,7 @@ public ResolveResult resolve(QueryContext query) } if (id == null) - return new ErrorResult(ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); String spigotAPIUrl = "https://apple.api.spiget.org/v2/resources/" + id; @@ -70,8 +70,9 @@ private ResolveResult buildResult(JsonObject jsonObject, @Nullable String versio { boolean external = jsonObject.get("external").getAsBoolean(); if (external) - return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("SpigotMC ではホストされていません。"), - ResolveResult.Source.SPIGOT_MC); + return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("SpigotMC ではホストされていません。"), + ResolveResult.Source.SPIGOT_MC + ); String description = b64Decode(jsonObject.get("description").getAsString()); String name = jsonObject.get("name").getAsString(); @@ -82,8 +83,9 @@ private ResolveResult buildResult(JsonObject jsonObject, @Nullable String versio boolean premium = jsonObject.get("premium").getAsBoolean(); if (premium) - return new ErrorResult(ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("このプラグインはプレミアムプラグインです。"), - ResolveResult.Source.SPIGOT_MC); + return new ErrorResult(this, ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("このプラグインはプレミアムプラグインです。"), + ResolveResult.Source.SPIGOT_MC + ); long[] versions = StreamSupport.stream(jsonObject.get("versions").getAsJsonArray().spliterator(), false) .mapToLong(e -> e.getAsJsonObject().get("id").getAsLong()) @@ -91,24 +93,25 @@ private ResolveResult buildResult(JsonObject jsonObject, @Nullable String versio if (versions.length == 0) - return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.SPIGOT_MC); + return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.SPIGOT_MC); if (version == null) { List results = new ArrayList<>(); for (long v : versions) - results.add(new SpigotMCSuccessResult(String.valueOf(v), name, id, description, testedVersions)); + results.add(new SpigotMCSuccessResult(this, String.valueOf(v), name, id, description, testedVersions)); - return new MultiResult(results.toArray(new SpigotMCSuccessResult[0])); + return new MultiResult(this, results.toArray(new SpigotMCSuccessResult[0])); } for (long v : versions) if (String.valueOf(v).equals(version)) - return new SpigotMCSuccessResult(version, name, id, description, testedVersions); + return new SpigotMCSuccessResult(this, version, name, id, description, testedVersions); - return new ErrorResult(ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("指定されたバージョンのプラグインが見つかりませんでした。"), - ResolveResult.Source.SPIGOT_MC); + return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("指定されたバージョンのプラグインが見つかりませんでした。"), + ResolveResult.Source.SPIGOT_MC + ); } private String b64Decode(String str) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java index e691e5df..fa3125a8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.VersionedResult; @@ -24,11 +25,12 @@ public class SpigotMCSuccessResult extends SuccessResult implements MarketplaceR @NotNull private final List versions; - public SpigotMCSuccessResult(@Nullable String version, @NotNull String title, long id, @NotNull String description, @NotNull List versions) + public SpigotMCSuccessResult(@NotNull BaseResolver resolver, @Nullable String version, @NotNull String title, long id, @NotNull String description, @NotNull List versions) { - super("https://apple.api.spiget.org/v2/resources/" + id + - (version != null ? "/versions/" + version : "") + "/download", - null, version, Source.SPIGOT_MC); + super(resolver, "https://apple.api.spiget.org/v2/resources/" + id + + (version != null ? "/versions/" + version: "") + "/download", + null, version, Source.SPIGOT_MC + ); this.title = title; this.description = description; this.url = "https://www.spigotmc.org/resources/" + id; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java index b63f9746..4b0e88a7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -43,7 +43,7 @@ default ResolveResult autoPickFirst(MultiResult multiResult, ResolveResult.Sourc ResolveResult[] results = multiResult.getResults(); if (results.length == 0) - return new ErrorResult(ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); return results[0]; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 76e05cc1..bbb2bf58 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -70,21 +70,22 @@ default ErrorResult processErrorResponse(int code, ResolveResult.Source source) case 200: return null; case 403: - return new ErrorResult(cause + return new ErrorResult(this, cause .value(errorCodeWith("サーバからリソースをダウンロードする権限がありません。", code)), source); case 404: - return new ErrorResult(cause + return new ErrorResult(this, cause .value(errorCodeWith("サーバからリソースを見つけることができません。", code)), source); case 418: - return new ErrorResult(cause.value(errorCodeWith("ティーポットでコーヒーを淹れようとしました。", code)), source); + return new ErrorResult(this, cause.value(errorCodeWith("ティーポットでコーヒーを淹れようとしました。", code)), source); default: if (code >= 500 && code < 600) - return new ErrorResult(cause + return new ErrorResult(this, cause .value(errorCodeWith("サーバーがダウンしています。", code)), source); - return new ErrorResult(cause + return new ErrorResult(this, cause .value(errorCodeWith("サーバーがエラーレスポンスを返答しました。。", code)), - source); + source + ); } } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index 9c3e08d3..7f750a6a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -2,7 +2,9 @@ import lombok.EqualsAndHashCode; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * プラグイン解決中のエラーの結果。 @@ -24,11 +26,19 @@ public class ErrorResult implements ResolveResult @NotNull private final Source source; // TODO: フロントエンドに依存しないよう、メッセージプロバイダ作る。 - public ErrorResult(@NotNull ErrorCause cause, @NotNull Source source) + /** + * この結果を提供したリゾルバ + */ + @Nullable + private final BaseResolver resolver; + + public ErrorResult(@Nullable BaseResolver resolver, @NotNull ErrorCause cause, @NotNull Source source) { + this.resolver = resolver; this.cause = cause; this.source = source; } + /** * エラーケース */ diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java index cb92c311..bcad38e3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; /** * 解決結果が複数ある場合に返されるクラス。 @@ -8,6 +9,10 @@ @Value public class MultiResult implements ResolveResult { + /** + * リゾルバ + */ + BaseResolver resolver; /** * The results. */ diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java index a3a26ccc..8c70e55a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java @@ -2,6 +2,7 @@ import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; /** @@ -10,6 +11,14 @@ @Value public class PipeResult implements ResolveResult { + /** + * リゾルバ + */ + @NotNull + BaseResolver resolver; + /** + * 改変したクエリ + */ @NotNull QueryContext query; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java index 70044bc0..9bc2eaa7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -2,12 +2,19 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; /** * プラグイン解決結果のインタフェース */ public interface ResolveResult { + /** + * この結果を解決したリゾルバ + * + * @return リゾルバ + */ + BaseResolver getResolver(); /** * プラグイン供給元 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java index 2376fdd9..37c8d044 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,13 +35,20 @@ public class SuccessResult implements ResolveResult @NotNull private final Source source; - public SuccessResult(@NotNull String downloadUrl, @NotNull Source source) + /** + * この結果を提供したリゾルバ + */ + @NotNull + private final BaseResolver resolver; + + public SuccessResult(BaseResolver resolver, @NotNull String downloadUrl, @NotNull Source source) { - this(downloadUrl, null, null, source); + this(resolver, downloadUrl, null, null, source); } - public SuccessResult(@NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull Source source) + public SuccessResult(@NotNull BaseResolver resolver, @NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull Source source) { + this.resolver = resolver; this.downloadUrl = downloadUrl; this.fileName = fileName; this.version = version; From 7b5156d30d14afc0c2e93a32b885862d0ea98d18 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:08:10 +0900 Subject: [PATCH 041/745] feat: New plugin resolver Close-WIP: 6b0e49f2643f791484ed95cccff523ce9ca67c9b --- .../plugin/Installer.java | 67 ++++++++++++++----- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index bdc10732..b9a250fd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -4,6 +4,10 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.HashLib; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; @@ -11,7 +15,6 @@ import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import net.kyori.adventure.text.Component; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; @@ -200,27 +203,59 @@ public static InstallResult install(CommandSender sender, String url, boolean ig //ダウンロードする場合はURL・クエリを直リンに変換 if (!withoutDownload) { - jarURL = PluginResolver.asUrl(url); + ResolveResult resolveResult = TeamKunPluginManager.resolver.resolve(url); - if (jarURL.startsWith("MULTI")) + if (resolveResult instanceof ErrorResult) { - //MULTIリザルトをパース。 - List> multi = parseMultiResult(jarURL.substring(6)); - if (sender.getName().equals("DUMMY1145141919810931")) - jarURL = pickPluginJar(multi); - else - { - depend_askToCommandSender(sender, multi, ignoreInstall, withoutResolveDepends, withoutRemove); - return new InstallResult(0, 0, 0, true); - } - } + ErrorResult errorResult = (ErrorResult) resolveResult; + + sender.sendMessage(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + " リゾルバ:" + errorResult.getSource().getName()); - if (jarURL.startsWith("ERROR ")) - { - finalSender.sendMessage(ChatColor.RED + "E: " + jarURL.substring(6)); //ERROR <-までをきりだし finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } + else if (resolveResult instanceof MultiResult) + { + MultiResult multiResult = (MultiResult) resolveResult; + + try + { + if (sender.getName().equals("DUMMY1145141919810931")) // TODO: なんやねんこのクソコード + { + resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); + if (resolveResult instanceof ErrorResult) + { + ErrorResult errorResult = (ErrorResult) resolveResult; + + sender.sendMessage(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + " リゾルバ:" + errorResult.getSource().getName()); + + finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + return new InstallResult(add, remove, modify, false); + } + else if (resolveResult instanceof SuccessResult) + jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); + else + throw new RuntimeException("resolveResultが不正です:プラグイン作成者に報告してください。"); + } + else + { + List> multi = Arrays.stream(multiResult.getResults()) + .filter(result -> result instanceof SuccessResult) + .map(result -> { + SuccessResult successResult = (SuccessResult) result; + return new Pair<>(successResult.getVersion(), successResult.getDownloadUrl()); + }).collect(Collectors.toList()); + + depend_askToCommandSender(sender, multi, ignoreInstall, withoutResolveDepends, withoutRemove); + return new InstallResult(add, remove, modify, false); + } + } + catch (IllegalArgumentException ignored) + { + } + } } Pair downloadResult; From 81b06b46f56656297c6ca7ab3dfe604daac7ab6e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:11:15 +0900 Subject: [PATCH 042/745] refactor: Old resolver to new resolver --- .../plugin/compactor/CompactBuilder.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java index 103cc8d7..7004d87a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java @@ -1,6 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.compactor; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.apache.commons.lang.ArrayUtils; import java.util.Map; @@ -51,12 +54,12 @@ public CompactBuilder addPlugin(String name) this.pre.pluginName = name; - String url = PluginResolver.asUrl(name); + ResolveResult result = TeamKunPluginManager.resolver.resolve(name); - if (url.startsWith("ERROR")) + if (result instanceof ErrorResult) this.rs = (BuildResult[]) ArrayUtils.add(this.rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED); - - this.pre.downloadUrl = url; + else if (result instanceof SuccessResult) + this.pre.downloadUrl = ((SuccessResult) result).getDownloadUrl(); return this; } From 11b18d466e81ed1308d5e3079d8b56575288151e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:11:40 +0900 Subject: [PATCH 043/745] chore: Remove unused import of Installer --- .../net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index b9a250fd..7c91bada 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -11,7 +11,6 @@ import net.kunmc.lab.teamkunpluginmanager.utils.HashLib; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; From b8776f45e69ea0480fd96741562f0b511e31381e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:12:13 +0900 Subject: [PATCH 044/745] refactor: Remove old resolver BREAKING CHANGE: Remove old resolver. Move to new PluginResolver --- .../utils/PluginResolver.java | 65 --------- .../utils/rdmarker/DevBukkit.java | 138 ------------------ .../utils/rdmarker/Spigotmc.java | 76 ---------- 3 files changed, 279 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/Spigotmc.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java deleted file mode 100644 index c099759a..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginResolver.java +++ /dev/null @@ -1,65 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; -import net.kunmc.lab.teamkunpluginmanager.utils.rdmarker.DevBukkit; -import net.kunmc.lab.teamkunpluginmanager.utils.rdmarker.Spigotmc; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.validator.routines.UrlValidator; - -import java.util.List; - -public class PluginResolver -{ - - /** - * プラグインのURLを名前解決します。 - * - * @param query 指定 - * @return URLまたはError - */ - public static String asUrl(String query) - { - String[] q = StringUtils.split(query, "@"); - - String s = q[0]; - String ver = q.length > 1 ? q[1]: null; - - if (UrlValidator.getInstance().isValid(query)) - { - if (DevBukkit.isMatch(query)) - return DevBukkit.toDownloadUrl(query); - else if (Spigotmc.isMatch(query)) - return Spigotmc.toDownloadUrl(query); - return GitHubURLBuilder.urlValidate(s, ver); - } - - if (KnownPlugins.isKnown(query)) - return PluginResolver.asUrl(KnownPlugins.getKnown(query).getUrl()); - else if (StringUtils.split(query, "/").length == 2) - return GitHubURLBuilder.urlValidate("https://github.com/" + s, ver); - - //configのorgを順番にfetch - - Object obj = TeamKunPluginManager.plugin.getConfig().get("gitHubName"); - - if (obj instanceof String) - if (GitHubURLBuilder.isRepoExists(obj + "/" + s)) - return GitHubURLBuilder.urlValidate("https://github.com/" + obj + "/" + s, ver); - else - return "ERROR " + query + "が見つかりませんでした。"; - - if (!(obj instanceof List) && !(obj instanceof String[])) - return "ERROR " + query + "が見つかりませんでした。"; - - - for (String str : TeamKunPluginManager.config.getStringList("gitHubName")) - { - if (GitHubURLBuilder.isRepoExists(str + "/" + query)) - return GitHubURLBuilder.urlValidate("https://github.com/" + str + "/" + s, ver); - } - - return "ERROR " + query + "が見つかりませんでした。"; - } - -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java deleted file mode 100644 index f09291d8..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/DevBukkit.java +++ /dev/null @@ -1,138 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.rdmarker; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; - -import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class DevBukkit -{ - - private static final String basePatterns = "(?\\w+)(/(files|/screenshots|relations/(dependencies|dependents)|)/?$)?(/?$|/files(/(?\\d+)((/files/(?\\d+))?/download)?)?)/?$"; - private static final Pattern BUKKIT_PATTERN = Pattern.compile("^/projects/" + basePatterns); - private static final Pattern CURSE_PATTERN = Pattern.compile("^/minecraft/bukkit-plugins/" + basePatterns); - - public static boolean isMatch(String urlName) - { - URL url; - try - { - url = new URL(urlName); - } - catch (Exception e) - { - return false; - } - - boolean isBukkit; - - if (!(isBukkit = url.getHost().equals("dev.bukkit.org")) && !url.getHost().equals("curseforge.com")) - return false; - - Matcher matcher = (isBukkit ? BUKKIT_PATTERN: CURSE_PATTERN).matcher(url.getPath()); - - while (matcher.find()) - if (matcher.group("slug") != null && !matcher.group("slug").equals("")) - return true; - return false; - } - - public static String toDownloadUrl(String urlName) - { - URL url; - try - { - url = new URL(urlName); - } - catch (Exception e) - { - return urlName; - } - - if (!url.getHost().equals("dev.bukkit.org")) - return urlName; - - Matcher matcher = BUKKIT_PATTERN.matcher(url.getPath()); - - String slug = null; - String version = null; - - while (matcher.find()) - { - if (matcher.group("slug") != null && !matcher.group("slug").equals("")) - slug = matcher.group("slug"); - if (matcher.group("version") != null && !matcher.group("version").equals("")) - version = matcher.group("version"); - } - - if (slug == null) - return urlName; - JsonArray projectSearchResult = new Gson().fromJson( - URLUtils.getAsString("https://servermods.forgesvc.net/servermods/projects?search=" + slug).getRight(), - JsonArray.class - ); - - String id = null; - - for (JsonElement elm : projectSearchResult) - { - JsonObject obj = (JsonObject) elm; - - if (obj.get("slug").getAsString().equalsIgnoreCase(slug)) - { - id = obj.get("id").getAsString(); - break; - } - } - - - if (id == null) - return urlName; - - JsonArray files = new Gson().fromJson( - URLUtils.getAsString("https://servermods.forgesvc.net/servermods/files?projectIds=" + id).getRight(), - JsonArray.class - ); - - String apiVersion = StringUtils.split(Bukkit.getVersion(), "-")[0]; - - String downloadUrl = null; - - for (JsonElement elm : files) - { - JsonObject obj = (JsonObject) elm; - - if (version != null) - { - if (obj.get("fileUrl").getAsString().endsWith(version)) - { - downloadUrl = obj.get("downloadUrl").getAsString(); - break; - } - } - else - { - if (apiVersion.contains(obj.get("gameVersion").getAsString())) - { - downloadUrl = obj.get("downloadUrl").getAsString(); - break; - } - } - } - - if (downloadUrl == null && files.size() > 0) - downloadUrl = ((JsonObject) files.get(files.size() - 1)).get("downloadUrl").getAsString(); - - if (downloadUrl == null) - return urlName; - - return downloadUrl; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/Spigotmc.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/Spigotmc.java deleted file mode 100644 index b31bea6f..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/rdmarker/Spigotmc.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.rdmarker; - -import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class Spigotmc -{ - - private static final Pattern PATTERN = Pattern.compile("^/resources/(?.+?\\.)?(?\\d+)(/|/download(/|\\?/version=(?\\d+))?)?$"); - - public static boolean isMatch(String urlName) - { - URL url; - try - { - url = new URL(urlName); - } - catch (Exception e) - { - return false; - } - - if (!url.getHost().equals("spigotmc.org") && !url.getHost().equals("www.spigotmc.org")) - return false; - - Matcher matcher = PATTERN.matcher(url.getPath()); - - while (matcher.find()) - if (matcher.group("id") != null && !matcher.group("id").equals("")) - return true; - return false; - } - - public static String toDownloadUrl(String urlName) - { - URL url; - try - { - url = new URL(urlName); - } - catch (Exception e) - { - return urlName; - } - - if (!url.getHost().equals("spigotmc.org") && !url.getHost().equals("www.spigotmc.org")) - return urlName; - - Matcher matcher = PATTERN.matcher(url.getPath()); - - String id = null; - String name = null; - String version = null; - - while (matcher.find()) - { - if (matcher.group("id") != null && !matcher.group("id").equals("")) - id = matcher.group("id"); - if (matcher.group("name") != null && !matcher.group("name").equals("")) - name = matcher.group("name"); - if (matcher.group("version") != null && !matcher.group("version").equals("")) - version = matcher.group("version"); - } - - if (id == null) - return urlName; - - String baseUrl = "https://apple.api.spiget.org/v2/resources/" + id + "/"; - - if (version == null) - return baseUrl + "download"; - else - return baseUrl + "versions/" + version + "/download"; - } -} From ba5181809d4c183230eea860413c367d4b7d58b0 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:26:44 +0900 Subject: [PATCH 045/745] fix: depend error --- .../plugin/Installer.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 7c91bada..f6125d7c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -476,15 +476,39 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが } //クエリを直リンに変換 - String dependUrl = PluginResolver.asUrl(dependency); - //エラーから始まった場合はエラーとして表示し、 - //失敗としてマーク - if (dependUrl.startsWith("ERROR ")) + ResolveResult resolveResult = TeamKunPluginManager.resolver.resolve(url); + String dependUrl; + + if (resolveResult instanceof ErrorResult) { + ErrorResult errorResult = (ErrorResult) resolveResult; + + sender.sendMessage(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + " リゾルバ:" + errorResult.getSource().getName()); finalSender.sendMessage(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); failedResolve.add(dependency); continue; } + else if (resolveResult instanceof MultiResult) + { + MultiResult multiResult = (MultiResult) resolveResult; + + resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); + if (resolveResult instanceof ErrorResult) + { + finalSender.sendMessage(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); + failedResolve.add(dependency); + continue; + } + else if (resolveResult instanceof SuccessResult) + dependUrl = ((SuccessResult) resolveResult).getDownloadUrl(); + else + throw new RuntimeException("resolveResultが不正です:プラグイン作成者に報告してください。"); + } + else if (resolveResult instanceof SuccessResult) + dependUrl = ((SuccessResult) resolveResult).getDownloadUrl(); + else + throw new RuntimeException("resolveResultが不正です:プラグイン作成者に報告してください。"); //依存関係のインストール InstallResult dependResolve = Installer.install(null, dependUrl, true, false, true, false); From dd251be1c148e8947f9c36a9b0103a149e74e4b9 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:29:38 +0900 Subject: [PATCH 046/745] fix: Resolver caching --- .../teamkunpluginmanager/resolver/PluginResolver.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 0c80db75..92fcefe3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -12,7 +12,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.stream.Collectors; /** * プラグインを解決するクラス @@ -21,11 +20,13 @@ public class PluginResolver { private final HashMap> resolvers; private final List onNotFoundResolvers; + private final List allResolvers; public PluginResolver() { this.resolvers = new HashMap<>(); this.onNotFoundResolvers = new ArrayList<>(); + this.allResolvers = new ArrayList<>(); } public void addResolver(BaseResolver resolver, String... names) @@ -41,6 +42,8 @@ public void addResolver(BaseResolver resolver, String... names) resolvers.put(name.toLowerCase(), new ArrayList<>(Collections.singletonList(resolver))); else resolverList.add(resolver); + + allResolvers.add(resolver); } } @@ -59,11 +62,7 @@ public ResolveResult resolve(String query) QueryContext context = QueryContext.fromString(query); if (context.getResolverName() == null) - { - return actuallyResolve(resolvers.values().stream() - .flatMap(List::stream) - .collect(Collectors.toList()), context); - } + return actuallyResolve(allResolvers, context); if (!resolvers.containsKey(context.getResolverName().toLowerCase())) return new ErrorResult(null, ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); From 37730de4bd3c3616f69f5f7ae2f7cbcf22f913c7 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:37:43 +0900 Subject: [PATCH 047/745] fix: Version pickup --- .../resolver/impl/CurseBukkitResolver.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 1d882b96..7d81bcf8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -11,7 +11,8 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; @@ -22,7 +23,16 @@ public class CurseBukkitResolver implements URLResolver private static final String basePatterns = "(?\\w+)(/files(/(?\\d+))?(/download)?)?/?$"; private static final Pattern BUKKIT_PATTERN = Pattern.compile("^/projects/" + basePatterns); private static final Pattern CURSE_PATTERN = Pattern.compile("^/minecraft/bukkit-plugins/" + basePatterns); - private static final String BUKKIT_API_VERSION = StringUtils.split("1.16.5", "-")[0]; + private static final String BUKKIT_API_VERSION; + + static + { + String baseVersion = Bukkit.getMinecraftVersion(); + // remove patch version + if (StringUtils.countMatches(baseVersion, ".") >= 2) + baseVersion = StringUtils.split(baseVersion, ".")[0] + "." + StringUtils.split(baseVersion, ".")[1]; + BUKKIT_API_VERSION = baseVersion; + } @Override public ResolveResult resolve(QueryContext query) From 44aa4d2842c6d9f56a3a6a076536befed2227763 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 03:42:01 +0900 Subject: [PATCH 048/745] fix: Single result error --- .../kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java | 4 ++-- .../net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 546f43b4..17d80dc6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -43,11 +43,11 @@ public void onEnable() resolver = new PluginResolver(); GitHubURLResolver githubResolver = new GitHubURLResolver(); - resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); - resolver.addResolver(githubResolver, "github", "gh"); resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); + resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); + resolver.addResolver(githubResolver, "github", "gh"); resolver.addOnNotFoundResolver(new BruteforceGitHubResolver(this, githubResolver)); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index f6125d7c..47c9d7f8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -255,6 +255,8 @@ else if (resolveResult instanceof SuccessResult) { } } + else if (resolveResult instanceof SuccessResult) + jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); } Pair downloadResult; From 84e3427dcd49886468c2b96576414a3145e767b7 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 04:30:22 +0900 Subject: [PATCH 049/745] style: Fix style --- .../kunmc/lab/teamkunpluginmanager/plugin/Installer.java | 6 +++--- .../resolver/impl/CurseBukkitSuccessResult.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 47c9d7f8..b666f59f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -236,7 +236,7 @@ else if (resolveResult instanceof MultiResult) else if (resolveResult instanceof SuccessResult) jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); else - throw new RuntimeException("resolveResultが不正です:プラグイン作成者に報告してください。"); + throw new IllegalStateException("resolveResultが不正です:プラグイン作成者に報告してください。"); } else { @@ -505,12 +505,12 @@ else if (resolveResult instanceof MultiResult) else if (resolveResult instanceof SuccessResult) dependUrl = ((SuccessResult) resolveResult).getDownloadUrl(); else - throw new RuntimeException("resolveResultが不正です:プラグイン作成者に報告してください。"); + throw new IllegalStateException("resolveResultが不正です:プラグイン作成者に報告してください。"); } else if (resolveResult instanceof SuccessResult) dependUrl = ((SuccessResult) resolveResult).getDownloadUrl(); else - throw new RuntimeException("resolveResultが不正です:プラグイン作成者に報告してください。"); + throw new IllegalStateException("resolveResultが不正です:プラグイン作成者に報告してください。"); //依存関係のインストール InstallResult dependResolve = Installer.install(null, dependUrl, true, false, true, false); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index d9ab74d8..ebc19d45 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -22,6 +22,8 @@ public class CurseBukkitSuccessResult extends SuccessResult implements Marketpla private final long id; + private String description = null; + public CurseBukkitSuccessResult(@NotNull CurseBukkitResolver resolver, @NotNull String downloadUrl, long id, @Nullable String fileName, @Nullable String version, @NotNull Source source, @NotNull String slug, @NotNull String title) { super(resolver, downloadUrl, fileName, version, source); @@ -43,7 +45,6 @@ public String getUrl() return "https://dev.bukkit.org/projects/" + this.slug; } - private String description = null; @Override public String getDescription() From b88abb59b77b5d999e1668f0cbbb75d83a031544 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 23 Mar 2022 04:31:29 +0900 Subject: [PATCH 050/745] refactor: Remove unused parameter of constructor --- .../resolver/impl/GitHubSuccessResult.java | 2 +- .../teamkunpluginmanager/resolver/impl/GitHubURLResolver.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java index b72ce3b9..49de5960 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java @@ -44,7 +44,7 @@ public class GitHubSuccessResult extends SuccessResult implements MarketplaceRes */ private final long releaseId; - public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String repoName, @NotNull String htmlPage, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) + public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String repoName, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) { super(resolver, downloadUrl, fileName, version, Source.GITHUB); this.owner = owner; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 019eb20a..997a8d45 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -143,7 +143,6 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso String body = object.get("body").getAsString(); String version = object.get("tag_name").getAsString(); long releaseId = object.get("id").getAsLong(); - String htmlUrl = object.get("html_url").getAsString(); if (queryVersion != null && !queryVersion.equalsIgnoreCase(version) && !("v" + queryVersion).equalsIgnoreCase(queryVersion) && !queryVersion.equalsIgnoreCase("v" + queryVersion)) @@ -165,7 +164,7 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso String fileName = assetObject.get("name").getAsString(); long size = assetObject.get("size").getAsLong(); - GitHubSuccessResult result = new GitHubSuccessResult(this, downloadURL, fileName, version, repositoryName, htmlUrl, owner, size, releaseName, body, releaseId); + GitHubSuccessResult result = new GitHubSuccessResult(this, downloadURL, fileName, version, repositoryName, owner, size, releaseName, body, releaseId); if (assets.size() == 1) return result; From dc80b0efb130a8ebdd8189e6083471f29b343a47 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 24 Mar 2022 00:13:56 +0900 Subject: [PATCH 051/745] fix: AutoRemove Nullpo --- .../commands/CommandAutoRemove.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 16b3d664..95466692 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -10,22 +10,20 @@ import org.bukkit.plugin.Plugin; import java.util.ArrayList; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class CommandAutoRemove { public static ArrayList onCommand(CommandSender sender, String[] args) { - - if (sender != null && !sender.hasPermission("kpm.autoremove")) + if (!sender.hasPermission("kpm.autoremove")) { sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); return null; } ArrayList rem = new ArrayList<>(); - if (sender == null) - sender = Installer.dummySender(); if (!TeamKunPluginManager.session.lock()) { @@ -35,6 +33,7 @@ public static ArrayList onCommand(CommandSender sender, String[] args) AtomicInteger removed = new AtomicInteger(); sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); + ArrayList removables = DependencyTree.unusedPlugins(); if (removables.size() == 0) { @@ -45,29 +44,37 @@ public static ArrayList onCommand(CommandSender sender, String[] args) return rem; } + while (removables.size() > 0) + { // のremoveUnusedPluginsで削除したプラグインによりいらない物ができた場合のためのループ + rem.addAll(removeUnusedPlugins(removables)); + removables = DependencyTree.unusedPlugins(); + } + + rem.forEach(s -> { + sender.sendMessage(Messages.getModifyMessage(Messages.ModifyType.REMOVE, s)); + removed.getAndIncrement(); + }); + sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); + + TeamKunPluginManager.session.unlock(); + return rem; + } + + private static List removeUnusedPlugins(ArrayList removables) + { + ArrayList removed = new ArrayList<>(); + for (String removable : removables) { Plugin plugin = Bukkit.getPluginManager().getPlugin(removable); if (plugin != null) { Installer.unInstall(null, removable, true); - rem.add(removable); + removed.add(removable); } DependencyTree.purge(removable); } - rem.addAll(onCommand(null, null)); - - if (!sender.equals(Installer.dummySender())) - { - CommandSender finalSender = sender; - rem.forEach(s -> { - finalSender.sendMessage(Messages.getModifyMessage(Messages.ModifyType.REMOVE, s)); - removed.getAndIncrement(); - }); - sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); - } - TeamKunPluginManager.session.unlock(); - return rem; + return removed; } } From f4874858baed5e8c4e8afe7d07431b95d3fac9de Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 24 Mar 2022 01:31:51 +0900 Subject: [PATCH 052/745] fix: Dependency resolver --- .../net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index b666f59f..bb035d4c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -478,7 +478,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが } //クエリを直リンに変換 - ResolveResult resolveResult = TeamKunPluginManager.resolver.resolve(url); + ResolveResult resolveResult = TeamKunPluginManager.resolver.resolve(dependency); String dependUrl; if (resolveResult instanceof ErrorResult) From aea353e77e8073f6dd6a81c056d7b3d09b168f6b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 24 Mar 2022 01:33:45 +0900 Subject: [PATCH 053/745] fix: Dependency pickup --- .../resolver/interfaces/BaseResolver.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java index 4b0e88a7..8bb5ef8a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -45,6 +45,10 @@ default ResolveResult autoPickFirst(MultiResult multiResult, ResolveResult.Sourc if (results.length == 0) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); - return results[0]; + ResolveResult result = results[0]; + if (result instanceof MultiResult) + return autoPickFirst((MultiResult) result, source); + + return result; } } From f46773e32f9d19149bb9cd3a075e017355d245d9 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 24 Mar 2022 22:16:27 +0900 Subject: [PATCH 054/745] refactor: Unstaticize --- .../TeamKunPluginManager.java | 29 ++++++++++----- .../commands/CommandAutoRemove.java | 6 +-- .../commands/CommandClean.java | 22 ++++++----- .../commands/CommandExport.java | 6 +-- .../commands/CommandFix.java | 6 +-- .../commands/CommandImport.java | 18 +++++---- .../commands/CommandInfo.java | 4 +- .../commands/CommandInstall.java | 14 ++++--- .../commands/CommandRegister.java | 18 +++++---- .../commands/CommandReload.java | 6 +-- .../commands/CommandStatus.java | 7 +++- .../commands/CommandUninstall.java | 6 +-- .../commands/CommandUpdate.java | 18 ++++----- .../plugin/DependencyTree.java | 2 +- .../plugin/Installer.java | 37 ++++++++++--------- .../plugin/KnownPlugins.java | 4 +- .../plugin/PluginEventListener.java | 18 +++++---- .../plugin/compactor/CompactBuilder.java | 2 +- .../utils/PluginUtil.java | 6 +-- .../teamkunpluginmanager/utils/URLUtils.java | 25 ++++++++++--- .../resolver/PluginResolverTest.java | 9 ----- 21 files changed, 145 insertions(+), 118 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 17d80dc6..57ec77cd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -1,5 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager; +import lombok.Getter; +import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.commands.CommandMain; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; @@ -21,16 +23,20 @@ import java.io.File; +@Getter public final class TeamKunPluginManager extends JavaPlugin { public static final String DATABASE_PATH = "plugins/TeamKunPluginManager/database/"; - public static TeamKunPluginManager plugin; - public static FileConfiguration config; - public static TokenVault vault; - public static Say2Functional functional; - public static boolean enableBuildTree = true; - public static Session session; - public static PluginResolver resolver; + @Getter + private static TeamKunPluginManager plugin; + + private FileConfiguration config; + private TokenVault vault; + private Say2Functional functional; + @Setter + private boolean enableBuildTree = true; + private Session session; + private PluginResolver resolver; @Override public void onEnable() @@ -56,9 +62,9 @@ public void onEnable() Bukkit.getPluginCommand("kunpluginmanager").setExecutor(new CommandMain()); Bukkit.getPluginCommand("kunpluginmanager").setTabCompleter(new CommandMain()); - DependencyTree.initialize(TeamKunPluginManager.config.getString("dependPath")); + DependencyTree.initialize(this.config.getString("dependPath")); DependencyTree.initializeTable(); - KnownPlugins.initialization(TeamKunPluginManager.config.getString("resolvePath")); + KnownPlugins.initialization(this.config.getString("resolvePath")); if (KnownPlugins.isLegacy()) { @@ -78,7 +84,10 @@ public void run() DependencyTree.crawlAllPlugins(); getLogger().info("依存関係ツリーの構築完了"); //すべてのPLが読み終わった後にイベントリスナを登録 - Bukkit.getPluginManager().registerEvents(new PluginEventListener(), TeamKunPluginManager.plugin); + Bukkit.getPluginManager().registerEvents( + new PluginEventListener(TeamKunPluginManager.this), + TeamKunPluginManager.plugin + ); } }.runTaskLater(this, 1L); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 95466692..2cade311 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -25,7 +25,7 @@ public static ArrayList onCommand(CommandSender sender, String[] args) ArrayList rem = new ArrayList<>(); - if (!TeamKunPluginManager.session.lock()) + if (!TeamKunPluginManager.getPlugin().getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return null; @@ -40,7 +40,7 @@ public static ArrayList onCommand(CommandSender sender, String[] args) sender.sendMessage(ChatColor.RED + "E: 削除可能なプラグインはありません。"); sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); - TeamKunPluginManager.session.unlock(); + TeamKunPluginManager.getPlugin().getSession().unlock(); return rem; } @@ -56,7 +56,7 @@ public static ArrayList onCommand(CommandSender sender, String[] args) }); sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); - TeamKunPluginManager.session.unlock(); + TeamKunPluginManager.getPlugin().getSession().unlock(); return rem; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index 6a9abb97..2b9318f1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -29,7 +29,9 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.session.lock()) + TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); + + if (!kpmInstance.getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; @@ -42,7 +44,7 @@ public static void onCommand(CommandSender sender, String[] args) if (removable.length == 0) { sender.sendMessage(ChatColor.RED + "E: 削除可能が項目が見つかりませんでした。"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } @@ -54,14 +56,14 @@ public static void onCommand(CommandSender sender, String[] args) if (!args[0].equals("all") && Arrays.stream(removable).noneMatch(s -> args[0].equalsIgnoreCase(s))) { sender.sendMessage(ChatColor.RED + "E: プラグインが見つかりませんでした。"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } if (args.length == 2 && !args[1].equals("no-preserve") && !(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "本当に実行する場合、次のコマンドを実行してください: /kpm clean " + args[0] + " no-preserve"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } @@ -75,7 +77,7 @@ public static void onCommand(CommandSender sender, String[] args) Installer.clean(args[0]); sender.sendMessage(Messages.getStatusMessage(0, args[0].equals("all") ? removable.length: 1, 0)); sender.sendMessage(ChatColor.GREEN + "S: 削除に成功しました。"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } @@ -87,7 +89,7 @@ public static void onCommand(CommandSender sender, String[] args) ChatColor.RED + "N" + ChatColor.WHITE + "]"); - TeamKunPluginManager.functional.add( + kpmInstance.getFunctional().add( ((Player) sender).getUniqueId(), new Say2Functional.FunctionalEntry(StringUtils::startsWithIgnoreCase, s -> { switch (s) @@ -111,7 +113,7 @@ public static void onCommand(CommandSender sender, String[] args) if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "本当に実行する場合、次のコマンドを実行してください: /kpm clean all no-preserve"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } sender.sendMessage(ChatColor.RED + "本当に続行しますか? " + @@ -120,14 +122,14 @@ public static void onCommand(CommandSender sender, String[] args) ChatColor.WHITE + "/" + ChatColor.RED + "N" + ChatColor.WHITE + "]"); - TeamKunPluginManager.functional.add( + kpmInstance.getFunctional().add( ((Player) sender).getUniqueId(), new Say2Functional.FunctionalEntry(StringUtils::startsWithIgnoreCase, s -> { switch (s) { case "n": sender.sendMessage(ChatColor.RED + "キャンセルしました。"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); break; case "y": sender.sendMessage(ChatColor.GREEN + "削除を実行しています..."); @@ -135,7 +137,7 @@ public static void onCommand(CommandSender sender, String[] args) .forEach(Installer::clean); sender.sendMessage(Messages.getStatusMessage(0, removable.length, 0)); sender.sendMessage(ChatColor.GREEN + "S: 削除に成功しました。"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); } }, "y", "n") ); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java index b0eb7c78..3c9b6061 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java @@ -49,7 +49,7 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.plugin.isTokenAvailable()) + if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) { sender.sendMessage(ChatColor.RED + "E: トークンがセットされていません!"); sender.sendMessage(ChatColor.RED + "/kpm register でトークンを発行してください。"); @@ -164,7 +164,7 @@ private static void fixError(UUID uuid, String name) else sender.sendMessage(ChatColor.GREEN + "これを解決するには、チャットでURLを発言してください。"); - TeamKunPluginManager.functional.add(uuid == CONSOLE_UUID ? null: uuid, new Say2Functional.FunctionalEntry(String::startsWith, s -> { + TeamKunPluginManager.getPlugin().getFunctional().add(uuid == CONSOLE_UUID ? null: uuid, new Say2Functional.FunctionalEntry(String::startsWith, s -> { ppc.fixUrl(target, s); sender.sendMessage(ChatColor.GREEN + "プラグイン " + ChatColor.GOLD + "'" + target + "' " + @@ -192,7 +192,7 @@ private static void runExec(UUID uuid, PluginPreCompacter ppc) SimpleDateFormat f = new SimpleDateFormat("yyyyMMddhhmmss"); File exportAs = new File( - TeamKunPluginManager.plugin.getDataFolder(), + TeamKunPluginManager.getPlugin().getDataFolder(), "exports/" + f.format(new Date()) + ".pmx" ); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java index 09ca26f6..b8e7a799 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java @@ -15,7 +15,7 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.session.lock()) + if (!TeamKunPluginManager.getPlugin().getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; @@ -25,13 +25,13 @@ public static void onCommand(CommandSender sender, String[] args) if (!DependencyTree.isErrors()) { sender.sendMessage(ChatColor.RED + "E: エラーは検出されませんでした。"); - TeamKunPluginManager.session.unlock(); + TeamKunPluginManager.getPlugin().getSession().unlock(); return; } sender.sendMessage(ChatColor.GREEN + "エラーを解決しています..."); DependencyTree.fix(); sender.sendMessage(ChatColor.GREEN + "S: エラーの解決に成功しました。"); - TeamKunPluginManager.session.unlock(); + TeamKunPluginManager.getPlugin().getSession().unlock(); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java index bd677f95..d6b746f3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java @@ -39,7 +39,9 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.session.lock()) + TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); + + if (!kpmInstance.getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; @@ -49,7 +51,7 @@ public static void onCommand(CommandSender sender, String[] args) { sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); sender.sendMessage(ChatColor.RED + "使用法: /kpm import URL"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } @@ -62,7 +64,7 @@ public static void onCommand(CommandSender sender, String[] args) { sender.sendMessage(ChatColor.RED + "E: 第一引数に適切なURLを入力してください。"); sender.sendMessage(Messages.getStatusMessage(add.get(), remove.get(), modify.get())); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } @@ -98,7 +100,7 @@ public static void onCommand(CommandSender sender, String[] args) catch (JsonParseException e) { sender.sendMessage(ChatColor.RED + "E: JSONファイルが正しくないようです。"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } @@ -117,7 +119,7 @@ public static void onCommand(CommandSender sender, String[] args) ArrayList loadOrder = PluginUtil.mathLoadOrder(results); - TeamKunPluginManager.enableBuildTree = false; + kpmInstance.setEnableBuildTree(false); sender.sendMessage(ChatColor.GOLD + "設定を書き込み中..."); @@ -160,12 +162,12 @@ public void run() if (file != null) file.delete(); } - }.runTaskLaterAsynchronously(TeamKunPluginManager.plugin, 20L); + }.runTaskLaterAsynchronously(kpmInstance, 20L); } PluginUtil.load(installResult.getFileName().substring(0, installResult.getFileName().length() - 4)); sender.sendMessage(ChatColor.GREEN + "+ " + installResult.getPluginName()); }); - TeamKunPluginManager.enableBuildTree = true; + kpmInstance.setEnableBuildTree(true); sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを構築中..."); container.parallelStream().forEach(pluginContainer -> { DependencyTree.crawlPlugin(pluginContainer.pluginName); @@ -174,6 +176,6 @@ public void run() sender.sendMessage(ChatColor.GREEN + "S: 正常にインポートしました。"); sender.sendMessage(Messages.getStatusMessage(add.get(), remove.get(), modify.get())); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index 7108f37f..d0ad8ad7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -8,8 +8,6 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ComponentBuilder; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -63,7 +61,7 @@ public static void onCommand(CommandSender sender, String[] args) sender.sendMessage(pi("作成者", String.join(", ", plugin.getDescription().getAuthors()))); sender.sendMessage(pi("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); sender.sendMessage(pi("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); - sender.sendMessage(pi("保護", TeamKunPluginManager.config.getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name)))); + sender.sendMessage(pi("保護", TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name)))); if (plugin.getDescription().getWebsite() != null) sender.sendMessage(pi("ウェブサイト", ChatColor.UNDERLINE + plugin.getDescription().getWebsite())); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index c33e2a6e..75322538 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -26,22 +26,24 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.plugin.isTokenAvailable()) + TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); + + if (!kpmInstance.isTokenAvailable()) { sender.sendMessage(ChatColor.RED + "E: トークンがセットされていません!"); sender.sendMessage(ChatColor.RED + "/kpm register でトークンを発行してください。"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } if (args.length == 1 && args[0].equals("$-CF$")) { - TeamKunPluginManager.functional.remove(sender instanceof ConsoleCommandSender ? null: ((Player) sender).getUniqueId()); + kpmInstance.getFunctional().remove(sender instanceof ConsoleCommandSender ? null: ((Player) sender).getUniqueId()); sender.sendMessage(ChatColor.GREEN + "E: 実行中のインストールをキャンセルしました。"); return; } - if (!TeamKunPluginManager.session.lock()) + if (!kpmInstance.getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; @@ -54,8 +56,8 @@ public static void onCommand(CommandSender sender, String[] args) public void run() { Installer.install(sender, args[0], false, false, false, false); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); } - }.runTaskAsynchronously(TeamKunPluginManager.plugin); + }.runTaskAsynchronously(kpmInstance); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 39dbb61c..4b760212 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -17,6 +17,7 @@ public class CommandRegister { private final static String CLIENT_ID = "94c5d446dbc765895979"; + private static final TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); public static void onCommand(CommandSender sender, String[] args) { @@ -33,23 +34,24 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.session.lock()) + if (!kpmInstance.getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; } + if (args.length == 1) { - TeamKunPluginManager.vault.vault(args[0]); + kpmInstance.getVault().vault(args[0]); sender.sendMessage(ChatColor.GREEN + "S: トークンを正常に保管しました!"); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); return; } sender.sendMessage(ChatColor.GREEN + "GitHubサーバを用いてトークンを生成しますか? y/N> "); - TeamKunPluginManager.functional.add(sender instanceof Player ? ((Player) sender).getUniqueId(): null, new Say2Functional.FunctionalEntry( + kpmInstance.getFunctional().add(sender instanceof Player ? ((Player) sender).getUniqueId(): null, new Say2Functional.FunctionalEntry( String::startsWith, s -> { if (!s.equalsIgnoreCase("y")) @@ -122,16 +124,16 @@ public void run() return; } - TeamKunPluginManager.vault.vault(response.get("access_token").getAsString()); + kpmInstance.getVault().vault(response.get("access_token").getAsString()); sender.sendMessage(ChatColor.GREEN + "S: トークンを正常に保管しました!"); if (sender instanceof Player) sender.resetTitle(); - TeamKunPluginManager.session.unlock(); + kpmInstance.getSession().unlock(); success[0] = true; this.cancel(); } }; - BukkitTask task = polling.runTaskTimer(TeamKunPluginManager.plugin, 100L, (get_interval * 20L) + 20L); + BukkitTask task = polling.runTaskTimer(kpmInstance, 100L, (get_interval * 20L) + 20L); BukkitRunnable expire = new BukkitRunnable() { @@ -143,7 +145,7 @@ public void run() task.cancel(); } }; - expire.runTaskLater(TeamKunPluginManager.plugin, get_interval * 20L); + expire.runTaskLater(kpmInstance, get_interval * 20L); } private static String parseError(String err) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java index 67cd2f97..cdd1459b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java @@ -33,7 +33,7 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.session.lock()) + if (!TeamKunPluginManager.getPlugin().getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; @@ -46,8 +46,8 @@ public void run() { PluginUtil.reload(plugin); sender.sendMessage(ChatColor.GREEN + "S: " + args[0] + " を正常に再読み込みしました。"); - TeamKunPluginManager.session.unlock(); + TeamKunPluginManager.getPlugin().getSession().unlock(); } - }.runTaskAsynchronously(TeamKunPluginManager.plugin); + }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java index a324e2c5..3c484b8e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java @@ -28,7 +28,10 @@ public static void onCommand(CommandSender sender, String[] args) sender.sendMessage(ChatColor.GREEN + "ステータス: " + (!statusError.equals("") ? ChatColor.RED + "エラー": ChatColor.DARK_GREEN + "正常")); sender.sendMessage(pi("プラグイン数", Bukkit.getPluginManager().getPlugins().length)); - File resolve = new File(TeamKunPluginManager.plugin.getDataFolder(), TeamKunPluginManager.config.getString("resolvePath")); + File resolve = new File( + TeamKunPluginManager.getPlugin().getDataFolder(), + TeamKunPluginManager.getPlugin().getConfig().getString("resolvePath") + ); if (resolve.exists()) sender.sendMessage(pi("最終アップデート", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(resolve.lastModified())))); if (!statusError.equals("")) @@ -39,7 +42,7 @@ public static void onCommand(CommandSender sender, String[] args) if (!autoRemovable.equals("")) sender.sendMessage(autoRemovable); - if (!TeamKunPluginManager.plugin.isTokenAvailable()) + if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) sender.sendMessage(ChatColor.RED + "トークンがセットされていません!/kpm register でトークンを発行してください。"); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index 5aeae70d..a93f9f8b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -24,7 +24,7 @@ public static void onCommand(CommandSender sender, String[] args) return; } - if (!TeamKunPluginManager.session.lock()) + if (!TeamKunPluginManager.getPlugin().getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; @@ -36,8 +36,8 @@ public static void onCommand(CommandSender sender, String[] args) public void run() { Installer.unInstall(sender, args[0], false); - TeamKunPluginManager.session.unlock(); + TeamKunPluginManager.getPlugin().getSession().unlock(); } - }.runTaskAsynchronously(TeamKunPluginManager.plugin); + }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 12150563..630d141c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -7,16 +7,13 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; -import net.kunmc.lab.teamkunpluginmanager.utils.FileUploadUtil; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.bukkit.ChatColor; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; -import javax.management.monitor.StringMonitor; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -49,14 +46,14 @@ public static void onCommand(CommandSender sender, String[] args) if (sender == null) sender = Installer.dummySender(); - if (!TeamKunPluginManager.plugin.isTokenAvailable()) + if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) { sender.sendMessage(ChatColor.RED + "E: トークンがセットされていません!"); sender.sendMessage(ChatColor.RED + "/kpm register でトークンを発行してください。"); return; } - if (!TeamKunPluginManager.session.lock()) + if (!TeamKunPluginManager.getPlugin().getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); return; @@ -86,9 +83,9 @@ public void run() "これらは無視されるか、古いものが代わりに使われます。"); finalSender.sendMessage(ChatColor.GREEN + "項目数: " + aliases); finalSender.sendMessage(ChatColor.GREEN + "S: プラグイン定義ファイルのアップデートに成功しました。"); - TeamKunPluginManager.session.unlock(); + TeamKunPluginManager.getPlugin().getSession().unlock(); } - }.runTaskAsynchronously(TeamKunPluginManager.plugin); + }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); } private static DownloadResult doDownload(CommandSender finalSender) @@ -97,7 +94,7 @@ private static DownloadResult doDownload(CommandSender finalSender) Map paths = new HashMap<>(); AtomicBoolean error = new AtomicBoolean(false); long start = System.currentTimeMillis(); - TeamKunPluginManager.config.getMapList("config") + TeamKunPluginManager.getPlugin().getConfig().getMapList("config") .forEach(s -> { String fileName; @@ -116,7 +113,10 @@ private static DownloadResult doDownload(CommandSender finalSender) connection.setRequestMethod("GET"); if (Boolean.parseBoolean(s.get("auth").toString()) && (urlObj.getHost().equals("api.github.com") || urlObj.getHost().equals("raw.githubusercontent.com"))) - connection.setRequestProperty("Authorization", "token " + TeamKunPluginManager.vault.getToken()); + connection.setRequestProperty( + "Authorization", + "token " + TeamKunPluginManager.getPlugin().getVault().getToken() + ); connection.setRequestProperty( "User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop" diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java index e2bd3b29..821c8562 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java @@ -26,7 +26,7 @@ public static void initialize(String fileName) HikariConfig config = new HikariConfig(); config.setDriverClassName("org.sqlite.JDBC"); - config.setJdbcUrl("jdbc:sqlite:" + new File(TeamKunPluginManager.plugin.getDataFolder().getPath(), fileName).getAbsolutePath()); + config.setJdbcUrl("jdbc:sqlite:" + new File(TeamKunPluginManager.getPlugin().getDataFolder().getPath(), fileName).getAbsolutePath()); config.setMaximumPoolSize(20); config.setLeakDetectionThreshold(300000); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index bb035d4c..904535e8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -89,7 +89,8 @@ public static void unInstall(CommandSender sender, String name, boolean force) } //保護されているプラグインの場合は削除せずreturn - if (TeamKunPluginManager.config.getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name))) + if (TeamKunPluginManager.getPlugin().getConfig(). + getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name))) { sender.sendMessage(ChatColor.YELLOW + "W: このプラグインは保護されています。\n" + ChatColor.YELLOW + " 保護されているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); @@ -143,7 +144,7 @@ public void run() finalSender.sendMessage(Messages.getStatusMessage(0, 1, 0)); finalSender.sendMessage(ChatColor.GREEN + "S: " + plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); } - }.runTaskLaterAsynchronously(TeamKunPluginManager.plugin, 20L); + }.runTaskLaterAsynchronously(TeamKunPluginManager.getPlugin(), 20L); } /** @@ -202,7 +203,7 @@ public static InstallResult install(CommandSender sender, String url, boolean ig //ダウンロードする場合はURL・クエリを直リンに変換 if (!withoutDownload) { - ResolveResult resolveResult = TeamKunPluginManager.resolver.resolve(url); + ResolveResult resolveResult = TeamKunPluginManager.getPlugin().getResolver().resolve(url); if (resolveResult instanceof ErrorResult) { @@ -317,7 +318,7 @@ else if (resolveResult instanceof SuccessResult) } //保護されているプラグインの場合はインスコ・変換せずreturn - if (TeamKunPluginManager.config.getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) + if (TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) { sender.sendMessage(ChatColor.RED + "E: このプラグインは保護されています。"); add--; @@ -381,7 +382,7 @@ public void run() } - }.runTaskLater(TeamKunPluginManager.plugin, 10L); + }.runTaskLater(TeamKunPluginManager.getPlugin(), 10L); } else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが変わらない(もしくは低い)。 @@ -409,7 +410,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが String fileName = downloadResult.getRight(); - TeamKunPluginManager.functional.add( + TeamKunPluginManager.getPlugin().getFunctional().add( sender instanceof Player ? ((Player) sender).getUniqueId(): null, new Say2Functional.FunctionalEntry( StringUtils::startsWithIgnoreCase, @@ -478,7 +479,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが } //クエリを直リンに変換 - ResolveResult resolveResult = TeamKunPluginManager.resolver.resolve(dependency); + ResolveResult resolveResult = TeamKunPluginManager.getPlugin().getResolver().resolve(dependency); String dependUrl; if (resolveResult instanceof ErrorResult) @@ -584,7 +585,7 @@ public void run() if (!withoutRemove && file != null) file.delete(); } - }.runTaskLaterAsynchronously(TeamKunPluginManager.plugin, 20L); + }.runTaskLaterAsynchronously(TeamKunPluginManager.getPlugin(), 20L); } //依存関係をロード @@ -659,7 +660,7 @@ public static String[] getRemovableDataDirs() try { //ignoreされているものを全て取得 - List bb = TeamKunPluginManager.config.getStringList("ignore"); + List bb = TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore"); return Arrays.stream(Objects.requireNonNull(new File("plugins/").listFiles(File::isDirectory))) //plugins/の中のフォルダを全取得 .map(File::getName) //Stream => Stream ファイルの名前 @@ -707,14 +708,14 @@ private static void depend_askToCommandSender(CommandSender sender, List { + .event(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + new ComponentBuilder(ChatColor.RED + "クリックしてこのリリースをキャンセル").create() + )) + .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/kpm i $-CF$")) + .create()); + + TeamKunPluginManager.getPlugin().getFunctional().add(uuid, new Say2Functional.FunctionalEntry(StringUtils::equalsIgnoreCase, s -> { if (s.equalsIgnoreCase("c")) { sender.sendMessage(ChatColor.RED + "E: キャンセルされました。"); @@ -827,7 +828,7 @@ public static boolean clean(String name) if (PluginUtil.isPluginLoaded(name)) return false; //プラグインがイネーブルの時、プロセスロックが掛かる - if (TeamKunPluginManager.config.getStringList("ignore").stream() + if (TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore").stream() .anyMatch(s -> s.equalsIgnoreCase(name))) // 保護されていたら除外 return false; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java index bdc87a9f..9cc7b250 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java @@ -35,7 +35,7 @@ public static void initialization(String fileName) HikariConfig config = new HikariConfig(); config.setDriverClassName("org.sqlite.JDBC"); - config.setJdbcUrl("jdbc:sqlite:" + new File(TeamKunPluginManager.plugin.getDataFolder().getPath(), fileName).getAbsolutePath()); + config.setJdbcUrl("jdbc:sqlite:" + new File(TeamKunPluginManager.getPlugin().getDataFolder().getPath(), fileName).getAbsolutePath()); config.setMaximumPoolSize(20); config.setLeakDetectionThreshold(300000); @@ -48,7 +48,7 @@ public static void initialization(String fileName) public static boolean isLegacy() { - try(Connection connection = dataSource.getConnection();) + try (Connection connection = dataSource.getConnection()) { DatabaseMetaData meta = connection.getMetaData(); ResultSet set = meta.getTables(null, null, "DEPEND", null); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java index 6563ee40..8dbba784 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin; +import lombok.AllArgsConstructor; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.event.EventHandler; @@ -10,22 +11,25 @@ import java.io.File; +@AllArgsConstructor public class PluginEventListener implements Listener { + private final TeamKunPluginManager kpmInstance; + @EventHandler public void onEnable(PluginEnableEvent e) { - if (!TeamKunPluginManager.enableBuildTree) + if (!kpmInstance.isEnableBuildTree()) return; - TeamKunPluginManager.plugin.getLogger().info("依存関係ツリーを構築中(ADD:" + e.getPlugin().getName() + ")..."); + kpmInstance.getLogger().info("依存関係ツリーを構築中(ADD:" + e.getPlugin().getName() + ")..."); DependencyTree.crawlPlugin(e.getPlugin()); - TeamKunPluginManager.plugin.getLogger().info("依存関係ツリーの構築完了"); + kpmInstance.getLogger().info("依存関係ツリーの構築完了"); } @EventHandler public void onDisable(PluginDisableEvent e) { - if (!TeamKunPluginManager.enableBuildTree) + if (!kpmInstance.isEnableBuildTree()) return; new BukkitRunnable() { @@ -36,11 +40,11 @@ public void run() File f = PluginUtil.getFile(e.getPlugin()); if (f == null || !f.exists()) { - TeamKunPluginManager.plugin.getLogger().info("依存関係ツリーを構築中(RMV:" + e.getPlugin().getName() + ")..."); + kpmInstance.getLogger().info("依存関係ツリーを構築中(RMV:" + e.getPlugin().getName() + ")..."); DependencyTree.wipePlugin(e.getPlugin()); - TeamKunPluginManager.plugin.getLogger().info("依存関係ツリーの構築完了"); + kpmInstance.getLogger().info("依存関係ツリーの構築完了"); } } - }.runTaskLater(TeamKunPluginManager.plugin, 2L); + }.runTaskLater(kpmInstance, 2L); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java index 7004d87a..36a703ae 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java @@ -54,7 +54,7 @@ public CompactBuilder addPlugin(String name) this.pre.pluginName = name; - ResolveResult result = TeamKunPluginManager.resolver.resolve(name); + ResolveResult result = TeamKunPluginManager.getPlugin().getResolver().resolve(name); if (result instanceof ErrorResult) this.rs = (BuildResult[]) ArrayUtils.add(this.rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index 55d0d885..2884f38f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -503,7 +503,7 @@ public static void load(String name) { try { - if (TeamKunPluginManager.plugin.getPluginLoader().getPluginDescription(f).getName().equalsIgnoreCase(name)) + if (TeamKunPluginManager.getPlugin().getPluginLoader().getPluginDescription(f).getName().equalsIgnoreCase(name)) { pluginFile = f; break; @@ -547,14 +547,14 @@ public void run() Bukkit.getOnlinePlayers().stream().parallel().forEach(Player::updateCommands); } - }.runTaskLater(TeamKunPluginManager.plugin, 10L); + }.runTaskLater(TeamKunPluginManager.getPlugin(), 10L); } catch (InvalidDescriptionException | InvalidPluginException e2) { e2.printStackTrace(); } } - }.runTask(TeamKunPluginManager.plugin); + }.runTask(TeamKunPluginManager.getPlugin()); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java index e278c9fd..9fc18bcb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java @@ -33,7 +33,10 @@ public static Pair postAsString(String urlString, String data, HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); if (url.getHost().equals("api.github.com")) - connection.setRequestProperty("Authorization", "token " + TeamKunPluginManager.vault.getToken()); + connection.setRequestProperty( + "Authorization", + "token " + TeamKunPluginManager.getPlugin().getVault().getToken() + ); if (url.getHost().equals("file.io")) connection.setRequestProperty("Referer", "https://www.file.io/"); connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); @@ -79,8 +82,12 @@ public static Pair getAsString(String urlString) URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); - if (url.getHost().equals("api.github.com") && !TeamKunPluginManager.vault.getToken().isEmpty()) - connection.setRequestProperty("Authorization", "token " + TeamKunPluginManager.vault.getToken()); + if (url.getHost().equals("api.github.com") && + !TeamKunPluginManager.getPlugin().getVault().getToken().isEmpty()) + connection.setRequestProperty( + "Authorization", + "token " + TeamKunPluginManager.getPlugin().getVault().getToken() + ); if (url.getHost().equals("file.io")) connection.setRequestProperty("Referer", "https://www.file.io/"); connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); @@ -138,7 +145,7 @@ public static Pair downloadFile(String url, String fileName) tryna = 0; - final int redirectLimit = TeamKunPluginManager.config.getInt("redirectLimit", 15); + final int redirectLimit = TeamKunPluginManager.getPlugin().getConfig().getInt("redirectLimit", 15); try { @@ -155,7 +162,10 @@ public static Pair downloadFile(String url, String fileName) connection.setRequestMethod("GET"); connection.setInstanceFollowRedirects(false); if (urlObj.getHost().equals("api.github.com")) - connection.setRequestProperty("Authorization", "token " + TeamKunPluginManager.vault.getToken()); + connection.setRequestProperty( + "Authorization", + "token " + TeamKunPluginManager.getPlugin().getVault().getToken() + ); connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); connection.connect(); @@ -221,7 +231,10 @@ public static int fetch(String urlString, String method) HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(method); if (url.getHost().equals("api.github.com")) - connection.setRequestProperty("Authorization", "token " + TeamKunPluginManager.vault.getToken()); + connection.setRequestProperty( + "Authorization", + "token " + TeamKunPluginManager.getPlugin().getVault().getToken() + ); connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); connection.connect(); return connection.getResponseCode(); diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java index c94e6a08..39bd609a 100644 --- a/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java +++ b/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java @@ -1,7 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.resolver; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.TokenVault; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubSuccessResult; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; @@ -10,7 +8,6 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -46,12 +43,6 @@ else if (result instanceof MultiResult) } } - @Before - public void init() - { - TeamKunPluginManager.vault = new TokenVault(); - } - @Ignore @Test public void resolveTest() From b66a1419dd7e8dbbf54119df8e21889267e4e2ba Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 28 Mar 2022 06:04:40 +0900 Subject: [PATCH 055/745] feat: Terminal --- .../terminal/framework/Input.java | 70 +++++ .../terminal/framework/InputTask.java | 95 +++++++ .../terminal/framework/Progressbar.java | 58 +++++ .../terminal/framework/Terminal.java | 242 ++++++++++++++++++ .../terminal/impl/AbstractBukkitTerminal.java | 53 ++++ .../terminal/impl/AbstractInputTask.java | 150 +++++++++++ .../terminal/impl/InputManager.java | 142 ++++++++++ .../terminal/impl/Terminals.java | 35 +++ .../impl/inputs/BasicStringInputTask.java | 33 +++ .../terminal/impl/inputs/ChoiceInputTask.java | 61 +++++ .../impl/inputs/YesNoCancelInputTask.java | 44 ++++ .../terminal/impl/inputs/YesNoInputTask.java | 59 +++++ .../terminal/impl/player/PlayerInput.java | 74 ++++++ .../impl/player/PlayerProgressbar.java | 167 ++++++++++++ .../terminal/impl/player/PlayerTerminal.java | 76 ++++++ 15 files changed, 1359 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java new file mode 100644 index 00000000..bf85029d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java @@ -0,0 +1,70 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.framework; + +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; + +/** + * データの入力を行うインターフェース + */ +public interface Input +{ + /** + * ターミナルのインスタンスを取得します。 + */ + @NotNull + Terminal getTerminal(); + + /** + * Y/N(yes/no)で回答できる質問を表示します。 + * + * @param question 質問内容 + * @return 回答 + */ + @NotNull + InputTask showYNQuestion(@NotNull String question); + + /** + * キャンセル可能な、Y/N(yes/no)で回答できる質問を表示します。 + * また、キャンセルされた場合は値に{@code null}が収納されます。 + * + * @param question 質問内容 + * @return 回答 + */ + @NotNull + InputTask showYNQuestionCancellable(@NotNull String question); + + /** + * 自由入力で回答できる質問を表示します。 + * + * @param question 質問内容 + * @return 回答 + */ + @NotNull + InputTask showInputQuestion(@NotNull String question); + + /** + * 選択式の質問を表示します。 + * + * @param question 質問 + * @param choices 選択肢 + * @return 回答 + */ + @NotNull + InputTask showChoiceQuestion(@NotNull String question, String... choices); + + /** + * 選択式の質問を表示します。 + * + * @param question 質問 + * @param choices 選択肢 + * @return 回答 + */ + @NotNull + InputTask showChoiceQuestion(@NotNull String question, @NotNull HashMap choices); + + /** + * 質問募集をキャンセルします。 + */ + void cancelQuestion(InputTask task); +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java new file mode 100644 index 00000000..fd0711df --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java @@ -0,0 +1,95 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.framework; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; +import java.util.UUID; + +public interface InputTask +{ + /** + * 入力値を設定します。 + * ブロッキングされたスレッドは解放されます。 + * + * @param value 入力値 + */ + void setValue(@NotNull String value); + + /** + * ブロッキングして入力値を取得します。 + * + * @return 入力値 + * @throws InterruptedException 入力値が取得できなかった場合/スレッドが殺された場合 + */ + @NotNull String waitAndGetValue() throws InterruptedException; + + /** + * 回答を得られるまでブロッキングします。 + */ + void waitForAnswer() throws InterruptedException; + + /** + * ブロッキングせずに入力値を取得します。 + * + * @return 入力値 + */ + @Nullable String getRawValue(); + + /** + * 入力値が取得できるかどうかを返します。 + * + * @return 入力値が取得できるかどうか + */ + boolean isValueAvailable(); + + /** + * 入力をキャンセルしまします。 + */ + default void cancel() + { + this.getInput().cancelQuestion(this); + } + + /** + * 質問のUUIDを返します。 + * + * @return 質問のUUID + */ + @NotNull UUID getUuid(); + + /** + * 質問の体操者を返します。 + * + * @return 質問の体操者 + */ + @Nullable UUID getTarget(); + + /** + * 質問で有効な入力値かどうかを返します。 + * + * @return 質問で有効な入力値かどうか + */ + boolean checkValidInput(String input); + + /** + * このタスクを作成したInputを返します。 + * + * @return このタスクを作成したInput + */ + @NotNull Input getInput(); + + /** + * 質問を出力します。 + * 実装時は {@link Terminal#info(String)} を使用することが望ましいです。 + * また、{@link InputTask#getChoices()} が内部で呼び出されます。 + */ + void printQuestion(); + + /** + * 質問の選択肢を取得します。 + * Mapの鍵はクリック時に自動入力される値で、値は表示される値です。 + * デフォルトでは {@link org.bukkit.ChatColor#GREEN} 色で表示されます。 + */ + Map getChoices(); +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java new file mode 100644 index 00000000..e658e525 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java @@ -0,0 +1,58 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.framework; + +import org.jetbrains.annotations.Nullable; + +public interface Progressbar +{ + + /** + * プログレスバーの最大値を設定します。 + * + * @param max 最大値 + */ + void setProgressMax(int max); + + /** + * プログレスバーの現在の値を設定します。 + * + * @param progress 現在の値 + */ + void setProgress(int progress); + + /** + * プログレスバーの接頭辞を変更します。 + * + * @param prefix 接頭辞 + */ + void setPrefix(@Nullable String prefix); + + /** + * プログレスバーの接尾辞を変更します。 + * + * @param suffix 接尾辞 + */ + void setSuffix(@Nullable String suffix); + + /** + * プログレスバーの大きさを変更します。 + * + * @param size 大きさ + */ + void setSize(int size); + + /** + * プログレスバーを表示します。 + * 更新の場合は {@link #update()} を呼び出してください。 + */ + void show(); + + /** + * プログレスバーを非表示にします。 + */ + void hide(); + + /** + * プログレスバーを更新します。 + */ + void update(); +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java new file mode 100644 index 00000000..0461a476 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java @@ -0,0 +1,242 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.framework; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * インストール時のInput/Outputです。 + */ +public interface Terminal +{ + /** + * 通知のデフォルトの表示時間です。 + */ + int DEFAULT_NOTIFICATION_TIME = 3000; + + /** + * ターミナルの使用者を取得します。 + */ + @NotNull Audience getAudience(); + + /** + * 情報メッセージを出力します。 + * + * @param message 出力するメッセージ + */ + void info(@NotNull String message); + + /** + * エラーメッセージを出力します。 + * + * @param message 出力するメッセージ + */ + void error(@NotNull String message); + + /** + * 成功メッセージを出力します。 + * + * @param message 出力するメッセージ + */ + void success(@NotNull String message); + + /** + * 警告メッセージを出力します。 + * + * @param message 出力するメッセージ + */ + void warn(@NotNull String message); + + /** + * メッセージを改行して出力します。 + * + * @param message 出力するメッセージ + */ + void writeLine(@NotNull String message); + + /** + * コンポーネントを出力します。 + * + * @param component 出力するコンポーネント + */ + void write(@NotNull Component component); + + /** + * プログレスバーを新規作成します。 + * + * @return プログレスバー + * @throws IllegalStateException プログレスバーが既に存在する場合 + */ + @NotNull Progressbar createProgressbar(@NotNull String name) throws IllegalStateException; + + /** + * 作成したプログレスバーを削除します。 + * + * @param name 削除するプログレスバーの名前 + * @return 削除できたかどうか + */ + boolean removeProgressbar(@NotNull String name); + + /** + * プログレスバーを取得します。 + * + * @param name 取得するプログレスバーの名前 + * @return プログレスバー + */ + @Nullable Progressbar getProgressbar(@NotNull String name); + + /** + * 通知を表示します。 + * + * @param title タイトル + * @param message メッセージ + * @param showTime 表示時間(ミリ秒) + */ + void showNotification(@NotNull String title, @NotNull String message, int showTime); + + /** + * 通知を表示します。 + * 表示時間はデフォルトでは {@link #DEFAULT_NOTIFICATION_TIME} ミリ秒です。 + * + * @param title タイトル + * @param message メッセージ + */ + default void showNotification(@NotNull String title, @NotNull String message) + { + showNotification(title, message, DEFAULT_NOTIFICATION_TIME); + } + + /** + * 通知を表示します。 + * + * @param message メッセージ + */ + default void showNotification(@NotNull String message) + { + showNotification("", message); + } + + /** + * 通知を非表示にします。 + * 通知時間中でも強制的に非表示にされます。 + */ + void clearNotification(); + + /** + * 静かかどうかを返します。 + * + * @return 静か + */ + default boolean isQuiet() + { + return false; + } + + /** + * 入力用のインタフェースを取得する + * + * @return 入力用のインタフェース + */ + Input getInput(); + + /** + * 静かなモードにします。 + * このモードを有効にした場合、{@link #info(String message)}をはじめとする出力系メソッドは文字列を出力しないようにしてください。 + * + * @return IOInterfaceのコピー + */ + default Terminal quiet() + { + return new Terminal() + { + @Override + public @NotNull Audience getAudience() + { + return Terminal.this.getAudience(); + } + + @Override + public void info(@NotNull String message) + { + + } + + @Override + public void error(@NotNull String message) + { + + } + + @Override + public void success(@NotNull String message) + { + + } + + @Override + public void warn(@NotNull String message) + { + + } + + @Override + public void writeLine(@NotNull String message) + { + + } + + @Override + public void write(@NotNull Component component) + { + + } + + @Override + public @NotNull Progressbar createProgressbar(@NotNull String name) throws IllegalStateException + { + return Terminal.this.createProgressbar(name); + } + + @Override + public boolean removeProgressbar(@NotNull String name) + { + return Terminal.this.removeProgressbar(name); + } + + @Override + public @Nullable Progressbar getProgressbar(@NotNull String name) + { + return Terminal.this.getProgressbar(name); + } + + @Override + public void showNotification(@NotNull String title, @NotNull String message, int showTime) + { + } + + @Override + public void showNotification(@NotNull String message) + { + } + + @Override + public Input getInput() + { + return Terminal.this.getInput(); + } + + @Override + public void clearNotification() + { + } + + @Override + public boolean isQuiet() + { + return true; + } + + }; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java new file mode 100644 index 00000000..48252d00 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java @@ -0,0 +1,53 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; + +public abstract class AbstractBukkitTerminal implements Terminal +{ + private final Audience audience; + + public AbstractBukkitTerminal(Audience audience) + { + this.audience = audience; + } + + @Override + public void info(@NotNull String message) + { + writeLine(ChatColor.BLUE + "I: " + message); + } + + @Override + public void error(@NotNull String message) + { + writeLine(ChatColor.RED + "E: " + message); + } + + @Override + public void success(@NotNull String message) + { + writeLine(ChatColor.GREEN + "S: " + message); + } + + @Override + public void warn(@NotNull String message) + { + writeLine(ChatColor.YELLOW + "W: " + message); + } + + @Override + public void writeLine(@NotNull String message) + { + write(Component.text(message)); + } + + @Override + public void write(@NotNull Component component) + { + audience.sendMessage(component); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java new file mode 100644 index 00000000..06aaacb4 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java @@ -0,0 +1,150 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl; + +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.InputTask; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.BasicStringInputTask; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * 入力のタスク + */ +@Getter +@EqualsAndHashCode +public abstract class AbstractInputTask implements InputTask +{ + private final UUID uuid; + private final UUID target; + private final Input input; + private final String question; + + @Getter(AccessLevel.PRIVATE) + private final Object locker; + + private String value; + @Getter(AccessLevel.PRIVATE) + private boolean valuePresent; + + public AbstractInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) + { + this.uuid = UUID.randomUUID(); + this.target = target instanceof Player ? ((Player) target).getUniqueId(): null; + this.input = input; + this.question = question; + + this.locker = new Object(); + + this.value = null; + this.valuePresent = false; + } + + @Override + public void setValue(@NotNull String value) + { + if (valuePresent) + throw new IllegalStateException("value is already set"); + + this.valuePresent = true; + this.value = value; + synchronized (locker) + { + locker.notifyAll(); + } + } + + @Override + @SuppressWarnings("ConstantConditions") + public @NotNull String waitAndGetValue() throws InterruptedException + { + waitForAnswer(); + return getRawValue(); + } + + @Override + public void waitForAnswer() throws InterruptedException + { + if (valuePresent) + return; + + synchronized (locker) + { + locker.wait(); + } + } + + @Override + public @Nullable String getRawValue() + { + return value; + } + + @Override + public boolean isValueAvailable() + { + return valuePresent; + } + + @Override + public void cancel() + { + if (valuePresent) + return; + synchronized (locker) + { + locker.notifyAll(); + } + } + + private void printSeparator(Terminal terminal) + { + terminal.writeLine(ChatColor.BLUE + ChatColor.STRIKETHROUGH.toString() + "================================================"); + } + + private void printChoices(Terminal terminal, Map choices) + { + AtomicInteger index = new AtomicInteger(1); + choices.forEach((value, text) -> terminal.write( + Component.text(ChatColor.YELLOW.toString() + index.getAndIncrement() + + " " + ChatColor.GREEN + text + "( " + value + " )") + .clickEvent(ClickEvent.suggestCommand(value)) + .hoverEvent(HoverEvent.showText( + Component.text(ChatColor.YELLOW + "クリックして補完!"))) + )); + } + + @Override + public void printQuestion() + { + Terminal terminal = input.getTerminal(); + + printSeparator(terminal); + terminal.writeLine(ChatColor.GREEN + " " + question); + + if (this instanceof BasicStringInputTask) + { + terminal.writeLine(" " + ChatColor.GREEN + "回答をチャットまたはコンソールに入力してください。"); + printSeparator(terminal); + return; + } + + Map choices = getChoices(); + if (choices != null) + printChoices(terminal, choices); + + printSeparator(terminal); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java new file mode 100644 index 00000000..fe3bf947 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java @@ -0,0 +1,142 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl; + +import io.papermc.paper.event.player.AsyncChatEvent; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.InputTask; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerCommandEvent; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * 入力のマネージャです。 + */ +public class InputManager implements Listener +{ + @Getter + private static final InputManager instance; + + static + { + instance = new InputManager(); + } + + private final Map> inputTasks; + + private InputManager() + { + inputTasks = new HashMap<>(); + } + + /** + * このマネージャをBukkitに登録します。 + * + * @param plugin 登録するプラグイン + */ + public static void register(Plugin plugin) + { + plugin.getServer().getPluginManager().registerEvents(instance, plugin); + } + + /** + * 入力タスクを追加します。 + * + * @param uuid 登録するプレイヤーのUUID。Nullの場合はコンソールからの入力を受け付け + * @param inputTask 入力タスク + */ + public void addInputTask(@Nullable UUID uuid, InputTask inputTask) + { + ArrayList inputTasks = this.inputTasks.get(uuid); + if (inputTasks == null) + inputTasks = new ArrayList<>(); + inputTasks.add(inputTask); + + if (inputTasks.size() == 1) + inputTask.printQuestion(); + this.inputTasks.put(uuid, inputTasks); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onSay(AsyncChatEvent event) + { + ArrayList inputTasks = this.inputTasks.get(event.getPlayer().getUniqueId()); + String message = ((TextComponent) event.originalMessage().asComponent()).content(); + + if (inputTasks == null || inputTasks.isEmpty()) + return; + + event.setCancelled(true); + + InputTask inputTask = inputTasks.get(0); + + if (!inputTask.checkValidInput(message)) + { + inputTask.getInput().getTerminal().error("入力が無効です:" + message); + return; + } + + inputTask.setValue(message); + inputTasks.remove(0); + if (!inputTasks.isEmpty()) + inputTasks.get(0).printQuestion(); + } + + @EventHandler + public void onConsoleSay(ServerCommandEvent e) + { + ArrayList inputTasks = this.inputTasks.get(null); + + e.setCancelled(true); + + if (inputTasks == null || inputTasks.isEmpty()) + return; + InputTask inputTask = inputTasks.get(0); + String message = e.getCommand(); + + if (!inputTask.checkValidInput(message)) + { + inputTask.getInput().getTerminal().error("入力が無効です:" + message); + return; + } + + inputTask.setValue(message); + inputTasks.remove(0); + if (!inputTasks.isEmpty()) + inputTasks.get(0).printQuestion(); + } + + /** + * 指定したプレイヤの入力タスクをすべて削除します。 + * + * @param uuid 削除するプレイヤのUUID + */ + public void cancelInputTask(UUID uuid) + { + ArrayList inputTasks = this.inputTasks.get(uuid); + if (inputTasks == null) + return; + inputTasks.clear(); + } + + /** + * 指定したプレイヤの入力タスクを削除します。 + * + * @param uuid 削除するプレイヤのUUID + * @param inputTask 削除する入力タスク + */ + public void cancelInputTask(UUID uuid, InputTask inputTask) + { + ArrayList inputTasks = this.inputTasks.get(uuid); + if (inputTasks == null) + return; + inputTasks.remove(inputTask); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java new file mode 100644 index 00000000..9f9393f3 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java @@ -0,0 +1,35 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.player.PlayerTerminal; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class Terminals +{ + private static final Map terminals; + + static + { + terminals = new HashMap<>(); + } + + private Terminals() + { + } + + public static @NotNull Terminal of(@NotNull Player player) + { + Terminal terminal = terminals.get(player.getUniqueId()); + if (terminal != null) + return terminal; + + terminal = new PlayerTerminal(player); + terminals.put(player.getUniqueId(), terminal); + return terminal; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java new file mode 100644 index 00000000..7ace5a23 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java @@ -0,0 +1,33 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractInputTask; +import net.kyori.adventure.audience.Audience; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +/** + * 標準的なテキスト入力用のタスク + */ +public class BasicStringInputTask extends AbstractInputTask +{ + + public BasicStringInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) + { + super(target, question, input); + } + + @Override + public boolean checkValidInput(String input) + { + return true; + } + + @Override + public @Nullable Map getChoices() + { + return null; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java new file mode 100644 index 00000000..65ec3df3 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java @@ -0,0 +1,61 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractInputTask; +import net.kyori.adventure.audience.Audience; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class ChoiceInputTask extends AbstractInputTask +{ + private final Map choices; + + public ChoiceInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input, @NotNull Map choices) + { + super(target, question, input); + this.choices = choices; + } + + public ChoiceInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input, String... choices) + { + super(target, question, input); + + Map choiceMap = new HashMap<>(choices.length); + for (String choice : choices) + choiceMap.put(choice, choice); + + this.choices = choiceMap; + } + + @Override + public @Nullable String getRawValue() + { + String rawValue = super.getRawValue(); + if (rawValue == null) + return null; + + if (choices.containsValue(rawValue)) + return choices.entrySet().stream().parallel() + .filter(entry -> Objects.equals(entry.getValue(), rawValue)) + .map(Map.Entry::getKey) + .findFirst().orElse(null); + + return rawValue; + } + + @Override + public boolean checkValidInput(String input) + { + return choices.containsKey(input) || choices.containsValue(input); + } + + @Override + public Map getChoices() + { + return choices; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java new file mode 100644 index 00000000..8220a9b3 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java @@ -0,0 +1,44 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; +import net.kyori.adventure.audience.Audience; +import org.apache.commons.lang.ArrayUtils; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class YesNoCancelInputTask extends YesNoInputTask +{ + private static final String[] CANCEL = new String[]{"c", "cancel", "キャンセル"}; + + public YesNoCancelInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) + { + super(target, question, input); + } + + @Override + public boolean checkValidInput(String input) + { + return super.checkValidInput(input) || ArrayUtils.contains(CANCEL, input); + } + + public boolean isCancelled() + { + + return ArrayUtils.contains(CANCEL, getValue()); + } + + public boolean waitAndIsCancelled() throws InterruptedException + { + waitForAnswer(); + return isCancelled(); + } + + @Override + public Map getChoices() + { + Map choices = super.getChoices(); + choices.put("c", "キャンセル"); + return choices; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java new file mode 100644 index 00000000..a9d2b195 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java @@ -0,0 +1,59 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractInputTask; +import net.kyori.adventure.audience.Audience; +import org.apache.commons.lang.ArrayUtils; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; + +public class YesNoInputTask extends AbstractInputTask +{ + protected static final String[] YES = new String[]{"y", "yes", "はい"}; + protected static final String[] NO = new String[]{"n", "no", "いいえ"}; + + public YesNoInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) + { + super(target, question, input); + } + + @Override + public boolean checkValidInput(String input) + { + return ArrayUtils.contains(YES, input.toLowerCase()) || + ArrayUtils.contains(NO, input.toLowerCase()); + } + + @Override + public Map getChoices() + { + return new HashMap() + {{ + put("yes", "はい"); + put("no", "いいえ"); + }}; + } + + /** + * スレッドをブロックして真偽値として値を取得します。 + * + * @return 真偽値 + * @throws InterruptedException キャンセルされた場合 + */ + public boolean waitAndGetValueAsBoolean() throws InterruptedException + { + return ArrayUtils.contains(YES, waitAndGetValue().toLowerCase()); + } + + /** + * 真偽値として値を取得します。 + * + * @return 真偽値 + */ + public boolean getValueAsBoolean() + { + return ArrayUtils.contains(YES, getValue().toLowerCase()); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java new file mode 100644 index 00000000..dde19e2f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java @@ -0,0 +1,74 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl.player; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.InputTask; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.InputManager; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.BasicStringInputTask; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.ChoiceInputTask; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.YesNoCancelInputTask; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.YesNoInputTask; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.UUID; + +public class PlayerInput implements Input +{ + @Getter + private final Terminal terminal; + + public PlayerInput(Terminal terminal) + { + this.terminal = terminal; + } + + private UUID getPlayerUUID() + { + return ((Player) terminal.getAudience()).getUniqueId(); + } + + private InputTask registerInputTask(@NotNull InputTask task) + { + InputManager.getInstance().addInputTask(getPlayerUUID(), task); + return task; + } + + @Override + public @NotNull InputTask showYNQuestion(@NotNull String question) + { + return registerInputTask(new YesNoInputTask(terminal.getAudience(), question, this)); + } + + @Override + public @NotNull InputTask showYNQuestionCancellable(@NotNull String question) + { + return registerInputTask(new YesNoCancelInputTask(terminal.getAudience(), question, this)); + } + + @Override + public @NotNull InputTask showInputQuestion(@NotNull String question) + { + return registerInputTask(new BasicStringInputTask(terminal.getAudience(), question, this)); + } + + @Override + public @NotNull InputTask showChoiceQuestion(@NotNull String question, String... choices) + { + return registerInputTask(new ChoiceInputTask(terminal.getAudience(), question, this, choices)); + } + + @Override + public @NotNull InputTask showChoiceQuestion(@NotNull String question, @NotNull HashMap choices) + { + return registerInputTask(new ChoiceInputTask(terminal.getAudience(), question, this, choices)); + } + + @Override + public void cancelQuestion(InputTask task) + { + InputManager.getInstance().cancelInputTask(getPlayerUUID(), task); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java new file mode 100644 index 00000000..687ad962 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java @@ -0,0 +1,167 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl.player; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Progressbar; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +public class PlayerProgressbar implements Progressbar +{ + private final Player player; + private final BossBar bossBar; + + private int progressMax; + private int progress; + private String prefix; + private String suffix; + private int size; + private boolean showing; + private ProgressbarType type; + + public PlayerProgressbar(Player player, ProgressbarType type) + { + this.player = player; + this.bossBar = Bukkit.createBossBar("", BarColor.GREEN, BarStyle.SOLID); + + this.type = type; + this.progressMax = 100; + this.progress = 0; + this.prefix = null; + this.suffix = null; + this.size = 10; + this.showing = false; + + this.bossBar.setVisible(false); + this.bossBar.addPlayer(player); + } + + @Override + public void setProgressMax(int max) + { + this.progressMax = max; + this.update(); + } + + @Override + public void setProgress(int progress) + { + this.progress = progress; + this.update(); + } + + @Override + public void setPrefix(@Nullable String prefix) + { + this.prefix = prefix; + this.update(); + } + + @Override + public void setSuffix(@Nullable String suffix) + { + this.suffix = suffix; + this.update(); + } + + @Override + public void setSize(int size) + { + this.size = size; + this.update(); + } + + @Override + public void show() + { + this.showing = true; + if (this.type == ProgressbarType.BOSS_BAR) + this.bossBar.setVisible(true); + this.update(); + } + + @Override + public void hide() + { + if (this.type == ProgressbarType.BOSS_BAR) + this.bossBar.setVisible(false); + this.showing = false; + } + + @Override + public void update() + { + if (!this.showing || this.progressMax == 0 || this.progress > this.progressMax) + return; + + double percent = (double) this.progress / (double) this.progressMax; + + if (this.type == ProgressbarType.ACTION_BAR) + { + StringBuilder builder = new StringBuilder(); + if (this.prefix != null) + builder.append(this.prefix); + builder.append("["); + for (int i = 0; i < this.size; i++) + { + if (i > progress * 10) + builder.append(ChatColor.RED).append("░"); + else + builder.append(ChatColor.GREEN).append("█"); + } + builder.append(ChatColor.WHITE).append("]"); + + ChatColor color; + if (percent < 0.7) + color = ChatColor.GREEN; + else if (percent < 0.9) + color = ChatColor.YELLOW; + else + color = ChatColor.RED; + + builder.append(color).append(this.progress).append(ChatColor.WHITE); + if (this.suffix != null) + builder.append(this.suffix); + this.player.sendActionBar(Component.text(builder.toString())); + } + else if (this.type == ProgressbarType.BOSS_BAR) + { + this.bossBar.setProgress(percent); + this.bossBar.setTitle((this.prefix == null ? "": this.prefix) + + ChatColor.WHITE + + "[ " + ChatColor.GREEN + this.progress + + ChatColor.WHITE + " / " + + ChatColor.GREEN + this.progressMax + + ChatColor.WHITE + " ]" + (this.suffix == null ? "": this.suffix)); + + if (this.progress > 0.7) + this.bossBar.setColor(BarColor.GREEN); + else if (this.progress > 0.4) + this.bossBar.setColor(BarColor.YELLOW); + else + this.bossBar.setColor(BarColor.RED); + } + } + + /** + * プログレスバーのタイプを変更します + * + * @param type プログレスバーのタイプ + */ + public void setType(ProgressbarType type) + { + this.hide(); + this.type = type; + this.show(); + } + + enum ProgressbarType + { + BOSS_BAR, + ACTION_BAR + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java new file mode 100644 index 00000000..7783e099 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java @@ -0,0 +1,76 @@ +package net.kunmc.lab.teamkunpluginmanager.terminal.impl.player; + +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; +import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Progressbar; +import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractBukkitTerminal; +import net.kyori.adventure.audience.Audience; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; + +public class PlayerTerminal extends AbstractBukkitTerminal +{ + private final Player player; + private final HashMap progressbars; + private final Input input; + + public PlayerTerminal(Player player) + { + super(player); + this.player = player; + this.progressbars = new HashMap<>(); + this.input = new PlayerInput(this); + } + + @Override + public @NotNull Audience getAudience() + { + return player; + } + + @Override + public @NotNull Progressbar createProgressbar(@NotNull String name) throws IllegalStateException + { + if (progressbars.containsKey(name)) + throw new IllegalStateException("Progressbar with name " + name + " already exists!"); + + Progressbar progressbar = new PlayerProgressbar(player, PlayerProgressbar.ProgressbarType.BOSS_BAR); + progressbars.put(name, progressbar); + + return progressbar; + } + + @Override + public boolean removeProgressbar(@NotNull String name) + { + return progressbars.remove(name) != null; + } + + @Override + public @Nullable Progressbar getProgressbar(@NotNull String name) + { + return progressbars.get(name); + } + + @Override + public void showNotification(@NotNull String title, @NotNull String message, int showTimeMS) + { + int ticks = showTimeMS / 50; + + this.player.sendTitle(title, message, 5, (int) (ticks * 0.5F), 10); + } + + @Override + public void clearNotification() + { + this.player.clearTitle(); + } + + @Override + public Input getInput() + { + return this.input; + } +} From c7e5301fdbc1e17e23c7fd52abf5436d49847a7a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:06:09 +0900 Subject: [PATCH 056/745] fix: Input terminal --- .../lab/teamkunpluginmanager/terminal/impl/InputManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java index fe3bf947..92d443d4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java @@ -94,10 +94,11 @@ public void onConsoleSay(ServerCommandEvent e) { ArrayList inputTasks = this.inputTasks.get(null); - e.setCancelled(true); - if (inputTasks == null || inputTasks.isEmpty()) return; + + e.setCancelled(true); + InputTask inputTask = inputTasks.get(0); String message = e.getCommand(); From 17c6d8a67656e8e2416f3dd592afba86fb7886a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 20:07:35 +0000 Subject: [PATCH 057/745] chore(deps): bump maven-shade-plugin from 3.2.4 to 3.3.0 Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.4 to 3.3.0. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.4...maven-shade-plugin-3.3.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ebfb5c0d..cee1cf51 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.3.0 package From e59987998c9b40fea342757a01a90a8839a8d248 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 2 Apr 2022 03:32:02 +0900 Subject: [PATCH 058/745] refactor: Apply peyautils --- pom.xml | 6 + .../terminal/framework/Input.java | 70 ----- .../terminal/framework/InputTask.java | 95 ------- .../terminal/framework/Progressbar.java | 58 ----- .../terminal/framework/Terminal.java | 242 ------------------ .../terminal/impl/AbstractBukkitTerminal.java | 53 ---- .../terminal/impl/AbstractInputTask.java | 150 ----------- .../terminal/impl/InputManager.java | 143 ----------- .../terminal/impl/Terminals.java | 35 --- .../impl/inputs/BasicStringInputTask.java | 33 --- .../terminal/impl/inputs/ChoiceInputTask.java | 61 ----- .../impl/inputs/YesNoCancelInputTask.java | 44 ---- .../terminal/impl/inputs/YesNoInputTask.java | 59 ----- .../terminal/impl/player/PlayerInput.java | 74 ------ .../impl/player/PlayerProgressbar.java | 167 ------------ .../terminal/impl/player/PlayerTerminal.java | 76 ------ src/main/resources/plugin.yml | 2 + 17 files changed, 8 insertions(+), 1360 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java diff --git a/pom.xml b/pom.xml index ebfb5c0d..0edef3f8 100644 --- a/pom.xml +++ b/pom.xml @@ -138,5 +138,11 @@ 5.8.2 test + + com.github.TeamKUN + PeyangPaperUtils + 1.0.0 + runtime + diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java deleted file mode 100644 index bf85029d..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Input.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.framework; - -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; - -/** - * データの入力を行うインターフェース - */ -public interface Input -{ - /** - * ターミナルのインスタンスを取得します。 - */ - @NotNull - Terminal getTerminal(); - - /** - * Y/N(yes/no)で回答できる質問を表示します。 - * - * @param question 質問内容 - * @return 回答 - */ - @NotNull - InputTask showYNQuestion(@NotNull String question); - - /** - * キャンセル可能な、Y/N(yes/no)で回答できる質問を表示します。 - * また、キャンセルされた場合は値に{@code null}が収納されます。 - * - * @param question 質問内容 - * @return 回答 - */ - @NotNull - InputTask showYNQuestionCancellable(@NotNull String question); - - /** - * 自由入力で回答できる質問を表示します。 - * - * @param question 質問内容 - * @return 回答 - */ - @NotNull - InputTask showInputQuestion(@NotNull String question); - - /** - * 選択式の質問を表示します。 - * - * @param question 質問 - * @param choices 選択肢 - * @return 回答 - */ - @NotNull - InputTask showChoiceQuestion(@NotNull String question, String... choices); - - /** - * 選択式の質問を表示します。 - * - * @param question 質問 - * @param choices 選択肢 - * @return 回答 - */ - @NotNull - InputTask showChoiceQuestion(@NotNull String question, @NotNull HashMap choices); - - /** - * 質問募集をキャンセルします。 - */ - void cancelQuestion(InputTask task); -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java deleted file mode 100644 index fd0711df..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/InputTask.java +++ /dev/null @@ -1,95 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.framework; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.UUID; - -public interface InputTask -{ - /** - * 入力値を設定します。 - * ブロッキングされたスレッドは解放されます。 - * - * @param value 入力値 - */ - void setValue(@NotNull String value); - - /** - * ブロッキングして入力値を取得します。 - * - * @return 入力値 - * @throws InterruptedException 入力値が取得できなかった場合/スレッドが殺された場合 - */ - @NotNull String waitAndGetValue() throws InterruptedException; - - /** - * 回答を得られるまでブロッキングします。 - */ - void waitForAnswer() throws InterruptedException; - - /** - * ブロッキングせずに入力値を取得します。 - * - * @return 入力値 - */ - @Nullable String getRawValue(); - - /** - * 入力値が取得できるかどうかを返します。 - * - * @return 入力値が取得できるかどうか - */ - boolean isValueAvailable(); - - /** - * 入力をキャンセルしまします。 - */ - default void cancel() - { - this.getInput().cancelQuestion(this); - } - - /** - * 質問のUUIDを返します。 - * - * @return 質問のUUID - */ - @NotNull UUID getUuid(); - - /** - * 質問の体操者を返します。 - * - * @return 質問の体操者 - */ - @Nullable UUID getTarget(); - - /** - * 質問で有効な入力値かどうかを返します。 - * - * @return 質問で有効な入力値かどうか - */ - boolean checkValidInput(String input); - - /** - * このタスクを作成したInputを返します。 - * - * @return このタスクを作成したInput - */ - @NotNull Input getInput(); - - /** - * 質問を出力します。 - * 実装時は {@link Terminal#info(String)} を使用することが望ましいです。 - * また、{@link InputTask#getChoices()} が内部で呼び出されます。 - */ - void printQuestion(); - - /** - * 質問の選択肢を取得します。 - * Mapの鍵はクリック時に自動入力される値で、値は表示される値です。 - * デフォルトでは {@link org.bukkit.ChatColor#GREEN} 色で表示されます。 - */ - Map getChoices(); -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java deleted file mode 100644 index e658e525..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Progressbar.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.framework; - -import org.jetbrains.annotations.Nullable; - -public interface Progressbar -{ - - /** - * プログレスバーの最大値を設定します。 - * - * @param max 最大値 - */ - void setProgressMax(int max); - - /** - * プログレスバーの現在の値を設定します。 - * - * @param progress 現在の値 - */ - void setProgress(int progress); - - /** - * プログレスバーの接頭辞を変更します。 - * - * @param prefix 接頭辞 - */ - void setPrefix(@Nullable String prefix); - - /** - * プログレスバーの接尾辞を変更します。 - * - * @param suffix 接尾辞 - */ - void setSuffix(@Nullable String suffix); - - /** - * プログレスバーの大きさを変更します。 - * - * @param size 大きさ - */ - void setSize(int size); - - /** - * プログレスバーを表示します。 - * 更新の場合は {@link #update()} を呼び出してください。 - */ - void show(); - - /** - * プログレスバーを非表示にします。 - */ - void hide(); - - /** - * プログレスバーを更新します。 - */ - void update(); -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java deleted file mode 100644 index 0461a476..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/framework/Terminal.java +++ /dev/null @@ -1,242 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.framework; - -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * インストール時のInput/Outputです。 - */ -public interface Terminal -{ - /** - * 通知のデフォルトの表示時間です。 - */ - int DEFAULT_NOTIFICATION_TIME = 3000; - - /** - * ターミナルの使用者を取得します。 - */ - @NotNull Audience getAudience(); - - /** - * 情報メッセージを出力します。 - * - * @param message 出力するメッセージ - */ - void info(@NotNull String message); - - /** - * エラーメッセージを出力します。 - * - * @param message 出力するメッセージ - */ - void error(@NotNull String message); - - /** - * 成功メッセージを出力します。 - * - * @param message 出力するメッセージ - */ - void success(@NotNull String message); - - /** - * 警告メッセージを出力します。 - * - * @param message 出力するメッセージ - */ - void warn(@NotNull String message); - - /** - * メッセージを改行して出力します。 - * - * @param message 出力するメッセージ - */ - void writeLine(@NotNull String message); - - /** - * コンポーネントを出力します。 - * - * @param component 出力するコンポーネント - */ - void write(@NotNull Component component); - - /** - * プログレスバーを新規作成します。 - * - * @return プログレスバー - * @throws IllegalStateException プログレスバーが既に存在する場合 - */ - @NotNull Progressbar createProgressbar(@NotNull String name) throws IllegalStateException; - - /** - * 作成したプログレスバーを削除します。 - * - * @param name 削除するプログレスバーの名前 - * @return 削除できたかどうか - */ - boolean removeProgressbar(@NotNull String name); - - /** - * プログレスバーを取得します。 - * - * @param name 取得するプログレスバーの名前 - * @return プログレスバー - */ - @Nullable Progressbar getProgressbar(@NotNull String name); - - /** - * 通知を表示します。 - * - * @param title タイトル - * @param message メッセージ - * @param showTime 表示時間(ミリ秒) - */ - void showNotification(@NotNull String title, @NotNull String message, int showTime); - - /** - * 通知を表示します。 - * 表示時間はデフォルトでは {@link #DEFAULT_NOTIFICATION_TIME} ミリ秒です。 - * - * @param title タイトル - * @param message メッセージ - */ - default void showNotification(@NotNull String title, @NotNull String message) - { - showNotification(title, message, DEFAULT_NOTIFICATION_TIME); - } - - /** - * 通知を表示します。 - * - * @param message メッセージ - */ - default void showNotification(@NotNull String message) - { - showNotification("", message); - } - - /** - * 通知を非表示にします。 - * 通知時間中でも強制的に非表示にされます。 - */ - void clearNotification(); - - /** - * 静かかどうかを返します。 - * - * @return 静か - */ - default boolean isQuiet() - { - return false; - } - - /** - * 入力用のインタフェースを取得する - * - * @return 入力用のインタフェース - */ - Input getInput(); - - /** - * 静かなモードにします。 - * このモードを有効にした場合、{@link #info(String message)}をはじめとする出力系メソッドは文字列を出力しないようにしてください。 - * - * @return IOInterfaceのコピー - */ - default Terminal quiet() - { - return new Terminal() - { - @Override - public @NotNull Audience getAudience() - { - return Terminal.this.getAudience(); - } - - @Override - public void info(@NotNull String message) - { - - } - - @Override - public void error(@NotNull String message) - { - - } - - @Override - public void success(@NotNull String message) - { - - } - - @Override - public void warn(@NotNull String message) - { - - } - - @Override - public void writeLine(@NotNull String message) - { - - } - - @Override - public void write(@NotNull Component component) - { - - } - - @Override - public @NotNull Progressbar createProgressbar(@NotNull String name) throws IllegalStateException - { - return Terminal.this.createProgressbar(name); - } - - @Override - public boolean removeProgressbar(@NotNull String name) - { - return Terminal.this.removeProgressbar(name); - } - - @Override - public @Nullable Progressbar getProgressbar(@NotNull String name) - { - return Terminal.this.getProgressbar(name); - } - - @Override - public void showNotification(@NotNull String title, @NotNull String message, int showTime) - { - } - - @Override - public void showNotification(@NotNull String message) - { - } - - @Override - public Input getInput() - { - return Terminal.this.getInput(); - } - - @Override - public void clearNotification() - { - } - - @Override - public boolean isQuiet() - { - return true; - } - - }; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java deleted file mode 100644 index 48252d00..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractBukkitTerminal.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import org.bukkit.ChatColor; -import org.jetbrains.annotations.NotNull; - -public abstract class AbstractBukkitTerminal implements Terminal -{ - private final Audience audience; - - public AbstractBukkitTerminal(Audience audience) - { - this.audience = audience; - } - - @Override - public void info(@NotNull String message) - { - writeLine(ChatColor.BLUE + "I: " + message); - } - - @Override - public void error(@NotNull String message) - { - writeLine(ChatColor.RED + "E: " + message); - } - - @Override - public void success(@NotNull String message) - { - writeLine(ChatColor.GREEN + "S: " + message); - } - - @Override - public void warn(@NotNull String message) - { - writeLine(ChatColor.YELLOW + "W: " + message); - } - - @Override - public void writeLine(@NotNull String message) - { - write(Component.text(message)); - } - - @Override - public void write(@NotNull Component component) - { - audience.sendMessage(component); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java deleted file mode 100644 index 06aaacb4..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/AbstractInputTask.java +++ /dev/null @@ -1,150 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl; - -import lombok.AccessLevel; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.InputTask; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.BasicStringInputTask; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * 入力のタスク - */ -@Getter -@EqualsAndHashCode -public abstract class AbstractInputTask implements InputTask -{ - private final UUID uuid; - private final UUID target; - private final Input input; - private final String question; - - @Getter(AccessLevel.PRIVATE) - private final Object locker; - - private String value; - @Getter(AccessLevel.PRIVATE) - private boolean valuePresent; - - public AbstractInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) - { - this.uuid = UUID.randomUUID(); - this.target = target instanceof Player ? ((Player) target).getUniqueId(): null; - this.input = input; - this.question = question; - - this.locker = new Object(); - - this.value = null; - this.valuePresent = false; - } - - @Override - public void setValue(@NotNull String value) - { - if (valuePresent) - throw new IllegalStateException("value is already set"); - - this.valuePresent = true; - this.value = value; - synchronized (locker) - { - locker.notifyAll(); - } - } - - @Override - @SuppressWarnings("ConstantConditions") - public @NotNull String waitAndGetValue() throws InterruptedException - { - waitForAnswer(); - return getRawValue(); - } - - @Override - public void waitForAnswer() throws InterruptedException - { - if (valuePresent) - return; - - synchronized (locker) - { - locker.wait(); - } - } - - @Override - public @Nullable String getRawValue() - { - return value; - } - - @Override - public boolean isValueAvailable() - { - return valuePresent; - } - - @Override - public void cancel() - { - if (valuePresent) - return; - synchronized (locker) - { - locker.notifyAll(); - } - } - - private void printSeparator(Terminal terminal) - { - terminal.writeLine(ChatColor.BLUE + ChatColor.STRIKETHROUGH.toString() + "================================================"); - } - - private void printChoices(Terminal terminal, Map choices) - { - AtomicInteger index = new AtomicInteger(1); - choices.forEach((value, text) -> terminal.write( - Component.text(ChatColor.YELLOW.toString() + index.getAndIncrement() + - " " + ChatColor.GREEN + text + "( " + value + " )") - .clickEvent(ClickEvent.suggestCommand(value)) - .hoverEvent(HoverEvent.showText( - Component.text(ChatColor.YELLOW + "クリックして補完!"))) - )); - } - - @Override - public void printQuestion() - { - Terminal terminal = input.getTerminal(); - - printSeparator(terminal); - terminal.writeLine(ChatColor.GREEN + " " + question); - - if (this instanceof BasicStringInputTask) - { - terminal.writeLine(" " + ChatColor.GREEN + "回答をチャットまたはコンソールに入力してください。"); - printSeparator(terminal); - return; - } - - Map choices = getChoices(); - if (choices != null) - printChoices(terminal, choices); - - printSeparator(terminal); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java deleted file mode 100644 index 92d443d4..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/InputManager.java +++ /dev/null @@ -1,143 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl; - -import io.papermc.paper.event.player.AsyncChatEvent; -import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.InputTask; -import net.kyori.adventure.text.TextComponent; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.server.ServerCommandEvent; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -/** - * 入力のマネージャです。 - */ -public class InputManager implements Listener -{ - @Getter - private static final InputManager instance; - - static - { - instance = new InputManager(); - } - - private final Map> inputTasks; - - private InputManager() - { - inputTasks = new HashMap<>(); - } - - /** - * このマネージャをBukkitに登録します。 - * - * @param plugin 登録するプラグイン - */ - public static void register(Plugin plugin) - { - plugin.getServer().getPluginManager().registerEvents(instance, plugin); - } - - /** - * 入力タスクを追加します。 - * - * @param uuid 登録するプレイヤーのUUID。Nullの場合はコンソールからの入力を受け付け - * @param inputTask 入力タスク - */ - public void addInputTask(@Nullable UUID uuid, InputTask inputTask) - { - ArrayList inputTasks = this.inputTasks.get(uuid); - if (inputTasks == null) - inputTasks = new ArrayList<>(); - inputTasks.add(inputTask); - - if (inputTasks.size() == 1) - inputTask.printQuestion(); - this.inputTasks.put(uuid, inputTasks); - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onSay(AsyncChatEvent event) - { - ArrayList inputTasks = this.inputTasks.get(event.getPlayer().getUniqueId()); - String message = ((TextComponent) event.originalMessage().asComponent()).content(); - - if (inputTasks == null || inputTasks.isEmpty()) - return; - - event.setCancelled(true); - - InputTask inputTask = inputTasks.get(0); - - if (!inputTask.checkValidInput(message)) - { - inputTask.getInput().getTerminal().error("入力が無効です:" + message); - return; - } - - inputTask.setValue(message); - inputTasks.remove(0); - if (!inputTasks.isEmpty()) - inputTasks.get(0).printQuestion(); - } - - @EventHandler - public void onConsoleSay(ServerCommandEvent e) - { - ArrayList inputTasks = this.inputTasks.get(null); - - if (inputTasks == null || inputTasks.isEmpty()) - return; - - e.setCancelled(true); - - InputTask inputTask = inputTasks.get(0); - String message = e.getCommand(); - - if (!inputTask.checkValidInput(message)) - { - inputTask.getInput().getTerminal().error("入力が無効です:" + message); - return; - } - - inputTask.setValue(message); - inputTasks.remove(0); - if (!inputTasks.isEmpty()) - inputTasks.get(0).printQuestion(); - } - - /** - * 指定したプレイヤの入力タスクをすべて削除します。 - * - * @param uuid 削除するプレイヤのUUID - */ - public void cancelInputTask(UUID uuid) - { - ArrayList inputTasks = this.inputTasks.get(uuid); - if (inputTasks == null) - return; - inputTasks.clear(); - } - - /** - * 指定したプレイヤの入力タスクを削除します。 - * - * @param uuid 削除するプレイヤのUUID - * @param inputTask 削除する入力タスク - */ - public void cancelInputTask(UUID uuid, InputTask inputTask) - { - ArrayList inputTasks = this.inputTasks.get(uuid); - if (inputTasks == null) - return; - inputTasks.remove(inputTask); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java deleted file mode 100644 index 9f9393f3..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/Terminals.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.player.PlayerTerminal; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class Terminals -{ - private static final Map terminals; - - static - { - terminals = new HashMap<>(); - } - - private Terminals() - { - } - - public static @NotNull Terminal of(@NotNull Player player) - { - Terminal terminal = terminals.get(player.getUniqueId()); - if (terminal != null) - return terminal; - - terminal = new PlayerTerminal(player); - terminals.put(player.getUniqueId(), terminal); - return terminal; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java deleted file mode 100644 index 7ace5a23..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/BasicStringInputTask.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractInputTask; -import net.kyori.adventure.audience.Audience; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; - -/** - * 標準的なテキスト入力用のタスク - */ -public class BasicStringInputTask extends AbstractInputTask -{ - - public BasicStringInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) - { - super(target, question, input); - } - - @Override - public boolean checkValidInput(String input) - { - return true; - } - - @Override - public @Nullable Map getChoices() - { - return null; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java deleted file mode 100644 index 65ec3df3..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/ChoiceInputTask.java +++ /dev/null @@ -1,61 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractInputTask; -import net.kyori.adventure.audience.Audience; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -public class ChoiceInputTask extends AbstractInputTask -{ - private final Map choices; - - public ChoiceInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input, @NotNull Map choices) - { - super(target, question, input); - this.choices = choices; - } - - public ChoiceInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input, String... choices) - { - super(target, question, input); - - Map choiceMap = new HashMap<>(choices.length); - for (String choice : choices) - choiceMap.put(choice, choice); - - this.choices = choiceMap; - } - - @Override - public @Nullable String getRawValue() - { - String rawValue = super.getRawValue(); - if (rawValue == null) - return null; - - if (choices.containsValue(rawValue)) - return choices.entrySet().stream().parallel() - .filter(entry -> Objects.equals(entry.getValue(), rawValue)) - .map(Map.Entry::getKey) - .findFirst().orElse(null); - - return rawValue; - } - - @Override - public boolean checkValidInput(String input) - { - return choices.containsKey(input) || choices.containsValue(input); - } - - @Override - public Map getChoices() - { - return choices; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java deleted file mode 100644 index 8220a9b3..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoCancelInputTask.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; -import net.kyori.adventure.audience.Audience; -import org.apache.commons.lang.ArrayUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public class YesNoCancelInputTask extends YesNoInputTask -{ - private static final String[] CANCEL = new String[]{"c", "cancel", "キャンセル"}; - - public YesNoCancelInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) - { - super(target, question, input); - } - - @Override - public boolean checkValidInput(String input) - { - return super.checkValidInput(input) || ArrayUtils.contains(CANCEL, input); - } - - public boolean isCancelled() - { - - return ArrayUtils.contains(CANCEL, getValue()); - } - - public boolean waitAndIsCancelled() throws InterruptedException - { - waitForAnswer(); - return isCancelled(); - } - - @Override - public Map getChoices() - { - Map choices = super.getChoices(); - choices.put("c", "キャンセル"); - return choices; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java deleted file mode 100644 index a9d2b195..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/inputs/YesNoInputTask.java +++ /dev/null @@ -1,59 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractInputTask; -import net.kyori.adventure.audience.Audience; -import org.apache.commons.lang.ArrayUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; - -public class YesNoInputTask extends AbstractInputTask -{ - protected static final String[] YES = new String[]{"y", "yes", "はい"}; - protected static final String[] NO = new String[]{"n", "no", "いいえ"}; - - public YesNoInputTask(@NotNull Audience target, @NotNull String question, @NotNull Input input) - { - super(target, question, input); - } - - @Override - public boolean checkValidInput(String input) - { - return ArrayUtils.contains(YES, input.toLowerCase()) || - ArrayUtils.contains(NO, input.toLowerCase()); - } - - @Override - public Map getChoices() - { - return new HashMap() - {{ - put("yes", "はい"); - put("no", "いいえ"); - }}; - } - - /** - * スレッドをブロックして真偽値として値を取得します。 - * - * @return 真偽値 - * @throws InterruptedException キャンセルされた場合 - */ - public boolean waitAndGetValueAsBoolean() throws InterruptedException - { - return ArrayUtils.contains(YES, waitAndGetValue().toLowerCase()); - } - - /** - * 真偽値として値を取得します。 - * - * @return 真偽値 - */ - public boolean getValueAsBoolean() - { - return ArrayUtils.contains(YES, getValue().toLowerCase()); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java deleted file mode 100644 index dde19e2f..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerInput.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl.player; - -import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.InputTask; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Terminal; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.InputManager; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.BasicStringInputTask; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.ChoiceInputTask; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.YesNoCancelInputTask; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.inputs.YesNoInputTask; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.UUID; - -public class PlayerInput implements Input -{ - @Getter - private final Terminal terminal; - - public PlayerInput(Terminal terminal) - { - this.terminal = terminal; - } - - private UUID getPlayerUUID() - { - return ((Player) terminal.getAudience()).getUniqueId(); - } - - private InputTask registerInputTask(@NotNull InputTask task) - { - InputManager.getInstance().addInputTask(getPlayerUUID(), task); - return task; - } - - @Override - public @NotNull InputTask showYNQuestion(@NotNull String question) - { - return registerInputTask(new YesNoInputTask(terminal.getAudience(), question, this)); - } - - @Override - public @NotNull InputTask showYNQuestionCancellable(@NotNull String question) - { - return registerInputTask(new YesNoCancelInputTask(terminal.getAudience(), question, this)); - } - - @Override - public @NotNull InputTask showInputQuestion(@NotNull String question) - { - return registerInputTask(new BasicStringInputTask(terminal.getAudience(), question, this)); - } - - @Override - public @NotNull InputTask showChoiceQuestion(@NotNull String question, String... choices) - { - return registerInputTask(new ChoiceInputTask(terminal.getAudience(), question, this, choices)); - } - - @Override - public @NotNull InputTask showChoiceQuestion(@NotNull String question, @NotNull HashMap choices) - { - return registerInputTask(new ChoiceInputTask(terminal.getAudience(), question, this, choices)); - } - - @Override - public void cancelQuestion(InputTask task) - { - InputManager.getInstance().cancelInputTask(getPlayerUUID(), task); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java deleted file mode 100644 index 687ad962..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerProgressbar.java +++ /dev/null @@ -1,167 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl.player; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Progressbar; -import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.boss.BarColor; -import org.bukkit.boss.BarStyle; -import org.bukkit.boss.BossBar; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; - -public class PlayerProgressbar implements Progressbar -{ - private final Player player; - private final BossBar bossBar; - - private int progressMax; - private int progress; - private String prefix; - private String suffix; - private int size; - private boolean showing; - private ProgressbarType type; - - public PlayerProgressbar(Player player, ProgressbarType type) - { - this.player = player; - this.bossBar = Bukkit.createBossBar("", BarColor.GREEN, BarStyle.SOLID); - - this.type = type; - this.progressMax = 100; - this.progress = 0; - this.prefix = null; - this.suffix = null; - this.size = 10; - this.showing = false; - - this.bossBar.setVisible(false); - this.bossBar.addPlayer(player); - } - - @Override - public void setProgressMax(int max) - { - this.progressMax = max; - this.update(); - } - - @Override - public void setProgress(int progress) - { - this.progress = progress; - this.update(); - } - - @Override - public void setPrefix(@Nullable String prefix) - { - this.prefix = prefix; - this.update(); - } - - @Override - public void setSuffix(@Nullable String suffix) - { - this.suffix = suffix; - this.update(); - } - - @Override - public void setSize(int size) - { - this.size = size; - this.update(); - } - - @Override - public void show() - { - this.showing = true; - if (this.type == ProgressbarType.BOSS_BAR) - this.bossBar.setVisible(true); - this.update(); - } - - @Override - public void hide() - { - if (this.type == ProgressbarType.BOSS_BAR) - this.bossBar.setVisible(false); - this.showing = false; - } - - @Override - public void update() - { - if (!this.showing || this.progressMax == 0 || this.progress > this.progressMax) - return; - - double percent = (double) this.progress / (double) this.progressMax; - - if (this.type == ProgressbarType.ACTION_BAR) - { - StringBuilder builder = new StringBuilder(); - if (this.prefix != null) - builder.append(this.prefix); - builder.append("["); - for (int i = 0; i < this.size; i++) - { - if (i > progress * 10) - builder.append(ChatColor.RED).append("░"); - else - builder.append(ChatColor.GREEN).append("█"); - } - builder.append(ChatColor.WHITE).append("]"); - - ChatColor color; - if (percent < 0.7) - color = ChatColor.GREEN; - else if (percent < 0.9) - color = ChatColor.YELLOW; - else - color = ChatColor.RED; - - builder.append(color).append(this.progress).append(ChatColor.WHITE); - if (this.suffix != null) - builder.append(this.suffix); - this.player.sendActionBar(Component.text(builder.toString())); - } - else if (this.type == ProgressbarType.BOSS_BAR) - { - this.bossBar.setProgress(percent); - this.bossBar.setTitle((this.prefix == null ? "": this.prefix) + - ChatColor.WHITE + - "[ " + ChatColor.GREEN + this.progress + - ChatColor.WHITE + " / " + - ChatColor.GREEN + this.progressMax + - ChatColor.WHITE + " ]" + (this.suffix == null ? "": this.suffix)); - - if (this.progress > 0.7) - this.bossBar.setColor(BarColor.GREEN); - else if (this.progress > 0.4) - this.bossBar.setColor(BarColor.YELLOW); - else - this.bossBar.setColor(BarColor.RED); - } - } - - /** - * プログレスバーのタイプを変更します - * - * @param type プログレスバーのタイプ - */ - public void setType(ProgressbarType type) - { - this.hide(); - this.type = type; - this.show(); - } - - enum ProgressbarType - { - BOSS_BAR, - ACTION_BAR - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java deleted file mode 100644 index 7783e099..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/terminal/impl/player/PlayerTerminal.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.terminal.impl.player; - -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Input; -import net.kunmc.lab.teamkunpluginmanager.terminal.framework.Progressbar; -import net.kunmc.lab.teamkunpluginmanager.terminal.impl.AbstractBukkitTerminal; -import net.kyori.adventure.audience.Audience; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; - -public class PlayerTerminal extends AbstractBukkitTerminal -{ - private final Player player; - private final HashMap progressbars; - private final Input input; - - public PlayerTerminal(Player player) - { - super(player); - this.player = player; - this.progressbars = new HashMap<>(); - this.input = new PlayerInput(this); - } - - @Override - public @NotNull Audience getAudience() - { - return player; - } - - @Override - public @NotNull Progressbar createProgressbar(@NotNull String name) throws IllegalStateException - { - if (progressbars.containsKey(name)) - throw new IllegalStateException("Progressbar with name " + name + " already exists!"); - - Progressbar progressbar = new PlayerProgressbar(player, PlayerProgressbar.ProgressbarType.BOSS_BAR); - progressbars.put(name, progressbar); - - return progressbar; - } - - @Override - public boolean removeProgressbar(@NotNull String name) - { - return progressbars.remove(name) != null; - } - - @Override - public @Nullable Progressbar getProgressbar(@NotNull String name) - { - return progressbars.get(name); - } - - @Override - public void showNotification(@NotNull String title, @NotNull String message, int showTimeMS) - { - int ticks = showTimeMS / 50; - - this.player.sendTitle(title, message, 5, (int) (ticks * 0.5F), 10); - } - - @Override - public void clearNotification() - { - this.player.clearTitle(); - } - - @Override - public Input getInput() - { - return this.input; - } -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b35a5d43..e2c5d2f9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,6 +6,8 @@ api-version: 1.16 description: Manage your plugin! website: https://kunmc.net/ +softdepend: [PeyangPaperUtils] + commands: kunpluginmanager: aliases: [pm, kpm, kunpm, kunmgmt] #devicemgmt.mscへの恨み From ea0e3e753451641908e9552cd6309953b19b23c3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 2 Apr 2022 03:56:25 +0900 Subject: [PATCH 059/745] refactor: Apply peyautils --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0edef3f8..d083ac66 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,6 @@ com.github.TeamKUN PeyangPaperUtils 1.0.0 - runtime From c69abfceb3a4cb121630172141f1f012d6d3813b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 2 Apr 2022 05:44:19 +0900 Subject: [PATCH 060/745] refactor: Improve startup sequence --- .../TeamKunPluginManager.java | 112 ++++++++++-------- .../commands/CommandInfo.java | 2 +- .../commands/CommandStatus.java | 2 +- .../commands/CommandUpdate.java | 2 +- .../plugin/Installer.java | 8 +- .../impl/BruteforceGitHubResolver.java | 4 +- .../teamkunpluginmanager/utils/URLUtils.java | 2 +- 7 files changed, 70 insertions(+), 62 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 57ec77cd..6269394a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -2,6 +2,7 @@ import lombok.Getter; import lombok.Setter; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.commands.CommandMain; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; @@ -19,7 +20,6 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; import java.io.File; @@ -30,7 +30,7 @@ public final class TeamKunPluginManager extends JavaPlugin @Getter private static TeamKunPluginManager plugin; - private FileConfiguration config; + private FileConfiguration pluginConfig; private TokenVault vault; private Say2Functional functional; @Setter @@ -38,15 +38,36 @@ public final class TeamKunPluginManager extends JavaPlugin private Session session; private PluginResolver resolver; - @Override - public void onEnable() + private static void setupDependencyTree(TeamKunPluginManager plugin) { - session = new Session(); - saveDefaultConfig(); - plugin = this; - config = getConfig(); - functional = new Say2Functional(this); - resolver = new PluginResolver(); + DependencyTree.initialize(plugin.getPluginConfig().getString("dependPath")); + DependencyTree.initializeTable(); + KnownPlugins.initialization(plugin.getPluginConfig().getString("resolvePath")); + + if (KnownPlugins.isLegacy()) + { + plugin.getLogger().warning("プラグイン定義ファイルの形式が古いです。更新しています..."); + KnownPlugins.migration(); + CommandUpdate.onCommand(Bukkit.getConsoleSender(), null); + } + + Runner.runLater(() -> { + DependencyTree.wipeAllPlugin(); + plugin.getLogger().info("依存関係ツリーを構築中..."); + DependencyTree.crawlAllPlugins(); + plugin.getLogger().info("依存関係ツリーの構築完了"); + + //すべてのPLが読み終わった後にイベントリスナを登録 + Bukkit.getPluginManager().registerEvents( + new PluginEventListener(plugin), + TeamKunPluginManager.plugin + ); + }, 1L); + } + + private static void setupResolver(TeamKunPluginManager plugin) + { + PluginResolver resolver = plugin.getResolver(); GitHubURLResolver githubResolver = new GitHubURLResolver(); resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); @@ -55,41 +76,41 @@ public void onEnable() resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); resolver.addResolver(githubResolver, "github", "gh"); - resolver.addOnNotFoundResolver(new BruteforceGitHubResolver(this, githubResolver)); + resolver.addOnNotFoundResolver(new BruteforceGitHubResolver(plugin, githubResolver)); + } - vault = new TokenVault(); + @Override + public void onDisable() + { + if (DependencyTree.dataSource != null) + DependencyTree.dataSource.close(); + if (KnownPlugins.dataSource != null) + KnownPlugins.dataSource.close(); + } - Bukkit.getPluginCommand("kunpluginmanager").setExecutor(new CommandMain()); - Bukkit.getPluginCommand("kunpluginmanager").setTabCompleter(new CommandMain()); + public boolean isTokenAvailable() + { + return !vault.getToken().isEmpty(); + } - DependencyTree.initialize(this.config.getString("dependPath")); - DependencyTree.initializeTable(); - KnownPlugins.initialization(this.config.getString("resolvePath")); + @Override + public void onEnable() + { + session = new Session(); + saveDefaultConfig(); + plugin = this; + pluginConfig = getConfig(); + functional = new Say2Functional(this); + resolver = new PluginResolver(); - if (KnownPlugins.isLegacy()) - { - getLogger().warning("プラグイン定義ファイルの形式が古いです。更新しています..."); - KnownPlugins.migration(); - CommandUpdate.onCommand(Bukkit.getConsoleSender(), null); - } + setupResolver(this); - new BukkitRunnable() - { + vault = new TokenVault(); - @Override - public void run() - { - DependencyTree.wipeAllPlugin(); - getLogger().info("依存関係ツリーを構築中..."); - DependencyTree.crawlAllPlugins(); - getLogger().info("依存関係ツリーの構築完了"); - //すべてのPLが読み終わった後にイベントリスナを登録 - Bukkit.getPluginManager().registerEvents( - new PluginEventListener(TeamKunPluginManager.this), - TeamKunPluginManager.plugin - ); - } - }.runTaskLater(this, 1L); + Bukkit.getPluginCommand("kunpluginmanager").setExecutor(new CommandMain()); + Bukkit.getPluginCommand("kunpluginmanager").setTabCompleter(new CommandMain()); + + setupDependencyTree(this); if (!new File(DATABASE_PATH).exists()) CommandUpdate.onCommand(Bukkit.getConsoleSender(), null); @@ -107,17 +128,4 @@ public void run() vault.vault(""); } - @Override - public void onDisable() - { - if (DependencyTree.dataSource != null) - DependencyTree.dataSource.close(); - if (KnownPlugins.dataSource != null) - KnownPlugins.dataSource.close(); - } - - public boolean isTokenAvailable() - { - return !vault.getToken().isEmpty(); - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index d0ad8ad7..fb59e963 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -61,7 +61,7 @@ public static void onCommand(CommandSender sender, String[] args) sender.sendMessage(pi("作成者", String.join(", ", plugin.getDescription().getAuthors()))); sender.sendMessage(pi("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); sender.sendMessage(pi("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); - sender.sendMessage(pi("保護", TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name)))); + sender.sendMessage(pi("保護", TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name)))); if (plugin.getDescription().getWebsite() != null) sender.sendMessage(pi("ウェブサイト", ChatColor.UNDERLINE + plugin.getDescription().getWebsite())); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java index 3c484b8e..a163a11d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java @@ -30,7 +30,7 @@ public static void onCommand(CommandSender sender, String[] args) File resolve = new File( TeamKunPluginManager.getPlugin().getDataFolder(), - TeamKunPluginManager.getPlugin().getConfig().getString("resolvePath") + TeamKunPluginManager.getPlugin().getPluginConfig().getString("resolvePath") ); if (resolve.exists()) sender.sendMessage(pi("最終アップデート", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(resolve.lastModified())))); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 630d141c..11884e32 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -94,7 +94,7 @@ private static DownloadResult doDownload(CommandSender finalSender) Map paths = new HashMap<>(); AtomicBoolean error = new AtomicBoolean(false); long start = System.currentTimeMillis(); - TeamKunPluginManager.getPlugin().getConfig().getMapList("config") + TeamKunPluginManager.getPlugin().getPluginConfig().getMapList("config") .forEach(s -> { String fileName; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 904535e8..dd2135f5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -89,7 +89,7 @@ public static void unInstall(CommandSender sender, String name, boolean force) } //保護されているプラグインの場合は削除せずreturn - if (TeamKunPluginManager.getPlugin().getConfig(). + if (TeamKunPluginManager.getPlugin().getPluginConfig(). getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name))) { sender.sendMessage(ChatColor.YELLOW + "W: このプラグインは保護されています。\n" + @@ -318,7 +318,7 @@ else if (resolveResult instanceof SuccessResult) } //保護されているプラグインの場合はインスコ・変換せずreturn - if (TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) + if (TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) { sender.sendMessage(ChatColor.RED + "E: このプラグインは保護されています。"); add--; @@ -660,7 +660,7 @@ public static String[] getRemovableDataDirs() try { //ignoreされているものを全て取得 - List bb = TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore"); + List bb = TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore"); return Arrays.stream(Objects.requireNonNull(new File("plugins/").listFiles(File::isDirectory))) //plugins/の中のフォルダを全取得 .map(File::getName) //Stream => Stream ファイルの名前 @@ -828,7 +828,7 @@ public static boolean clean(String name) if (PluginUtil.isPluginLoaded(name)) return false; //プラグインがイネーブルの時、プロセスロックが掛かる - if (TeamKunPluginManager.getPlugin().getConfig().getStringList("ignore").stream() + if (TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream() .anyMatch(s -> s.equalsIgnoreCase(name))) // 保護されていたら除外 return false; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java index a00cd5d0..5a01e594 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java @@ -20,7 +20,7 @@ public class BruteforceGitHubResolver implements BaseResolver public ResolveResult resolve(QueryContext query) { - Object obj = plugin.getConfig().get("gitHubName"); + Object obj = plugin.getPluginConfig().get("gitHubName"); if (obj instanceof String) // Legacy support { @@ -33,7 +33,7 @@ public ResolveResult resolve(QueryContext query) ResolveResult result = new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); - for (String str : plugin.getConfig().getStringList("gitHubName")) + for (String str : plugin.getPluginConfig().getStringList("gitHubName")) { query.setQuery("https://github.com/" + str + "/" + query.getQuery()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java index 9fc18bcb..827bfdd5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java @@ -145,7 +145,7 @@ public static Pair downloadFile(String url, String fileName) tryna = 0; - final int redirectLimit = TeamKunPluginManager.getPlugin().getConfig().getInt("redirectLimit", 15); + final int redirectLimit = TeamKunPluginManager.getPlugin().getPluginConfig().getInt("redirectLimit", 15); try { From 8a7d202d6fafddd893cfc8d2b91d8e39dc56c8b1 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 9 Apr 2022 13:59:06 +0900 Subject: [PATCH 061/745] revert: Remove import/export --- .../commands/CommandExport.java | 239 ------------------ .../commands/CommandImport.java | 181 ------------- .../commands/CommandMain.java | 14 +- .../plugin/compactor/BuildResult.java | 8 - .../plugin/compactor/CompactBuilder.java | 84 ------ .../plugin/compactor/PluginCompacter.java | 31 --- .../plugin/compactor/PluginContainer.java | 33 --- .../plugin/compactor/PluginPreCompacter.java | 110 -------- .../utils/FileUploadUtil.java | 60 ----- .../teamkunpluginmanager/utils/Messages.java | 2 - src/main/resources/plugin.yml | 8 +- 11 files changed, 2 insertions(+), 768 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/BuildResult.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginCompacter.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginContainer.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginPreCompacter.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/FileUploadUtil.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java deleted file mode 100644 index 3c9b6061..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandExport.java +++ /dev/null @@ -1,239 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; -import net.kunmc.lab.teamkunpluginmanager.plugin.compactor.PluginCompacter; -import net.kunmc.lab.teamkunpluginmanager.plugin.compactor.PluginPreCompacter; -import net.kunmc.lab.teamkunpluginmanager.utils.FileUploadUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; -import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.ArrayUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; - -public class CommandExport -{ - public static final UUID CONSOLE_UUID = UUID.randomUUID(); - public static HashMap session = new HashMap<>(); - - public static void onCommand(CommandSender sender, String[] args) - { - if (!sender.hasPermission("kpm.export")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - - if (args.length < 1) - { - sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); - sender.sendMessage(ChatColor.RED + "使用法: /kpm export [プラグイン名2]..."); - return; - } - - if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) - { - sender.sendMessage(ChatColor.RED + "E: トークンがセットされていません!"); - sender.sendMessage(ChatColor.RED + "/kpm register でトークンを発行してください。"); - return; - } - - if (DependencyTree.isErrors()) - { - sender.sendMessage(Messages.getErrorMessage()); - sender.sendMessage(ChatColor.RED + "E: エラーが検出されたため、システムが保護されました。"); - return; - } - - UUID sessionKey = sender instanceof Player ? ((Player) sender).getUniqueId(): CONSOLE_UUID; - - if (session.containsKey(sessionKey)) - { - sender.sendMessage(ChatColor.RED + "E: 既にエクスポートセッションが有効です。"); - return; - } - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "情報を変換中..."); - - args = Arrays.stream(args).parallel().map(String::toLowerCase).toArray(String[]::new); - - String[] validPlugin; - if (args[0].equals("all")) - validPlugin = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).toArray(String[]::new); - else - { - String[] finalArgs = args; - validPlugin = Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() - .map(Plugin::getName) - .map(String::toLowerCase) - .filter(name -> containsIgnoreCase(finalArgs, name)) - .toArray(String[]::new); - } - - if (validPlugin.length == 0) - { - sender.sendMessage(ChatColor.RED + "E: エクスポート可能なプラグインが見つかりませんでした。"); - return; - } - - sender.sendMessage(ChatColor.GREEN + "この操作で、以下のプラグインがエクスポートされます: "); - sender.sendMessage(ChatColor.GREEN + Arrays.stream(validPlugin).map(s -> Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(s)).getName()).collect(Collectors.joining(" "))); - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); - - String[] finalValidPlugin = validPlugin; - String[] dependencies = Arrays.stream(validPlugin) - .flatMap(plugin -> DependencyTree.getInfo(plugin, false).depends.stream()) - .map(depend -> depend.depend.toLowerCase()) - .filter(s -> !containsIgnoreCase(Arrays.stream(finalValidPlugin).map(String::toLowerCase).toArray(String[]::new), s)) - .distinct() - .toArray(String[]::new); - - if (dependencies.length != 0) - { - sender.sendMessage(ChatColor.GREEN + "また、追加で以下のプラグインがエクスポートされます。"); - sender.sendMessage(ChatColor.GREEN + Arrays.stream(dependencies).map(s -> Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(s)).getName()).collect(Collectors.joining(" "))); - } - - - validPlugin = (String[]) ArrayUtils.addAll(validPlugin, dependencies); - - validPlugin = Arrays.stream(validPlugin) - .map(s -> Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(s)).getName()) - .filter(s -> !s.equals("TeamKunPluginManager")) - .toArray(String[]::new); - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "プラグインをバンドル中..."); - - PluginPreCompacter compacter = new PluginPreCompacter(); - compacter.addAll(validPlugin); - session.put(sender instanceof Player ? ((Player) sender).getUniqueId(): CONSOLE_UUID, compacter); - fixError(sender instanceof Player ? ((Player) sender).getUniqueId(): CONSOLE_UUID, null); - //fixErrorに引き継ぎする - } - - private static void fixError(UUID uuid, String name) - { - PluginPreCompacter ppc = session.get(uuid); - if (ppc == null) - return; - if (!ppc.isErrors()) - { - runExec(uuid, ppc); - return; - } - - CommandSender sender = uuid == CONSOLE_UUID ? Bukkit.getConsoleSender(): Bukkit.getPlayer(uuid); - - if (sender == null) - { - session.remove(uuid); - return; - } - - final String target; - if (name == null) - target = ppc.nextUrlError(); - else - target = name; - - - sender.sendMessage(ChatColor.RED + "プラグイン " + - ChatColor.GOLD + "'" + target + "' " + - ChatColor.RED + "のダウンロードURLの解決に失敗しました。"); - if (uuid == CONSOLE_UUID) - sender.sendMessage(ChatColor.GREEN + "これを解決するには、コンソールでURLを発言してください。"); - else - sender.sendMessage(ChatColor.GREEN + "これを解決するには、チャットでURLを発言してください。"); - - TeamKunPluginManager.getPlugin().getFunctional().add(uuid == CONSOLE_UUID ? null: uuid, new Say2Functional.FunctionalEntry(String::startsWith, s -> { - ppc.fixUrl(target, s); - sender.sendMessage(ChatColor.GREEN + "プラグイン " + - ChatColor.GOLD + "'" + target + "' " + - ChatColor.GREEN + "のダウンロードURLを解決しました。"); - fixError(uuid, ppc.nextUrlError()); - })); - } - - private static void runExec(UUID uuid, PluginPreCompacter ppc) - { - CommandSender sender = uuid == CONSOLE_UUID ? Bukkit.getConsoleSender(): Bukkit.getPlayer(uuid); - - if (sender == null) - { - session.remove(uuid); - return; - } - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "情報を読み込み中..."); - - PluginCompacter pc = ppc.getCompacter(); - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "データを書き込み中..."); - - SimpleDateFormat f = new SimpleDateFormat("yyyyMMddhhmmss"); - - File exportAs = new File( - TeamKunPluginManager.getPlugin().getDataFolder(), - "exports/" + f.format(new Date()) + ".pmx" - ); - - String json = pc.build(); - try - { - FileUtils.writeStringToFile(exportAs, json, StandardCharsets.UTF_8, false); - } - catch (IOException e) - { - sender.sendMessage(ChatColor.RED + "E: データの書き込みに失敗しました。"); - session.remove(uuid); - e.printStackTrace(); - return; - } - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "ファイルをアップロードしています..."); - Optional up = FileUploadUtil.uploadFile(exportAs); - if (!up.isPresent()) - sender.sendMessage(ChatColor.YELLOW + "W: ファイルアップロードに失敗しました。\n" + - ChatColor.YELLOW + "エクスポートを使用するには、直接ファイルを参照する必要がございます。"); - else - { - JsonObject object = new Gson().fromJson(up.get(), JsonObject.class); - if (!object.get("success").getAsBoolean()) - sender.sendMessage(ChatColor.YELLOW + "W: ファイルアップロードに失敗しました。\n" + - ChatColor.YELLOW + "エクスポートを使用するには、直接ファイルを参照する必要がございます。"); - else - { - sender.sendMessage(ChatColor.GREEN + "ファイルを正常にアップロードしました: " + - ChatColor.GOLD + ChatColor.UNDERLINE + object.get("link").getAsString()); - sender.sendMessage(ChatColor.GRAY + ChatColor.ITALIC.toString() + "このファイルはアクセスまたは時間経過で自動的に削除されます。"); - } - } - - sender.sendMessage(ChatColor.GREEN + "S: プラグインのエクスポートに成功しました。"); - session.remove(uuid); - } - - public static boolean containsIgnoreCase(String[] target, String maf) - { - return Arrays.stream(target).parallel().anyMatch(maf::equalsIgnoreCase); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java deleted file mode 100644 index d6b746f3..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandImport.java +++ /dev/null @@ -1,181 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; - -import com.google.gson.Gson; -import com.google.gson.JsonParseException; -import com.google.gson.reflect.TypeToken; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; -import net.kunmc.lab.teamkunpluginmanager.plugin.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; -import net.kunmc.lab.teamkunpluginmanager.plugin.compactor.PluginContainer; -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.validator.routines.UrlValidator; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; -import org.yaml.snakeyaml.Yaml; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.concurrent.atomic.AtomicInteger; - -public class CommandImport -{ - public static void onCommand(CommandSender sender, String[] args) - { - if (!sender.hasPermission("kpm.import")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - - TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - - if (!kpmInstance.getSession().lock()) - { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); - return; - } - - if (args.length < 1) - { - sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); - sender.sendMessage(ChatColor.RED + "使用法: /kpm import URL"); - kpmInstance.getSession().unlock(); - return; - } - - String url = args[0]; - AtomicInteger add = new AtomicInteger(); - AtomicInteger remove = new AtomicInteger(); - AtomicInteger modify = new AtomicInteger(); - - if (!UrlValidator.getInstance().isValid(url)) - { - sender.sendMessage(ChatColor.RED + "E: 第一引数に適切なURLを入力してください。"); - sender.sendMessage(Messages.getStatusMessage(add.get(), remove.get(), modify.get())); - kpmInstance.getSession().unlock(); - return; - } - - sender.sendMessage(ChatColor.GOLD + "ファイルのダウンロード中..."); - - Pair json = URLUtils.getAsString(url); - - switch (json.getLeft()) - { - case 404: - sender.sendMessage(ChatColor.RED + "E: ファイルが見つかりませんでした。"); - break; - case 403: - sender.sendMessage(ChatColor.RED + "E: ファイルを取得できません。しばらくしてからもう一度インポートしてください。"); - break; - } - - if (json.getLeft() != 200) - { - sender.sendMessage(ChatColor.RED + "E: 不明なエラーが発生しました。"); - return; - } - - sender.sendMessage(ChatColor.GOLD + "ファイルの読み込み中..."); - - LinkedList container; - try - { - container = new Gson().fromJson(json.getRight(), new TypeToken>() - { - }.getType()); - } - catch (JsonParseException e) - { - sender.sendMessage(ChatColor.RED + "E: JSONファイルが正しくないようです。"); - kpmInstance.getSession().unlock(); - return; - } - - ArrayList results = new ArrayList<>(); - - - container.stream().parallel() - .forEach(pluginContainer -> { - InstallResult result = Installer.install(null, pluginContainer.downloadUrl, true, true, true, false); - add.addAndGet(result.getAdd()); - remove.addAndGet(result.getRemove()); - modify.addAndGet(result.getModify()); - results.add(result); - }); - - - ArrayList loadOrder = PluginUtil.mathLoadOrder(results); - - kpmInstance.setEnableBuildTree(false); - - sender.sendMessage(ChatColor.GOLD + "設定を書き込み中..."); - - container.stream().parallel().forEach(pluginContainer -> { - if (pluginContainer.config == null || pluginContainer.config.size() == 0) - return; - Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginContainer.pluginName); - if (!PluginUtil.isPluginLoaded(plugin)) - return; - - - try - { - FileUtils.writeStringToFile(new File(plugin.getDataFolder(), "config.yml"), new Yaml().dump(pluginContainer.config), StandardCharsets.UTF_8, false); - - } - catch (IOException e) - { - e.printStackTrace(); - sender.sendMessage(ChatColor.RED + "プラグイン '" + pluginContainer.pluginName + "' の設定の保存に失敗しました。"); - } - }); - - loadOrder.forEach(installResult -> { - if (!installResult.isSuccess()) - return; - if (PluginUtil.isPluginLoaded(installResult.getPluginName())) - { - JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(installResult.getPluginName()); - - PluginUtil.unload(plugin); - - new BukkitRunnable() - { - - @Override - public void run() - { - File file = PluginUtil.getFile(plugin); - if (file != null) - file.delete(); - } - }.runTaskLaterAsynchronously(kpmInstance, 20L); - } - PluginUtil.load(installResult.getFileName().substring(0, installResult.getFileName().length() - 4)); - sender.sendMessage(ChatColor.GREEN + "+ " + installResult.getPluginName()); - }); - kpmInstance.setEnableBuildTree(true); - sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを構築中..."); - container.parallelStream().forEach(pluginContainer -> { - DependencyTree.crawlPlugin(pluginContainer.pluginName); - }); - - - sender.sendMessage(ChatColor.GREEN + "S: 正常にインポートしました。"); - sender.sendMessage(Messages.getStatusMessage(add.get(), remove.get(), modify.get())); - kpmInstance.getSession().unlock(); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java index 73c554c0..f7e24026 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java @@ -67,12 +67,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St case "info": CommandInfo.onCommand(sender, argsList.toArray(new String[0])); break; - case "export": - CommandExport.onCommand(sender, argsList.toArray(new String[0])); - break; - case "import": - CommandImport.onCommand(sender, argsList.toArray(new String[0])); - break; case "register": CommandRegister.onCommand(sender, argsList.toArray(new String[0])); break; @@ -100,7 +94,7 @@ public List onTabComplete(CommandSender sender, Command command, String switch (args.length) { case 1: - completes.addAll(Arrays.asList("install", "i", "uninstall", "remove", "rm", "status", "autoremove", "fix", "update", "clean", "info", "export", "import", "register")); + completes.addAll(Arrays.asList("install", "i", "uninstall", "remove", "rm", "status", "autoremove", "fix", "update", "clean", "info", "register")); break; case 2: String cmd = args[0]; @@ -123,12 +117,6 @@ public List onTabComplete(CommandSender sender, Command command, String } } - if (args.length > 1 && args[0].equals("export")) - { - completes = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toCollection(ArrayList::new)); - completes.add("all"); - } - ArrayList asCopy = new ArrayList<>(); StringUtil.copyPartialMatches(args[args.length - 1], completes, asCopy); Collections.sort(asCopy); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/BuildResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/BuildResult.java deleted file mode 100644 index 9cf014d2..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/BuildResult.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.compactor; - -public enum BuildResult -{ - OK, - DOWNLOAD_LINK_RESOLVE_FAILED, - CONFIG_RESOLVE_FAILED -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java deleted file mode 100644 index 36a703ae..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/CompactBuilder.java +++ /dev/null @@ -1,84 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.compactor; - -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import org.apache.commons.lang.ArrayUtils; - -import java.util.Map; - -public class CompactBuilder implements Cloneable -{ - - private final PluginCompacter pc; - private PluginContainer pre; - private BuildResult[] rs; - - public CompactBuilder(PluginCompacter comp) - { - this.pre = new PluginContainer(); - this.pc = comp; - this.rs = new BuildResult[]{}; - } - - @Override - protected Object clone() - { - CompactBuilder builder = null; - try - { - builder = (CompactBuilder) super.clone(); - builder.pre = (PluginContainer) this.pre.clone(); - } - catch (Exception e) - { - e.printStackTrace(); - } - return builder; - } - - public PluginContainer build() - { - return pre; - } - - public PluginContainer getPre() - { - return pre; - } - - public CompactBuilder addPlugin(String name) - { - rs = new BuildResult[]{}; - - this.pre.pluginName = name; - - ResolveResult result = TeamKunPluginManager.getPlugin().getResolver().resolve(name); - - if (result instanceof ErrorResult) - this.rs = (BuildResult[]) ArrayUtils.add(this.rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED); - else if (result instanceof SuccessResult) - this.pre.downloadUrl = ((SuccessResult) result).getDownloadUrl(); - - return this; - } - - public CompactBuilder applyUrl(String url) - { - this.pre.downloadUrl = url; - this.rs = (BuildResult[]) ArrayUtils.removeElement(this.rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED); - return this; - } - - public CompactBuilder applyConfig(Map map) - { - this.pre.config = map; - return this; - } - - public boolean isResolveFailed() - { - return ArrayUtils.contains(this.rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginCompacter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginCompacter.java deleted file mode 100644 index b00122bd..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginCompacter.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.compactor; - -import com.google.gson.Gson; - -import java.util.ArrayList; - -public class PluginCompacter -{ - private final ArrayList container; - - public PluginCompacter() - { - this.container = new ArrayList<>(); - } - - public void apply(PluginContainer pc) - { - this.container.add(pc); - } - - public CompactBuilder builder() - { - return new CompactBuilder(this); - } - - public String build() - { - return new Gson().toJson(this.container); - } - -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginContainer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginContainer.java deleted file mode 100644 index c126c8c5..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginContainer.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.compactor; - -import java.util.Map; - -public class PluginContainer implements Cloneable -{ - public String pluginName; - public String downloadUrl; - public Map config; - - public void clean() - { - this.pluginName = null; - this.downloadUrl = null; - this.config = null; - } - - @Override - protected Object clone() - { - PluginContainer container = null; - try - { - container = (PluginContainer) super.clone(); - return container; - } - catch (Exception e) - { - e.printStackTrace(); - } - return container; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginPreCompacter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginPreCompacter.java deleted file mode 100644 index dcae7e85..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/compactor/PluginPreCompacter.java +++ /dev/null @@ -1,110 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.compactor; - -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import org.bukkit.Bukkit; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; - -public class PluginPreCompacter -{ - private final PluginCompacter compacter; - private final ArrayList resolveFailed; - private ArrayList builder; - - public PluginPreCompacter() - { - this.compacter = new PluginCompacter(); - this.resolveFailed = new ArrayList<>(); - this.builder = new ArrayList<>(); - } - - public CompactBuilder getBuilderFromName(String name) - { - AtomicReference result = new AtomicReference<>(); - builder.forEach(compactBuilder -> { - if (compactBuilder.getPre().pluginName.equalsIgnoreCase(name)) - result.set(compactBuilder); - }); - - return result.get(); - } - - public void fixUrl(String name, String url) - { - if (!resolveFailed.contains(name)) - return; - - AtomicReference rm = new AtomicReference<>(); - AtomicReference ad = new AtomicReference<>(); - this.builder.forEach(compactBuilder -> { - CompactBuilder builder = getBuilderFromName(name); - if (builder == null) - return; - rm.set(builder); - ad.set(((CompactBuilder) builder.clone()).applyUrl(url)); - resolveFailed.remove(name); - }); - if (rm.get() != null) - this.builder.remove(rm.get()); - if (ad.get() != null) - this.builder.add(ad.get()); - - applyAll(); - } - - public String nextUrlError() - { - if (resolveFailed.size() == 0) - return null; - return resolveFailed.get(resolveFailed.size() - 1); - } - - public void addAll(String[] target) - { - Arrays.stream(target).parallel() - .forEach(s -> { - CompactBuilder builder = new CompactBuilder(this.compacter); - builder.addPlugin(s); - builder.applyConfig(PluginUtil.getConfig(Bukkit.getPluginManager().getPlugin(s))); - this.builder.add(builder); - if (builder.isResolveFailed()) - this.resolveFailed.add(s); - }); - applyAll(); - } - - public boolean isErrors() - { - return this.nextUrlError() != null; - } - - public PluginCompacter getCompacter() - { - return compacter; - } - - public void applyAll() - { - this.builder = this.builder.parallelStream().filter(b -> { - if (b.isResolveFailed()) - return true; - compacter.apply(b.build()); - return false; - }).collect(Collectors.toCollection(ArrayList::new)); - - } - - public void bundleConfig(String name, Map config) - { - CompactBuilder builder = getBuilderFromName(name); - if (builder == null) - return; - builder.applyConfig(config); - } - - -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/FileUploadUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/FileUploadUtil.java deleted file mode 100644 index bafbe3a9..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/FileUploadUtil.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.Optional; -import java.util.UUID; - -public class FileUploadUtil -{ - private static final String PROVIDER_ = "https://file.io/?expires=1d"; - private static final String PARAM_ = "file"; - private static final String METHOD_ = "POST"; - - public static Optional uploadFile(File f) - { - if (!f.exists()) - return Optional.empty(); - - try (FileInputStream stream = new FileInputStream(f)) - { - HttpURLConnection connection = (HttpURLConnection) new URL(PROVIDER_).openConnection(); - connection.setRequestMethod(METHOD_); - connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); - final UUID boundary = UUID.randomUUID(); - connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); - connection.setDoOutput(true); - connection.connect(); - try (OutputStream out = connection.getOutputStream()) - { - out.write(("--" + boundary + "\r\n" + - "Content-Disposition: form-data; name=\"" + PARAM_ + "\"; " + - "filename=\"" + f.getName() + "\"\r\n" + - "Content-Type: application/octet-stream" + "\r\n\r\n") - .getBytes(StandardCharsets.UTF_8) - ); - - byte[] buffer = new byte[1024]; - int size = -1; - while ((size = stream.read(buffer)) != -1) - out.write(buffer, 0, size); - out.write(("\r\n--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8)); - out.flush(); - if (connection.getResponseCode() != 200) - return Optional.empty(); - return Optional.of(IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8)); - } - } - catch (Exception e) - { - e.printStackTrace(); - return Optional.empty(); - } - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java index c95ddfb1..db4e9db3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java @@ -20,8 +20,6 @@ public static String getCommandNotFoundMessage() " " + commandMessageBuilder("fix", "エラーを修復します。\n" + ChatColor.YELLOW + " メッセージがあった場合のみ実行してください。") + "\n" + " " + commandMessageBuilder("clean", "不要になったプラグインデータを削除します。") + "\n" + - " " + commandMessageBuilder("export", "プラグインをエクスポートします。") + "\n" + - " " + commandMessageBuilder("import", "エクスポートしたファイルからインポートします。") + "\n" + " " + commandMessageBuilder("register", "トークンを発行します。") + "\n"; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e2c5d2f9..fa34c8c0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -11,7 +11,7 @@ softdepend: [PeyangPaperUtils] commands: kunpluginmanager: aliases: [pm, kpm, kunpm, kunmgmt] #devicemgmt.mscへの恨み - usage: "/kpm [Plugin name | URL | Repository Name]" + usage: "/kpm [Plugin name | URL | Repository Name]" permissions: @@ -28,8 +28,6 @@ permissions: kpm.fix: true kpm.status: true kpm.update: true - kpm.export: true - kpm.import: true kpm.install: description: "プラグインをインストールできます。" kpm.uninstall: @@ -48,7 +46,3 @@ permissions: description: "プラグインの状態を閲覧します。" kpm.update: description: "エイリアス定義データベースを更新します。" - kpm.export: - description: "プラグインとデータをエクスポートします。" - kpm.import: - description: "プラグインとデータをインポートします。" From 42fddfed338cec45790ffcd80d03205e08f23a68 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 11 Apr 2022 16:25:46 +0900 Subject: [PATCH 062/745] refactor: Apply peyautils to command --- pom.xml | 2 +- .../TeamKunPluginManager.java | 37 ++- .../commands/CommandAutoRemove.java | 71 +++-- .../commands/CommandClean.java | 203 ++++++-------- .../commands/CommandFix.java | 52 +++- .../commands/CommandInfo.java | 180 ++++++------ .../commands/CommandInstall.java | 80 +++--- .../commands/CommandMain.java | 125 --------- .../commands/CommandRegister.java | 265 ++++++++++-------- .../commands/CommandReload.java | 79 ++++-- .../commands/CommandStatus.java | 62 ++-- .../commands/CommandUninstall.java | 77 +++-- .../commands/CommandUpdate.java | 162 ++++++----- .../teamkunpluginmanager/utils/Messages.java | 41 ++- src/main/resources/plugin.yml | 4 +- 15 files changed, 758 insertions(+), 682 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java diff --git a/pom.xml b/pom.xml index a68d9c8f..38300df0 100644 --- a/pom.xml +++ b/pom.xml @@ -141,7 +141,7 @@ com.github.TeamKUN PeyangPaperUtils - 1.0.0 + 1.0.4 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 6269394a..a80685f4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -2,8 +2,18 @@ import lombok.Getter; import lombok.Setter; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandManager; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandMain; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandAutoRemove; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandClean; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandFix; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandInfo; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandInstall; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandRegister; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandReload; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandStatus; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandUninstall; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; @@ -37,6 +47,7 @@ public final class TeamKunPluginManager extends JavaPlugin private boolean enableBuildTree = true; private Session session; private PluginResolver resolver; + private CommandManager commandManager; private static void setupDependencyTree(TeamKunPluginManager plugin) { @@ -48,7 +59,7 @@ private static void setupDependencyTree(TeamKunPluginManager plugin) { plugin.getLogger().warning("プラグイン定義ファイルの形式が古いです。更新しています..."); KnownPlugins.migration(); - CommandUpdate.onCommand(Bukkit.getConsoleSender(), null); + new CommandUpdate().onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); } Runner.runLater(() -> { @@ -93,6 +104,20 @@ public boolean isTokenAvailable() return !vault.getToken().isEmpty(); } + public static void registerCommands(CommandManager commandManager) + { + commandManager.registerCommand("autoremove", new CommandAutoRemove()); + commandManager.registerCommand("clean", new CommandClean()); + commandManager.registerCommand("fix", new CommandFix()); + commandManager.registerCommand("info", new CommandInfo()); + commandManager.registerCommand("install", new CommandInstall()); + commandManager.registerCommand("register", new CommandRegister()); + commandManager.registerCommand("reload", new CommandReload()); + commandManager.registerCommand("status", new CommandStatus()); + commandManager.registerCommand("uninstall", new CommandUninstall()); + commandManager.registerCommand("update", new CommandUpdate()); + } + @Override public void onEnable() { @@ -102,18 +127,18 @@ public void onEnable() pluginConfig = getConfig(); functional = new Say2Functional(this); resolver = new PluginResolver(); + commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); + + registerCommands(commandManager); setupResolver(this); vault = new TokenVault(); - Bukkit.getPluginCommand("kunpluginmanager").setExecutor(new CommandMain()); - Bukkit.getPluginCommand("kunpluginmanager").setTabCompleter(new CommandMain()); - setupDependencyTree(this); if (!new File(DATABASE_PATH).exists()) - CommandUpdate.onCommand(Bukkit.getConsoleSender(), null); + new CommandUpdate().onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); String tokenEnv = System.getenv("TOKEN"); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 2cade311..2b86896a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -1,50 +1,70 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; +import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -public class CommandAutoRemove +public class CommandAutoRemove extends CommandBase { - public static ArrayList onCommand(CommandSender sender, String[] args) + private static List removeUnusedPlugins(ArrayList removables) { - if (!sender.hasPermission("kpm.autoremove")) + ArrayList removed = new ArrayList<>(); + + for (String removable : removables) { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return null; + Plugin plugin = Bukkit.getPluginManager().getPlugin(removable); + if (plugin != null) + { + Installer.unInstall(null, removable, true); + removed.add(removable); + } + DependencyTree.purge(removable); } + return removed; + } + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { // TODO: Separate frontend and backend + if (checkPermission(sender, terminal, "kpm.autoremove")) + sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); + ArrayList rem = new ArrayList<>(); if (!TeamKunPluginManager.getPlugin().getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); - return null; + return; } AtomicInteger removed = new AtomicInteger(); sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); ArrayList removables = DependencyTree.unusedPlugins(); - if (removables.size() == 0) + if (removables.isEmpty()) { sender.sendMessage(ChatColor.RED + "E: 削除可能なプラグインはありません。"); sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); TeamKunPluginManager.getPlugin().getSession().unlock(); - return rem; } - while (removables.size() > 0) + while (!removables.isEmpty()) { // のremoveUnusedPluginsで削除したプラグインによりいらない物ができた場合のためのループ rem.addAll(removeUnusedPlugins(removables)); removables = DependencyTree.unusedPlugins(); @@ -57,24 +77,29 @@ public static ArrayList onCommand(CommandSender sender, String[] args) sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); TeamKunPluginManager.getPlugin().getSession().unlock(); - return rem; } - private static List removeUnusedPlugins(ArrayList removables) + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - ArrayList removed = new ArrayList<>(); + return null; + } - for (String removable : removables) - { - Plugin plugin = Bukkit.getPluginManager().getPlugin(removable); - if (plugin != null) - { - Installer.unInstall(null, removable, true); - removed.add(removable); - } - DependencyTree.purge(removable); - } + @Override + public @Nullable String getPermission() + { + return "kpm.autoremove"; + } - return removed; + @Override + public TextComponent getHelpOneLine() + { + return of("必要がなくなったプラグインを自動で削除します。"); + } + + @Override + public String[] getArguments() + { + return new String[0]; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index 2b9318f1..3bcdd23b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -1,31 +1,35 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; -import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; -import org.apache.commons.lang.StringUtils; +import net.kyori.adventure.text.TextComponent; +import org.apache.commons.lang.ArrayUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.List; -public class CommandClean +public class CommandClean extends CommandBase { - public static void onCommand(CommandSender sender, String[] args) + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (!sender.hasPermission("kpm.clean")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - if (DependencyTree.isErrors()) { - sender.sendMessage(Messages.getErrorMessage()); - sender.sendMessage(ChatColor.RED + "E: エラーが検出されたため、システムが保護されました。"); + terminal.error("重大なエラーが検出されました。/kpm fix で修正を行ってください。"); + terminal.info("エラーが検出されたため、システムが保護されました。"); return; } @@ -33,116 +37,95 @@ public static void onCommand(CommandSender sender, String[] args) if (!kpmInstance.getSession().lock()) { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); + terminal.error("TeamKunPluginManagerが多重起動しています。"); return; } - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); + terminal.info("依存関係ツリーを読み込み中..."); String[] removable = Installer.getRemovableDataDirs(); if (removable.length == 0) { - sender.sendMessage(ChatColor.RED + "E: 削除可能が項目が見つかりませんでした。"); + terminal.info("削除可能な項目が見つかりませんでした。"); kpmInstance.getSession().unlock(); return; } - switch (args.length) - { - case 2: - case 1: - sender.sendMessage(ChatColor.GREEN + "データを検索中..."); - if (!args[0].equals("all") && Arrays.stream(removable).noneMatch(s -> args[0].equalsIgnoreCase(s))) - { - sender.sendMessage(ChatColor.RED + "E: プラグインが見つかりませんでした。"); - kpmInstance.getSession().unlock(); - return; - } - - if (args.length == 2 && !args[1].equals("no-preserve") && !(sender instanceof Player)) - { - sender.sendMessage(ChatColor.RED + "本当に実行する場合、次のコマンドを実行してください: /kpm clean " + args[0] + " no-preserve"); - kpmInstance.getSession().unlock(); - return; - } - - if (args.length == 2 && args[1].equals("no-preserve")) - { - sender.sendMessage(ChatColor.GREEN + "削除を実行しています..."); - if (args[0].equals("all")) - Arrays.stream(removable) - .forEach(Installer::clean); - else - Installer.clean(args[0]); - sender.sendMessage(Messages.getStatusMessage(0, args[0].equals("all") ? removable.length: 1, 0)); - sender.sendMessage(ChatColor.GREEN + "S: 削除に成功しました。"); - kpmInstance.getSession().unlock(); - return; - } - - - sender.sendMessage(ChatColor.RED + "本当に続行しますか? " + - ChatColor.WHITE + "[" + - ChatColor.GREEN + "y" + - ChatColor.WHITE + "/" + - ChatColor.RED + "N" + - ChatColor.WHITE + "]"); - - kpmInstance.getFunctional().add( - ((Player) sender).getUniqueId(), - new Say2Functional.FunctionalEntry(StringUtils::startsWithIgnoreCase, s -> { - switch (s) - { - case "n": - sender.sendMessage(ChatColor.RED + "キャンセルしました。"); - break; - case "y": - sender.sendMessage(ChatColor.GREEN + "削除を実行しています..."); - sender.sendMessage(Messages.getStatusMessage(0, args[0].equals("all") ? removable.length: 1, 0)); - sender.sendMessage(Messages.getStatusMessage(0, removable.length, 0)); - sender.sendMessage(ChatColor.GREEN + "S: 削除に成功しました。"); - } - }, "y", "n") - ); - - break; - case 0: - sender.sendMessage(ChatColor.GREEN + "この操作で、以下の" + removable.length + "つのプラグインデータが削除されます: "); - sender.sendMessage(ChatColor.AQUA + String.join(", ", removable)); - if (!(sender instanceof Player)) - { - sender.sendMessage(ChatColor.RED + "本当に実行する場合、次のコマンドを実行してください: /kpm clean all no-preserve"); - kpmInstance.getSession().unlock(); - return; - } - sender.sendMessage(ChatColor.RED + "本当に続行しますか? " + - ChatColor.WHITE + "[" + - ChatColor.GREEN + "y" + - ChatColor.WHITE + "/" + - ChatColor.RED + "N" + - ChatColor.WHITE + "]"); - kpmInstance.getFunctional().add( - ((Player) sender).getUniqueId(), - new Say2Functional.FunctionalEntry(StringUtils::startsWithIgnoreCase, s -> { - switch (s) - { - case "n": - sender.sendMessage(ChatColor.RED + "キャンセルしました。"); - kpmInstance.getSession().unlock(); - break; - case "y": - sender.sendMessage(ChatColor.GREEN + "削除を実行しています..."); - Arrays.stream(removable) - .forEach(Installer::clean); - sender.sendMessage(Messages.getStatusMessage(0, removable.length, 0)); - sender.sendMessage(ChatColor.GREEN + "S: 削除に成功しました。"); - kpmInstance.getSession().unlock(); - } - }, "y", "n") - ); + String pluginName = null; + if (args.length > 0 && !args[0].equals("all")) + pluginName = args[0]; + + if (pluginName != null) + if (ArrayUtils.contains(removable, pluginName)) + removable = new String[]{pluginName}; + else + { + terminal.error("指定されたプラグインのデータフォルダが見つかりませんでした。"); + kpmInstance.getSession().unlock(); + return; + } + + // TODO: aptっぽく、スキャンで引っかかったプラグインのリストを表示する + terminal.writeLine(ChatColor.GREEN + "この操作で、以下の" + removable.length + "つのプラグインデータが削除されます: "); + terminal.writeLine(ChatColor.AQUA + String.join(", ", removable)); + + String[] finalRemovable = removable; + Runner.run(() -> { + QuestionResult result = terminal.getInput(). + showQuestion("本当に続行しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) + .waitAndGetResult(); + + if (result.test(QuestionAttribute.CANCELLABLE)) + terminal.error("キャンセルしました。"); + else if (result.test(QuestionAttribute.YES)) + removeDatas(terminal, finalRemovable); + + kpmInstance.getSession().unlock(); + }, (exception, bukkitTask) -> { + }); + + } + + private void removeDatas(Terminal terminal, String[] removables) + { + for (String removable : removables) + { + terminal.info(removable + " を削除しています..."); + Installer.clean(removable); } + + terminal.writeLine(Messages.getStatusMessage(0, removables.length, 0)); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + List list = new ArrayList<>(Collections.singleton("all")); + + if (args.length == 1) + list.addAll(Arrays.asList(Installer.getRemovableDataDirs())); + + return list; } + @Override + public @Nullable String getPermission() + { + return "kpm.clean"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("削除されて使用されなくなったプラグインのデータフォルダを再帰的に削除します。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + optional("name", "プラグイン名", "all"), + }; + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java index b8e7a799..8b974096 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java @@ -1,37 +1,63 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; +import net.kyori.adventure.text.TextComponent; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CommandFix +import java.util.List; + +public class CommandFix extends CommandBase { - public static void onCommand(CommandSender sender, String[] args) + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (!sender.hasPermission("kpm.fix")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - if (!TeamKunPluginManager.getPlugin().getSession().lock()) { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); + terminal.error("TeamKunPluginManagerが多重起動しています。"); return; } - sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); + terminal.info("依存関係ツリーを読み込み中..."); if (!DependencyTree.isErrors()) { - sender.sendMessage(ChatColor.RED + "E: エラーは検出されませんでした。"); + terminal.error("エラーは検出されませんでした。"); TeamKunPluginManager.getPlugin().getSession().unlock(); return; } - sender.sendMessage(ChatColor.GREEN + "エラーを解決しています..."); + terminal.info(ChatColor.GREEN + "問題を修復しています..."); DependencyTree.fix(); - sender.sendMessage(ChatColor.GREEN + "S: エラーの解決に成功しました。"); + terminal.success("問題の修復に成功しました。"); TeamKunPluginManager.getPlugin().getSession().unlock(); } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.fix"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("エラーを修復します。" + ChatColor.YELLOW + "エラーメッセージが表示された場合のみ実行してください。"); + } + + @Override + public String[] getArguments() + { + return new String[0]; + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index fb59e963..52972a2d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -1,8 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree.Info; +import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; @@ -11,89 +14,27 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -public class CommandInfo +public class CommandInfo extends CommandBase { - public static void onCommand(CommandSender sender, String[] args) - { - if (!sender.hasPermission("kpm.info")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - - - if (args.length < 1) - { - sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); - sender.sendMessage(ChatColor.RED + "使用法: /kpm info <プラグイン名>"); - return; - } - - if (!PluginUtil.isPluginLoaded(args[0])) - { - sender.sendMessage(ChatColor.RED + "E: プラグインが見つかりませんでした。"); - return; - } - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); - - Info info = DependencyTree.getInfo(args[0], false); - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "情報を読み込み中..."); - JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(args[0]); - - if (plugin == null) - { - sender.sendMessage(ChatColor.RED + "E: 情報の読み込みに失敗しました。"); - return; - } - - File file = PluginUtil.getFile(plugin); - - sender.sendMessage(pi("名前", info.name)); - sender.sendMessage(pi("作成者", String.join(", ", plugin.getDescription().getAuthors()))); - sender.sendMessage(pi("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); - sender.sendMessage(pi("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); - sender.sendMessage(pi("保護", TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name)))); - - if (plugin.getDescription().getWebsite() != null) - sender.sendMessage(pi("ウェブサイト", ChatColor.UNDERLINE + plugin.getDescription().getWebsite())); - if (plugin.getDescription().getPrefix() != null) - sender.sendMessage(pi("ログ接頭辞", plugin.getDescription().getPrefix())); - if (plugin.getDescription().getDescription() != null) - sender.sendMessage(pi("概要", plugin.getDescription().getDescription())); - - if (file != null) - { - sender.sendMessage(""); - sender.sendMessage(pi("ファイル名", file.getName())); - sender.sendMessage(pi("ダウンロードサイズ", PluginUtil.getFileSizeString(file.length()))); - } - - sender.sendMessage(""); - sender.sendMessage(dependTree("依存関係", plugin.getDescription().getDepend())); - sender.sendMessage(dependTree("被依存関係", info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.toList()))); - - sender.sendMessage(""); - sender.sendMessage(commandList(plugin.getDescription().getCommands())); - - } - private static Component dependTree(String name, List l) { TextComponent content = Component.text(ChatColor.GREEN + name + ": "); - if (l.size() == 0) + if (l.isEmpty()) return content.append(Component.text(ChatColor.DARK_GREEN + "なし")).asComponent(); - for(String depend: l) + for (String depend : l) { content = content.append(Component.text(" " + ChatColor.DARK_GREEN + depend) .hoverEvent(HoverEvent.showText(Component.text(ChatColor.AQUA + "クリックして詳細を表示"))) @@ -106,23 +47,25 @@ private static Component dependTree(String name, List l) @SuppressWarnings("unchecked") private static Component commandHover(String name, Map command) { - Component component = Component.text(pi("コマンド名", name + "\n\n")); + Component component = Component.text(Messages.keyValue("コマンド名", name + "\n\n")); if (command.containsKey("aliases")) { if (command.get("aliases") instanceof String) - component = component.append(Component.text(pi("エイリアス", "/" + command.get("aliases")))); + component = component.append(Component.text(Messages.keyValue("エイリアス", "/" + command.get("aliases")))); else if (command.get("aliases") instanceof List) - component = component.append(Component.text(pi("エイリアス", - "/" + String.join(", /", (List) command.get("aliases"))) + "\n")); + component = component.append(Component.text(Messages.keyValue( + "エイリアス", + "/" + String.join(", /", (List) command.get("aliases")) + ) + "\n")); } if (command.containsKey("usage")) - component = component.append(Component.text(pi("使用法", command.get("usage")) + "\n")); + component = component.append(Component.text(Messages.keyValue("使用法", command.get("usage")) + "\n")); if (command.containsKey("description")) - component = component.append(Component.text(pi("概要", command.get("description")) + "\n")); + component = component.append(Component.text(Messages.keyValue("概要", command.get("description")) + "\n")); if (command.containsKey("permission")) - component = component.append(Component.text(pi("権限", command.get("permission")) + "\n")); + component = component.append(Component.text(Messages.keyValue("権限", command.get("permission")) + "\n")); return component; } @@ -130,28 +73,97 @@ private static Component commandList(Map> command) { TextComponent component = Component.text(ChatColor.GREEN + "コマンド:"); - for (Map.Entry> c: command.entrySet()) + for (Map.Entry> c : command.entrySet()) { component = component.append( Component.text(ChatColor.DARK_GREEN + " /" + c.getKey()) - .hoverEvent(HoverEvent.showText(commandHover(c.getKey(), c.getValue())))); + .hoverEvent(HoverEvent.showText(commandHover(c.getKey(), c.getValue())))); } return component; } - private static String pi(String property, String value) + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 1, 1)) + return; + + if (!PluginUtil.isPluginLoaded(args[0])) + { + terminal.error("プラグインが見つかりませんでした。"); + return; + } + + terminal.info("依存関係ツリーを読み込み中..."); + + Info info = DependencyTree.getInfo(args[0], false); + + terminal.info("情報を読み込み中..."); + JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(args[0]); + + if (plugin == null) + { + terminal.error("情報の読み込みに失敗しました。"); + return; + } + + File file = PluginUtil.getFile(plugin); + + terminal.writeLine(Messages.keyValue("名前", info.name)); + terminal.writeLine(Messages.keyValue("作成者", String.join(", ", plugin.getDescription().getAuthors()))); + terminal.writeLine(Messages.keyValue("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); + terminal.writeLine(Messages.keyValue("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); + terminal.writeLine(Messages.keyValueYesNo("保護", TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name)))); + + if (plugin.getDescription().getWebsite() != null) + terminal.writeLine(Messages.keyValue("ウェブサイト", ChatColor.UNDERLINE + plugin.getDescription().getWebsite())); + if (plugin.getDescription().getPrefix() != null) + terminal.writeLine(Messages.keyValue("ログ接頭辞", plugin.getDescription().getPrefix())); + if (plugin.getDescription().getDescription() != null) + terminal.writeLine(Messages.keyValue("概要", plugin.getDescription().getDescription())); + + if (file != null) + { + terminal.writeLine(""); + terminal.writeLine(Messages.keyValue("ファイル名", file.getName())); + terminal.writeLine(Messages.keyValue("ダウンロードサイズ", PluginUtil.getFileSizeString(file.length()))); + } + + terminal.writeLine(""); + terminal.write(dependTree("依存関係", plugin.getDescription().getDepend())); + terminal.write(dependTree("被依存関係", info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.toList()))); + + terminal.writeLine(""); + terminal.write(commandList(plugin.getDescription().getCommands())); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (args.length == 1) + return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName).collect(Collectors.toList()); + return null; + } + + @Override + public @Nullable String getPermission() { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + ChatColor.DARK_GREEN + value; + return "kpm.info"; } - private static String pi(String property, boolean a) + @Override + public TextComponent getHelpOneLine() { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + (a ? ChatColor.DARK_GREEN + "はい": ChatColor.RED + "いいえ"); + return of("インストールされているプラグインの詳細を表示します。"); } - private static String pi(String property, Object obj) + @Override + public String[] getArguments() { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + obj.toString(); + return new String[]{ + required("pluginName", "string") + }; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index 75322538..d0f79d2a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -1,63 +1,77 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; +import net.kyori.adventure.text.TextComponent; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CommandInstall +import java.util.List; + +public class CommandInstall extends CommandBase { - public static void onCommand(CommandSender sender, String[] args) + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - - if (!sender.hasPermission("kpm.install")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); + if (indicateArgsLengthInvalid(terminal, args, 1, 2)) // TODO: Set max to 1 cuz arg of $-CF-$ will be removed. return; - } - - if (args.length < 1) - { - sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); - sender.sendMessage(ChatColor.RED + "使用法: /kpm i "); - return; - } TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); if (!kpmInstance.isTokenAvailable()) - { - sender.sendMessage(ChatColor.RED + "E: トークンがセットされていません!"); - sender.sendMessage(ChatColor.RED + "/kpm register でトークンを発行してください。"); + { // TODO: Set level to warn + terminal.error("トークンが設定されていません!"); + terminal.info("/kpm register でトークンを発行することができます!"); kpmInstance.getSession().unlock(); return; } - if (args.length == 1 && args[0].equals("$-CF$")) + if (args.length == 1 && args[0].equals("$-CF$")) // TODO: Remove this and refactor to new Question system. { - kpmInstance.getFunctional().remove(sender instanceof ConsoleCommandSender ? null: ((Player) sender).getUniqueId()); - sender.sendMessage(ChatColor.GREEN + "E: 実行中のインストールをキャンセルしました。"); + terminal.success(ChatColor.GREEN + "実行中のインストールをキャンセルしました。"); return; } if (!kpmInstance.getSession().lock()) { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); + terminal.error("TeamKunPluginManagerが多重起動しています。"); return; } + Runner.runAsync(() -> { + Installer.install(sender, args[0], false, false, false, false); + kpmInstance.getSession().unlock(); + }); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return null; + } - new BukkitRunnable() - { - @Override - public void run() - { - Installer.install(sender, args[0], false, false, false, false); - kpmInstance.getSession().unlock(); - } - }.runTaskAsynchronously(kpmInstance); + @Override + public @Nullable String getPermission() + { + return "kpm.install"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("クエリからプラグインを新規インストールします。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("query", "string") + }; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java deleted file mode 100644 index f7e24026..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandMain.java +++ /dev/null @@ -1,125 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; - -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.plugin.Plugin; -import org.bukkit.util.StringUtil; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -public class CommandMain implements CommandExecutor, TabCompleter -{ - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { - if (!sender.hasPermission("kpm.use")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return true; - } - - if (args.length < 1) - { - sender.sendMessage(ChatColor.RED + "E: 不明なコマンドです!"); - sender.sendMessage(Messages.getCommandNotFoundMessage()); - return true; - } - - ArrayList argsList = new ArrayList<>(Arrays.asList(args)); - - argsList.remove(0); - - switch (args[0].toLowerCase()) - { - case "install": - case "i": - CommandInstall.onCommand(sender, argsList.toArray(new String[0])); - break; - case "uninstall": - case "remove": - case "rm": - CommandUninstall.onCommand(sender, argsList.toArray(new String[0])); - break; - case "status": - CommandStatus.onCommand(sender, argsList.toArray(new String[0])); - break; - case "autoremove": - CommandAutoRemove.onCommand(sender, argsList.toArray(new String[0])); - break; - case "fix": - CommandFix.onCommand(sender, argsList.toArray(new String[0])); - break; - case "update": - CommandUpdate.onCommand(sender, argsList.toArray(new String[0])); - break; - case "clean": - CommandClean.onCommand(sender, argsList.toArray(new String[0])); - break; - case "info": - CommandInfo.onCommand(sender, argsList.toArray(new String[0])); - break; - case "register": - CommandRegister.onCommand(sender, argsList.toArray(new String[0])); - break; - case "reload": - CommandReload.onCommand(sender, argsList.toArray(new String[0])); - break; - default: - sender.sendMessage(ChatColor.RED + "E: 不明なコマンドです!"); - sender.sendMessage(Messages.getCommandNotFoundMessage()); - break; - } - - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) - { - ArrayList completes = new ArrayList<>(); - - if (!sender.hasPermission("kpm.use")) - return new ArrayList<>(); - - - switch (args.length) - { - case 1: - completes.addAll(Arrays.asList("install", "i", "uninstall", "remove", "rm", "status", "autoremove", "fix", "update", "clean", "info", "register")); - break; - case 2: - String cmd = args[0]; - switch (cmd) - { - case "uninstall": - case "rm": - case "remove": - case "info": - case "clean": - case "reload": - completes = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toCollection(ArrayList::new)); - break; - } - case 3: - if (args[0].equals("clean")) - { - completes = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toCollection(ArrayList::new)); - completes.add("all"); - } - } - - ArrayList asCopy = new ArrayList<>(); - StringUtil.copyPartialMatches(args[args.length - 1], completes, asCopy); - Collections.sort(asCopy); - return asCopy; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 4b760212..ccdc1f0f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -1,151 +1,176 @@ package net.kunmc.lab.teamkunpluginmanager.commands; -import com.destroystokyo.paper.Title; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kyori.adventure.text.TextComponent; import org.bukkit.ChatColor; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CommandRegister +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +public class CommandRegister extends CommandBase { private final static String CLIENT_ID = "94c5d446dbc765895979"; private static final TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - public static void onCommand(CommandSender sender, String[] args) + private static void parseErrorAndPost(Terminal terminal, String data, int code) { - if (!sender.hasPermission("kpm.register")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - - if (args.length < 1 && sender instanceof BlockCommandSender) + try { - sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); - sender.sendMessage(ChatColor.RED + "使用法: /kpm register "); - return; + JsonObject response = new Gson().fromJson(data, JsonObject.class); + if (response.has("error")) + terminal.error("エラーが発生しました。:Server response with " + parseError(response.get("error").getAsString())); + else + terminal.error("エラーが発生しました。:Server response with code " + code); } - - if (!kpmInstance.getSession().lock()) + catch (JsonSyntaxException e) { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); - return; + terminal.error("サーバから不正なデータを受信しました。:" + data.substring(0, Math.min(data.length(), 50))); } - - - if (args.length == 1) - { - kpmInstance.getVault().vault(args[0]); - sender.sendMessage(ChatColor.GREEN + "S: トークンを正常に保管しました!"); - kpmInstance.getSession().unlock(); - return; - } - - - sender.sendMessage(ChatColor.GREEN + "GitHubサーバを用いてトークンを生成しますか? y/N> "); - kpmInstance.getFunctional().add(sender instanceof Player ? ((Player) sender).getUniqueId(): null, new Say2Functional.FunctionalEntry( - String::startsWith, - s -> { - if (!s.equalsIgnoreCase("y")) - return; - performAction(sender); - } - )); } - private static void performAction(CommandSender sender) + private static void performAction(Terminal terminal) { - sender.sendMessage(ChatColor.LIGHT_PURPLE + "サーバと通信しています..."); + terminal.info(ChatColor.LIGHT_PURPLE + "サーバと通信しています..."); - Pair data = URLUtils.postAsString("https://github.com/login/device/code?client_id=" + CLIENT_ID + "&scope=repo%2Cpublic_repo", + Pair data = URLUtils.postAsString( + "https://github.com/login/device/code?client_id=" + CLIENT_ID + "&scope=repo%20public_repo", "", "application/json", "text/plain" ); if (data.getLeft() != 200) { - sender.sendMessage(ChatColor.RED + "E: エラーが発生しました。しばらくしてからもう一度お試しください。"); + parseErrorAndPost(terminal, data.getRight(), data.getLeft()); return; } JsonObject object = new Gson().fromJson(data.getRight(), JsonObject.class); - final String device_code = object.get("device_code").getAsString(); - final String user_code = object.get("user_code").getAsString(); - final String verif_uri = object.get("verification_uri").getAsString(); - final int expires_sec = object.get("expires_in").getAsInt(); - final int get_interval = object.get("interval").getAsInt(); - - sender.sendMessage(ChatColor.DARK_GREEN + "入力するコード:" + ChatColor.WHITE + user_code); - sender.sendMessage(ChatColor.DARK_GREEN + "こちらからコードを有効化してください:" + ChatColor.BLUE + ChatColor.UNDERLINE + verif_uri); - sender.sendMessage(ChatColor.DARK_GRAY + "I:コードは、" + (expires_sec / 60) + "分で失効します。"); - if (sender instanceof Player) - showTitle((Player) sender, user_code, expires_sec); + String deviceCode = object.get("device_code").getAsString(); + String userCode = object.get("user_code").getAsString(); + String verifyURI = object.get("verification_uri").getAsString(); + int expireSeconds = object.get("expires_in").getAsInt(); + int pollingInterval = object.get("interval").getAsInt(); + + terminal.writeLine(ChatColor.DARK_GREEN + "こちらからコードを有効化してください:" + ChatColor.BLUE + ChatColor.UNDERLINE + verifyURI); + terminal.writeLine(ChatColor.DARK_GREEN + "コード: " + ChatColor.WHITE + userCode); + terminal.writeLine(ChatColor.DARK_GRAY + "I:なお、このコードは " + (expireSeconds / 60) + " 分で失効します。"); + if (terminal.isPlayer()) + terminal.showNotification(userCode, "GitHubでこのコードを入力して有効化してください。", expireSeconds * 20); //ここからポーリング - final boolean[] success = {false}; - BukkitRunnable polling = new BukkitRunnable() - { - @Override - public void run() + AtomicBoolean successFlag = new AtomicBoolean(false); + + BukkitTask task = Runner.runTimerAsync( + polling(terminal, deviceCode, successFlag), (exception, bukkitTask) -> bukkitTask.cancel(), + 100L, (pollingInterval * 20L) + 20L + ); + + Runner.runTimer(() -> { + if (!successFlag.get()) + return; + task.cancel(); + + throw new RuntimeException(); + }, (e, t) -> t.cancel(), 10L * 20L); + + } + + private static Runner.GeneralExceptableRunner polling(Terminal terminal, String device_code, AtomicBoolean successFlag) + { + return () -> { + Pair pollingData = URLUtils.postAsString( + "https://github.com/login/oauth/access_token?client_id=" + CLIENT_ID + + "&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&device_code=" + device_code, + "", + "application/json", + "text/plain" + ); + if (pollingData.getLeft() != 200) { - Pair data = URLUtils.postAsString( - "https://github.com/login/oauth/access_token?client_id=" + CLIENT_ID + - "&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&device_code=" + device_code, - "", - "application/json", - "text/plain" - ); - if (data.getLeft() != 200) - { - sender.sendMessage(ChatColor.RED + "E: エラーが発生しました。: Server response with" + data.getLeft()); - this.cancel(); - return; - } - - JsonObject response = new Gson().fromJson(data.getRight(), JsonObject.class); - - if (response.has("error")) - { - if (response.get("error").getAsString().equals("authorization_pending")) - return; - String error = response.get("error").getAsString(); - sender.sendMessage(ChatColor.RED + "E: エラーが発生いたしました。:" + parseError(error)); - if (sender instanceof Player) - sender.resetTitle(); - this.cancel(); - return; - } - - kpmInstance.getVault().vault(response.get("access_token").getAsString()); - sender.sendMessage(ChatColor.GREEN + "S: トークンを正常に保管しました!"); - if (sender instanceof Player) - sender.resetTitle(); - kpmInstance.getSession().unlock(); - success[0] = true; - this.cancel(); + parseErrorAndPost(terminal, pollingData.getRight(), pollingData.getLeft()); + throw new RuntimeException(); // For cancel bukkit task } - }; - BukkitTask task = polling.runTaskTimer(kpmInstance, 100L, (get_interval * 20L) + 20L); - BukkitRunnable expire = new BukkitRunnable() - { - @Override - public void run() + JsonObject response = new Gson().fromJson(pollingData.getRight(), JsonObject.class); + + if (response.has("error")) { - if (!success[0]) + if (response.get("error").getAsString().equals("authorization_pending")) return; - task.cancel(); + + terminal.error( + "エラーが発生しました。:Server response with %s", + parseError(response.get("error").getAsString()) + ); + + if (terminal.isPlayer()) + terminal.clearNotification(); + + throw new RuntimeException(); // For cancel bukkit task } + + kpmInstance.getVault().vault(response.get("access_token").getAsString()); + terminal.success("S: トークンを正常に保管しました!"); + if (terminal.isPlayer()) + terminal.clearNotification(); + kpmInstance.getSession().unlock(); + successFlag.set(true); + + throw new RuntimeException(); // For cancel bukkit task }; - expire.runTaskLater(kpmInstance, get_interval * 20L); + } + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (args.length < 1 && sender instanceof BlockCommandSender) + { + terminal.error("コマンドブロックから実行するには第一引数が必須です。"); + return; + } + + if (!kpmInstance.getSession().lock()) + { + terminal.error("TeamKunPluginManagerが多重起動しています。"); + return; + } + + if (args.length == 1) + { + kpmInstance.getVault().vault(args[0]); + terminal.success("トークンを正常に保管しました!"); + kpmInstance.getSession().unlock(); + return; + } + + Runner.runAsync(() -> { + QuestionResult result = terminal.getInput(). + showQuestion("GitHubサーバを用いてトークンを生成しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) + .waitAndGetResult(); + + if (result.test(QuestionAttribute.CANCELLABLE)) + terminal.error("キャンセルしました。"); + else if (result.test(QuestionAttribute.YES)) + performAction(terminal); + + kpmInstance.getSession().unlock(); + }, (e, b) -> { + }); } private static String parseError(String err) @@ -166,15 +191,29 @@ private static String parseError(String err) return response; } - private static void showTitle(Player player, String code, int expires) + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - player.sendTitle(Title.builder() - .title(code) - .subtitle("上記のコードを入力してください。") - .fadeIn(10) - .fadeOut(10) - .stay(expires * 20) - .build() - ); + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.register"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("事前に取得したトークンを設定または、GitHubでログインしてトークンを設定します。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + optional("token", "string") + }; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java index cdd1459b..80869868 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java @@ -1,53 +1,78 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CommandReload +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class CommandReload extends CommandBase { - public static void onCommand(CommandSender sender, String[] args) + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (!sender.hasPermission("kpm.reload")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - - if (args.length < 1) - { - sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); - sender.sendMessage(ChatColor.RED + "使用法: /kpm reload "); + if (indicateArgsLengthInvalid(terminal, args, 1, 1)) return; - } Plugin plugin; if ((plugin = Bukkit.getPluginManager().getPlugin(args[0])) == null) { - sender.sendMessage(ChatColor.RED + "E: プラグイン " + args[0] + " は存在しません。"); + terminal.error("E: プラグイン %s は存在しません。", args[0]); return; } if (!TeamKunPluginManager.getPlugin().getSession().lock()) { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); + terminal.error("TeamKunPluginManagerが多重起動しています。"); return; } - new BukkitRunnable() - { - @Override - public void run() - { - PluginUtil.reload(plugin); - sender.sendMessage(ChatColor.GREEN + "S: " + args[0] + " を正常に再読み込みしました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - } - }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); + Runner.runAsync(() -> { + terminal.info("プラグイン %s を再読み込み中...", args[0]); + PluginUtil.reload(plugin); + terminal.success("プラグイン %s を正常に再読み込み中しました。", args[0]); + TeamKunPluginManager.getPlugin().getSession().unlock(); + }); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (args.length == 1) + return Arrays.stream(Bukkit.getPluginManager().getPlugins()) + .map(Plugin::getName) + .collect(Collectors.toList()); + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.reload"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("インストールされているプラグインを再読み込みします。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("pluginName", "string") + }; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java index a163a11d..f6a515f9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java @@ -1,63 +1,77 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; +import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; -public class CommandStatus +public class CommandStatus extends CommandBase { - public static void onCommand(CommandSender sender, String[] args) + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (!sender.hasPermission("kpm.status")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - - - sender.sendMessage(ChatColor.GREEN + "===現在の状態==="); + terminal.writeLine("===現在の状態==="); String statusError = Messages.getErrorMessage(); - sender.sendMessage(ChatColor.GREEN + "ステータス: " + (!statusError.equals("") ? ChatColor.RED + "エラー": ChatColor.DARK_GREEN + "正常")); - sender.sendMessage(pi("プラグイン数", Bukkit.getPluginManager().getPlugins().length)); + terminal.writeLine(ChatColor.GREEN + "ステータス: " + + (!statusError.isEmpty() ? ChatColor.RED + "エラー": ChatColor.DARK_GREEN + "正常")); + terminal.writeLine(Messages.keyValue("プラグイン数", Bukkit.getPluginManager().getPlugins().length)); File resolve = new File( TeamKunPluginManager.getPlugin().getDataFolder(), TeamKunPluginManager.getPlugin().getPluginConfig().getString("resolvePath") ); if (resolve.exists()) - sender.sendMessage(pi("最終アップデート", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(resolve.lastModified())))); - if (!statusError.equals("")) - sender.sendMessage(statusError); + terminal.writeLine(Messages.keyValue( + "最終アップデート", + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(resolve.lastModified())) + )); + + if (!statusError.isEmpty()) + terminal.writeLine(statusError); String autoRemovable = Messages.getUnInstallableMessage(); - if (!autoRemovable.equals("")) - sender.sendMessage(autoRemovable); + if (!autoRemovable.isEmpty()) + terminal.writeLine(autoRemovable); if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) - sender.sendMessage(ChatColor.RED + "トークンがセットされていません!/kpm register でトークンを発行してください。"); + terminal.writeLine(ChatColor.RED + "トークンがセットされていません!/kpm register でトークンを発行してください。"); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return null; } - private static String pi(String property, String value) + @Override + public @Nullable String getPermission() { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + ChatColor.DARK_GREEN + value; + return "kpm.status"; } - private static String pi(String property, boolean a) + @Override + public TextComponent getHelpOneLine() { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + (a ? ChatColor.DARK_GREEN + "はい": ChatColor.RED + "いいえ"); + return of("TeamKUNPluginManagerの状態を表示します。"); } - private static String pi(String property, Object obj) + @Override + public String[] getArguments() { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + ChatColor.GREEN + obj.toString(); + return new String[0]; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index a93f9f8b..97711999 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -1,43 +1,68 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CommandUninstall +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class CommandUninstall extends CommandBase { - public static void onCommand(CommandSender sender, String[] args) + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (!sender.hasPermission("kpm.uninstall")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); + if (indicateArgsLengthInvalid(terminal, args, 1, 1)) return; - } - - - if (args.length < 1) - { - sender.sendMessage(ChatColor.RED + "E: 引数が不足しています!"); - sender.sendMessage(ChatColor.RED + "使用法: /kpm rm "); - return; - } if (!TeamKunPluginManager.getPlugin().getSession().lock()) { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); + terminal.error("TeamKunPluginManagerが多重起動しています。"); return; } - new BukkitRunnable() - { - @Override - public void run() - { - Installer.unInstall(sender, args[0], false); - TeamKunPluginManager.getPlugin().getSession().unlock(); - } - }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); + Runner.runAsync(() -> { + Installer.unInstall(sender, args[0], false); + TeamKunPluginManager.getPlugin().getSession().unlock(); + }); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (args.length == 1) + return Arrays.stream(Bukkit.getPluginManager().getPlugins()) + .map(Plugin::getName) + .collect(Collectors.toList()); + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.uninstall"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("インストールされているプラグインを削除します。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("pluginName", "string") + }; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 11884e32..142f953b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -3,16 +3,20 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kyori.adventure.text.TextComponent; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; import java.io.File; @@ -28,67 +32,15 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -public class CommandUpdate +public class CommandUpdate extends CommandBase // TODO: Rewrite this { - public static void onCommand(CommandSender sender, String[] args) - { - if (sender != null && !sender.hasPermission("kpm.update")) - { - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - return; - } - - if (sender == null) - sender = Installer.dummySender(); - - if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) - { - sender.sendMessage(ChatColor.RED + "E: トークンがセットされていません!"); - sender.sendMessage(ChatColor.RED + "/kpm register でトークンを発行してください。"); - return; - } - - if (!TeamKunPluginManager.getPlugin().getSession().lock()) - { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); - return; - } - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "エイリアスセットファイルのダウンロードを開始します..."); - CommandSender finalSender = sender; - - new BukkitRunnable() - { - @Override - public void run() - { - HashMap paths = new HashMap<>(); - new File(TeamKunPluginManager.DATABASE_PATH).mkdirs(); - - DownloadResult downloadResult = doDownload(finalSender); - printDownloadMessage(finalSender, downloadResult); - finalSender.sendMessage(ChatColor.LIGHT_PURPLE + "リストを読み込んでいます..."); - - int aliases = doRegister(downloadResult); - - doCleanUp(downloadResult); - - if (downloadResult.errors) - finalSender.sendMessage(ChatColor.YELLOW + "W: いくつかのエイリアスセットファイルのダウンロードに失敗しました。" + - "これらは無視されるか、古いものが代わりに使われます。"); - finalSender.sendMessage(ChatColor.GREEN + "項目数: " + aliases); - finalSender.sendMessage(ChatColor.GREEN + "S: プラグイン定義ファイルのアップデートに成功しました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - } - }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); - } - - private static DownloadResult doDownload(CommandSender finalSender) + private static DownloadResult doDownload(Terminal terminal) { AtomicInteger num = new AtomicInteger(0); Map paths = new HashMap<>(); @@ -124,8 +76,8 @@ private static DownloadResult doDownload(CommandSender finalSender) connection.connect(); if (connection.getResponseCode() != 200) { - finalSender.sendMessage(ChatColor.RED + "無視:" + num.incrementAndGet() + " " + url); - finalSender.sendMessage(ChatColor.RED + " " + + terminal.writeLine(ChatColor.RED + "無視:" + num.incrementAndGet() + " " + url); + terminal.writeLine(ChatColor.RED + " " + connection.getResponseCode() + " " + connection.getResponseMessage() + " [IP: " + InetAddress.getByName(urlObj.getHost()).getHostAddress() + @@ -140,15 +92,15 @@ private static DownloadResult doDownload(CommandSender finalSender) if (paths.containsKey(name)) { - finalSender.sendMessage(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + name); - finalSender.sendMessage(ChatColor.RED + " エイリアスセット '" + name + "' が重複しています。"); + terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + name); + terminal.writeLine(ChatColor.RED + " エイリアスセット '" + name + "' が重複しています。"); error.set(true); return; } paths.put(name, fileName); if (!file.createNewFile()) { - finalSender.sendMessage(ChatColor.GREEN + "ヒット:" + num.incrementAndGet() + " " + url); + terminal.writeLine(ChatColor.GREEN + "ヒット:" + num.incrementAndGet() + " " + url); return; } try (InputStream is = connection.getInputStream(); @@ -158,25 +110,25 @@ private static DownloadResult doDownload(CommandSender finalSender) } - finalSender.sendMessage(ChatColor.GREEN + "取得:" + num.incrementAndGet() + + terminal.writeLine(ChatColor.GREEN + "取得:" + num.incrementAndGet() + " " + url + " [" + PluginUtil.getFileSizeString(file.length()) + "]"); } catch (MalformedURLException e) { - finalSender.sendMessage(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); - finalSender.sendMessage(ChatColor.RED + " '" + url + "' はURLではありません。"); + terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); + terminal.writeLine(ChatColor.RED + " '" + url + "' はURLではありません。"); error.set(true); } catch (UnknownHostException e) { - finalSender.sendMessage(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); - finalSender.sendMessage(ChatColor.RED + " '" + url + "' を解決できませんでした。"); + terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); + terminal.writeLine(ChatColor.RED + " '" + url + "' を解決できませんでした。"); error.set(true); } catch (Exception e) { - finalSender.sendMessage(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); - finalSender.sendMessage(ChatColor.RED + " エラー " + e.getClass().getName() + " が発生しました。"); + terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); + terminal.writeLine(ChatColor.RED + " エラー " + e.getClass().getName() + " が発生しました。"); error.set(true); e.printStackTrace(); } @@ -185,7 +137,7 @@ private static DownloadResult doDownload(CommandSender finalSender) return new DownloadResult(paths, error.get(), System.currentTimeMillis() - start); } - private static void printDownloadMessage(CommandSender sender, DownloadResult result) + private static void printDownloadMessage(Terminal terminal, DownloadResult result) { AtomicLong size = new AtomicLong(0); @@ -193,10 +145,11 @@ private static void printDownloadMessage(CommandSender sender, DownloadResult re size.addAndGet(new File(s).length()); }); - double seconds = new BigDecimal(result.sec).divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); + double seconds = new BigDecimal(result.sec).divide(new BigDecimal("1000")) + .setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); - sender.sendMessage( + terminal.writeLine( ChatColor.LIGHT_PURPLE + PluginUtil.getFileSizeString(size.get()) + " を " + @@ -258,6 +211,73 @@ private static int doRegister(DownloadResult result) return atomicInteger.get(); } + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (!TeamKunPluginManager.getPlugin().getSession().lock()) + { + sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); + return; + } + + if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) + { // TODO: Set level to warn + terminal.error("トークンが設定されていません!"); + terminal.info("/kpm register でトークンを発行することができます!"); + TeamKunPluginManager.getPlugin().getSession().unlock(); + return; + } + + terminal.info("プラグインデータセットファイルのダウンロードを開始します..."); + new BukkitRunnable() + { + @Override + public void run() + { + new File(TeamKunPluginManager.DATABASE_PATH).mkdirs(); + + DownloadResult downloadResult = doDownload(terminal); + printDownloadMessage(terminal, downloadResult); + sender.sendMessage(ChatColor.LIGHT_PURPLE + "リストを読み込んでいます..."); + + int aliases = doRegister(downloadResult); + + doCleanUp(downloadResult); + + if (downloadResult.errors) + terminal.warn("いくつかのエイリアスセットファイルのダウンロードに失敗しました。" + + "これらは無視されるか、古いものが代わりに使われます。"); + terminal.writeLine(ChatColor.GREEN + "項目数: " + aliases); + terminal.success("プラグイン定義ファイルのアップデートに成功しました。"); + TeamKunPluginManager.getPlugin().getSession().unlock(); + } + }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.update"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("既知プラグインデータセットをアップデートします。"); + } + + @Override + public String[] getArguments() + { + return new String[0]; + } + private static class DownloadResult { public DownloadResult(Map lists, boolean errors, long sec) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java index db4e9db3..15f1deb3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java @@ -7,22 +7,6 @@ public class Messages { - public static String getCommandNotFoundMessage() - { - - return ChatColor.RED + "使用可能なコマンド: \n" + - " " + commandMessageBuilder("install", "リポジトリまたはURLからインストールします。", "i") + "\n" + - " " + commandMessageBuilder("remove", "プラグインをアンインストールします。", "rm", "uninstall") + "\n" + - " " + commandMessageBuilder("autoremove", "いらないプラグインを自動で削除します。") + "\n" + - " " + commandMessageBuilder("update", "既知プラグインデータセットをアップデートします。") + "\n" + - " " + commandMessageBuilder("status", "現在の状態を表示します。") + "\n" + - " " + commandMessageBuilder("info", "プラグインの情報を取得します。") + "\n" + - " " + commandMessageBuilder("fix", "エラーを修復します。\n" + ChatColor.YELLOW + - " メッセージがあった場合のみ実行してください。") + "\n" + - " " + commandMessageBuilder("clean", "不要になったプラグインデータを削除します。") + "\n" + - " " + commandMessageBuilder("register", "トークンを発行します。") + "\n"; - } - public static String getErrorMessage() { if (!DependencyTree.isErrors()) @@ -32,10 +16,9 @@ public static String getErrorMessage() public static String getUnInstallableMessage() { - List rmble = DependencyTree.unusedPlugins(); - if (rmble.size() == 0) + if (rmble.isEmpty()) return ""; return ChatColor.BLUE + "以下のプラグインがインストールされていますが、もう必要とされていません:\n" + @@ -43,13 +26,6 @@ public static String getUnInstallableMessage() ChatColor.BLUE + "これを削除するには、'/kpm autoremove' を利用してください。"; } - private static String commandMessageBuilder(String label, String help, String... aliases) - { - return ChatColor.GREEN + label + - (aliases.length != 0 ? ", " + String.join(", ", aliases): "") + - ChatColor.YELLOW + " - " + help; - } - public static String getModifyMessage(ModifyType type, String name) { switch (type) @@ -70,6 +46,21 @@ public static String getStatusMessage(int installed, int removed, int modified) return ChatColor.GREEN.toString() + installed + " 追加 " + ChatColor.RED + removed + " 削除 " + ChatColor.YELLOW + modified + " 変更"; } + public static String keyValue(String property, String value) + { + return ChatColor.GREEN + property + ChatColor.WHITE + ": " + ChatColor.DARK_GREEN + value; + } + + public static String keyValueYesNo(String property, boolean a) + { + return ChatColor.GREEN + property + ChatColor.WHITE + ": " + (a ? ChatColor.DARK_GREEN + "はい": ChatColor.RED + "いいえ"); + } + + public static String keyValue(String property, Object obj) + { + return ChatColor.GREEN + property + ChatColor.WHITE + ": " + obj.toString(); + } + public enum ModifyType { ADD, diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fa34c8c0..1e051569 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -15,7 +15,7 @@ commands: permissions: - kpm.use: + kpm: description: "このプラグインを使用できます。" default: op children: @@ -46,3 +46,5 @@ permissions: description: "プラグインの状態を閲覧します。" kpm.update: description: "エイリアス定義データベースを更新します。" + kpm.help: + description: "プラグインのヘルプを表示します。" From 31322e3ae084a50bd4b7cf67a3ce40089bf69354 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:01:13 +0900 Subject: [PATCH 063/745] refactor: deprecated bigdecimal option --- .../lab/teamkunpluginmanager/commands/CommandUpdate.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 142f953b..7a9e5443 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -26,6 +26,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.MalformedURLException; @@ -145,8 +146,8 @@ private static void printDownloadMessage(Terminal terminal, DownloadResult resul size.addAndGet(new File(s).length()); }); - double seconds = new BigDecimal(result.sec).divide(new BigDecimal("1000")) - .setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); + double seconds = new BigDecimal(result.sec) + .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN).doubleValue(); terminal.writeLine( From a6a75811b4a4fdd4d6422a7f82e534766966fe04 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:01:39 +0900 Subject: [PATCH 064/745] pref: file unit converter --- .../utils/PluginUtil.java | 79 ++++--------------- 1 file changed, 14 insertions(+), 65 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index 2884f38f..f1c8f5f7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -32,6 +32,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URLClassLoader; import java.text.DecimalFormat; import java.util.ArrayList; @@ -127,67 +128,28 @@ public static boolean isPluginLoaded(Plugin plugin) return ((PluginClassLoader) plugin.getClass().getClassLoader()).getPlugin() != null; } + private static final String[] fileUnits = { + "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" + }; + public static String getFileSizeString(long bytes) { String suffix = "B"; BigDecimal dec = new BigDecimal(String.valueOf(bytes)); - BigDecimal div = new BigDecimal(1024); - if (dec.compareTo(div) >= 0) - { - dec = dec.divide(div); - suffix = "KiB"; - } - - if (dec.compareTo(div) >= 0) - { - dec = dec.divide(div); - suffix = "MiB"; - } + BigDecimal base = new BigDecimal(1024); - if (dec.compareTo(div) >= 0) + for (String fileUnit : fileUnits) { - dec = dec.divide(div); - suffix = "GiB"; - } - - if (dec.compareTo(div) >= 0) - { - dec = dec.divide(div); - suffix = "TiB"; - } - - - if (dec.compareTo(div) >= 0) - { - dec = dec.divide(div); - suffix = "PiB"; - } - - - if (dec.compareTo(div) >= 0) - { - dec = dec.divide(div); - suffix = "EiB"; - } - - - if (dec.compareTo(div) >= 0) - { - dec = dec.divide(div); - suffix = "ZiB"; - } - - - if (dec.compareTo(div) >= 0) - { - dec = dec.divide(div); - suffix = "YiB"; + if (dec.compareTo(base) < 0) + { + suffix = fileUnit; + dec = dec.divide(base, 3, RoundingMode.HALF_UP); + } + else + break; } - dec = dec.setScale(3, BigDecimal.ROUND_HALF_UP); - - return new DecimalFormat("#,###.##;#,###.##").format(dec) + suffix; } @@ -290,19 +252,6 @@ private static boolean containValue(String contain, ArrayList key return ab.get(); } - private static ArrayList> removeByValue(ArrayList> original, String value) - { - ArrayList> copyOf = (ArrayList>) original.clone(); - - original.stream().parallel() - .forEach(stringStringPair -> { - if (stringStringPair.getRight().equals(value)) - copyOf.remove(stringStringPair); - }); - - return copyOf; - } - public static PluginDescriptionFile loadDescription(File file) throws InvalidDescriptionException, IOException { if (!file.exists()) From 09ae5a9f1bab9b4fcb08bfb66e51e706eeea9631 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:11:43 +0900 Subject: [PATCH 065/745] refactor: Replace all Runnable to Runner --- .../commands/CommandUpdate.java | 36 ++++---- .../plugin/Installer.java | 90 ++++++++----------- .../plugin/PluginEventListener.java | 21 ++--- .../utils/PluginUtil.java | 49 ++++------ 4 files changed, 79 insertions(+), 117 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 7a9e5443..24a7649c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -5,6 +5,7 @@ import com.google.gson.JsonObject; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; @@ -14,7 +15,6 @@ import org.apache.commons.io.IOUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -230,29 +230,25 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, } terminal.info("プラグインデータセットファイルのダウンロードを開始します..."); - new BukkitRunnable() - { - @Override - public void run() - { - new File(TeamKunPluginManager.DATABASE_PATH).mkdirs(); - DownloadResult downloadResult = doDownload(terminal); - printDownloadMessage(terminal, downloadResult); - sender.sendMessage(ChatColor.LIGHT_PURPLE + "リストを読み込んでいます..."); + Runner.runAsync(() -> { + new File(TeamKunPluginManager.DATABASE_PATH).mkdirs(); - int aliases = doRegister(downloadResult); + DownloadResult downloadResult = doDownload(terminal); + printDownloadMessage(terminal, downloadResult); + sender.sendMessage(ChatColor.LIGHT_PURPLE + "リストを読み込んでいます..."); - doCleanUp(downloadResult); + int aliases = doRegister(downloadResult); - if (downloadResult.errors) - terminal.warn("いくつかのエイリアスセットファイルのダウンロードに失敗しました。" + - "これらは無視されるか、古いものが代わりに使われます。"); - terminal.writeLine(ChatColor.GREEN + "項目数: " + aliases); - terminal.success("プラグイン定義ファイルのアップデートに成功しました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - } - }.runTaskAsynchronously(TeamKunPluginManager.getPlugin()); + doCleanUp(downloadResult); + + if (downloadResult.errors) + terminal.warn("いくつかのエイリアスセットファイルのダウンロードに失敗しました。" + + "これらは無視されるか、古いものが代わりに使われます。"); + terminal.writeLine(ChatColor.GREEN + "項目数: " + aliases); + terminal.success("プラグイン定義ファイルのアップデートに成功しました。"); + TeamKunPluginManager.getPlugin().getSession().unlock(); + }); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index dd2135f5..07ef7acb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -3,6 +3,7 @@ import com.g00fy2.versioncompare.Version; import com.google.gson.Gson; import com.google.gson.JsonObject; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; @@ -31,7 +32,6 @@ import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -116,35 +116,31 @@ public static void unInstall(CommandSender sender, String name, boolean force) CommandSender finalSender = sender; //非同期実行 - new BukkitRunnable() - { - @Override - public void run() - { - //プラグインのファイルを取得 - File file = PluginUtil.getFile(plugin); - //ファイルが有った場合は削除 - if (file != null) - file.delete(); - - //依存関係ツリーをワイプする - DependencyTree.wipePlugin(plugin); - finalSender.sendMessage(ChatColor.RED + "- " + plugin.getName() + ":" + plugin.getDescription().getVersion()); - - // エラーが有っる場合は表示 - String statusError = Messages.getErrorMessage(); - if (!statusError.equals("")) - finalSender.sendMessage(statusError); - - // 削除できるプラグイン(使われない依存関係等)があれば通知 - String autoRemovable = Messages.getUnInstallableMessage(); - - if (!autoRemovable.equals("")) - finalSender.sendMessage(autoRemovable); - finalSender.sendMessage(Messages.getStatusMessage(0, 1, 0)); - finalSender.sendMessage(ChatColor.GREEN + "S: " + plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); - } - }.runTaskLaterAsynchronously(TeamKunPluginManager.getPlugin(), 20L); + Runner.runLaterAsync(() -> { + //プラグインのファイルを取得 + File file = PluginUtil.getFile(plugin); + //ファイルが有った場合は削除 + if (file != null) + file.delete(); + + //依存関係ツリーをワイプする + DependencyTree.wipePlugin(plugin); + finalSender.sendMessage(ChatColor.RED + "- " + plugin.getName() + ":" + plugin.getDescription().getVersion()); + + // エラーが有っる場合は表示 + String statusError = Messages.getErrorMessage(); + if (!statusError.equals("")) // TODO: Replace all empty equals like this to String#isEmpty(). + finalSender.sendMessage(statusError); + + // 削除できるプラグイン(使われない依存関係等)があれば通知 + String autoRemovable = Messages.getUnInstallableMessage(); + + if (!autoRemovable.equals("")) + finalSender.sendMessage(autoRemovable); + finalSender.sendMessage(Messages.getStatusMessage(0, 1, 0)); + finalSender.sendMessage(ChatColor.GREEN + "S: " + plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); + + }, 20L); } /** @@ -371,19 +367,11 @@ else if (resolveResult instanceof SuccessResult) //バージョンの低いプラグインをアンインストール。 PluginUtil.unload(plugin); - new BukkitRunnable() - { - @Override - public void run() - { - //削除する場合は削除 - if (!withoutRemove) - delete(finalSender, PluginUtil.getFile(plugin)); - - - } - }.runTaskLater(TeamKunPluginManager.getPlugin(), 10L); - + Runner.runLater(() -> { + //削除する場合は削除 + if (!withoutRemove) + delete(finalSender, PluginUtil.getFile(plugin)); + }, 10L); } else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが変わらない(もしくは低い)。 { @@ -575,17 +563,11 @@ else if (resolveResult instanceof SuccessResult) //プラグインをアンロード PluginUtil.unload(plugin); - new BukkitRunnable() - { - - @Override - public void run() - { - File file = PluginUtil.getFile(plugin); - if (!withoutRemove && file != null) - file.delete(); - } - }.runTaskLaterAsynchronously(TeamKunPluginManager.getPlugin(), 20L); + Runner.runLaterAsync(() -> { + File file = PluginUtil.getFile(plugin); + if (!withoutRemove && file != null) + file.delete(); + }, 20L); } //依存関係をロード diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java index 8dbba784..3e095dbb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java @@ -1,13 +1,13 @@ package net.kunmc.lab.teamkunpluginmanager.plugin; import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; -import org.bukkit.scheduler.BukkitRunnable; import java.io.File; @@ -31,20 +31,15 @@ public void onDisable(PluginDisableEvent e) { if (!kpmInstance.isEnableBuildTree()) return; - new BukkitRunnable() - { - @Override - public void run() + Runner.runLater(() -> { + File f = PluginUtil.getFile(e.getPlugin()); + if (f == null || !f.exists()) { - File f = PluginUtil.getFile(e.getPlugin()); - if (f == null || !f.exists()) - { - kpmInstance.getLogger().info("依存関係ツリーを構築中(RMV:" + e.getPlugin().getName() + ")..."); - DependencyTree.wipePlugin(e.getPlugin()); - kpmInstance.getLogger().info("依存関係ツリーの構築完了"); - } + kpmInstance.getLogger().info("依存関係ツリーを構築中(RMV:" + e.getPlugin().getName() + ")..."); + DependencyTree.wipePlugin(e.getPlugin()); + kpmInstance.getLogger().info("依存関係ツリーの構築完了"); } - }.runTaskLater(kpmInstance, 2L); + }, 2L); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index f1c8f5f7..09505669 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.utils; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.InstallResult; import org.bukkit.Bukkit; @@ -22,7 +23,6 @@ import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.PluginClassLoader; -import org.bukkit.scheduler.BukkitRunnable; import java.io.File; import java.io.FileNotFoundException; @@ -472,39 +472,28 @@ public static void load(String name) File finalPluginFile = pluginFile; - new BukkitRunnable() - { - @Override - public void run() + Runner.run(() -> { + try { - try - { - Plugin target = Bukkit.getPluginManager().loadPlugin(finalPluginFile); - Objects.requireNonNull(target).onLoad(); - Bukkit.getPluginManager().enablePlugin(target); - new BukkitRunnable() - { - @Override - public void run() - { - getKnownCommands().entrySet().stream().parallel() - .filter(stringCommandEntry -> stringCommandEntry.getValue() instanceof PluginIdentifiableCommand) - .forEach(stringCommandEntry -> { - wrapCommand(stringCommandEntry.getValue(), stringCommandEntry.getKey()); - }); + Plugin target = Bukkit.getPluginManager().loadPlugin(finalPluginFile); + Objects.requireNonNull(target).onLoad(); + Bukkit.getPluginManager().enablePlugin(target); + Runner.runLater(() -> { // TODO: Remove this runLater cuz PluginManager#enablePlugin() seems return on Plugin's enable method has returned. + getKnownCommands().entrySet().stream().parallel() + .filter(stringCommandEntry -> stringCommandEntry.getValue() instanceof PluginIdentifiableCommand) + .forEach(stringCommandEntry -> { + wrapCommand(stringCommandEntry.getValue(), stringCommandEntry.getKey()); + }); - Bukkit.getOnlinePlayers().stream().parallel().forEach(Player::updateCommands); - } - }.runTaskLater(TeamKunPluginManager.getPlugin(), 10L); - } - catch (InvalidDescriptionException | InvalidPluginException e2) - { - e2.printStackTrace(); - } + Bukkit.getOnlinePlayers().stream().parallel().forEach(Player::updateCommands); + }, 10L); } - }.runTask(TeamKunPluginManager.getPlugin()); - + catch (InvalidDescriptionException | InvalidPluginException e2) + { + e2.printStackTrace(); + } + }); } public static void reload(Plugin plugin) From d75f03068865dd6ace4778e724da1fb3ef8648c9 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:44:02 +0900 Subject: [PATCH 066/745] refactor: Replace with lambda --- .../lab/teamkunpluginmanager/commands/CommandUpdate.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 24a7649c..44a131eb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -142,9 +142,7 @@ private static void printDownloadMessage(Terminal terminal, DownloadResult resul { AtomicLong size = new AtomicLong(0); - result.lists.values().stream().parallel().forEach(s -> { - size.addAndGet(new File(s).length()); - }); + result.lists.values().stream().parallel().forEach(s -> size.addAndGet(new File(s).length())); double seconds = new BigDecimal(result.sec) .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN).doubleValue(); From ac0c7f6e23d71cb3dd0e1164ef31ecce7b0a9eba Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:50:50 +0900 Subject: [PATCH 067/745] refactor: use isEmpty() --- .../TeamKunPluginManager.java | 2 +- .../plugin/DependencyTree.java | 2 +- .../plugin/Installer.java | 24 +++++++++---------- .../utils/GitHubURLBuilder.java | 12 +++++----- .../teamkunpluginmanager/utils/URLUtils.java | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index a80685f4..eeefdd10 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -149,7 +149,7 @@ public void onEnable() return; } - if (vault.getToken().equals("")) + if (vault.getToken().isEmpty()) vault.vault(""); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java index 821c8562..4c2eb548 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java @@ -278,7 +278,7 @@ private static boolean checkError() e.printStackTrace(); } - return plugin.size() != 0; + return !plugin.isEmpty(); } public static void fix() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 07ef7acb..baf2fd64 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -100,7 +100,7 @@ public static void unInstall(CommandSender sender, String name, boolean force) //他のプラグインの依存関係になっている場合はreturn // 強制アンインストールである場合は無視 - if (info.rdepends.size() != 0 && !force) + if (!info.rdepends.isEmpty() && !force) { sender.sendMessage(ChatColor.YELLOW + "W: このプラグインは以下のプラグインの依存関係です。"); sender.sendMessage(ChatColor.BLUE + info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.joining(" "))); @@ -129,13 +129,13 @@ public static void unInstall(CommandSender sender, String name, boolean force) // エラーが有っる場合は表示 String statusError = Messages.getErrorMessage(); - if (!statusError.equals("")) // TODO: Replace all empty equals like this to String#isEmpty(). + if (!statusError.isEmpty()) finalSender.sendMessage(statusError); // 削除できるプラグイン(使われない依存関係等)があれば通知 String autoRemovable = Messages.getUnInstallableMessage(); - if (!autoRemovable.equals("")) + if (!autoRemovable.isEmpty()) finalSender.sendMessage(autoRemovable); finalSender.sendMessage(Messages.getStatusMessage(0, 1, 0)); finalSender.sendMessage(ChatColor.GREEN + "S: " + plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); @@ -504,7 +504,7 @@ else if (resolveResult instanceof SuccessResult) //依存関係のインストール InstallResult dependResolve = Installer.install(null, dependUrl, true, false, true, false); //ファイルの名前がない場合は失敗としてマーク - if (dependResolve.getFileName().equals("")) + if (dependResolve.getFileName().isEmpty()) { failedResolve.add(dependency); continue; @@ -527,11 +527,11 @@ else if (resolveResult instanceof SuccessResult) finalSender.sendMessage(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_DOWN) + "秒で取得しました。"); //結果を表示しないモードで依存関係エラーが発生した場合はreturn - if (sender.equals(dummySender()) && failedResolve.size() > 0) + if (sender.equals(dummySender()) && !failedResolve.isEmpty()) return new InstallResult(add, remove, modify, true); //依存関係エラーが発生した場合は表示 - if (failedResolve.size() > 0) + if (!failedResolve.isEmpty()) { finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); finalSender.sendMessage(ChatColor.YELLOW + "W: " + description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); @@ -599,12 +599,12 @@ public void run() {*/ //エラーが発生した場合 String statusError = Messages.getErrorMessage(); - if (!statusError.equals("")) + if (!statusError.isEmpty()) finalSender.sendMessage(statusError); // 削除できるプラグイン(使われない依存関係等)があれば通知 String autoRemovable = Messages.getUnInstallableMessage(); - if (!autoRemovable.equals("")) + if (!autoRemovable.isEmpty()) finalSender.sendMessage(autoRemovable); finalSender.sendMessage(Messages.getStatusMessage(finalAdd1, remove, finalModify1)); @@ -723,7 +723,7 @@ private static void depend_askToCommandSender(CommandSender sender, List> jar) { - if (jar.size() == 0) + if (jar.isEmpty()) return null; String result = ""; @@ -741,9 +741,9 @@ private static String pickPluginJar(List> jar) tmp = pair.getRight(); } - if (result.equals("") && !tmp.equals("")) + if (result.isEmpty() && !tmp.isEmpty()) result = tmp; - if (result.equals("")) + if (result.isEmpty()) result = jar.get(0).getRight(); return result; @@ -765,7 +765,7 @@ private static List> parseMultiResult(String mlt) if (!escape && c == '|') { - if (!name.toString().equals("") && !url.toString().equals("")) + if (!name.toString().isEmpty() && !url.toString().isEmpty()) { result.add(new Pair<>(name.toString(), url.toString())); name = new StringBuilder(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java index 55296edd..cb904314 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java @@ -90,15 +90,15 @@ public static String urlValidate(String urlName, String version) String file = matcher.group("fileName"); //ファイルがない、もしくは""だった場合はオウム返し。 - if (file != null && !file.equals("")) + if (file != null && !file.isEmpty()) return urlName; //この辺は代入なので無視。 - if (!repository.equals("")) + if (!repository.isEmpty()) repoName = repository; - if (tag != null && !tag.equals("")) + if (tag != null && !tag.isEmpty()) tagName = tag; - else if (tagNF != null && !tagNF.equals("")) + else if (tagNF != null && !tagNF.isEmpty()) tagName = tagNF; } @@ -129,7 +129,7 @@ else if (tagNF != null && !tagNF.equals("")) //APIレスポンスがエラーかどうか。 String error = error(json.getRight()); - if (!error.equals("")) + if (!error.isEmpty()) return "ERROR " + error; JsonArray array = new Gson().fromJson(json.getRight(), JsonArray.class); @@ -177,7 +177,7 @@ else if (tagNF != null && !tagNF.equals("")) //APIレスポンスがエラーかどうか。 String error = error(json.getRight()); - if (!error.equals("")) + if (!error.isEmpty()) return "ERROR " + error; //アセットを上からなめる diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java index 25a85fec..63f93b6d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java @@ -132,7 +132,7 @@ public static Pair downloadFile(String url, String fileName) { boolean duplicateFile = false; - if (fileName.equals("")) + if (fileName.isEmpty()) fileName = "tmp1.jar"; int tryna = 0; From acabbfa97f7528a1ead45f9d21302a490edb208d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:51:58 +0900 Subject: [PATCH 068/745] refactor: deprecated bigdecimal option --- .../net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index baf2fd64..2f0621c6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -40,6 +40,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -279,7 +280,9 @@ else if (resolveResult instanceof SuccessResult) finalSender.sendMessage(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadResult.getRight())); add++; - finalSender.sendMessage(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_DOWN) + "秒で取得しました。"); + finalSender.sendMessage(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())) + .subtract(new BigDecimal(String.valueOf(startTime))) + .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN) + "秒で取得しました。"); } else //ダウンロードしない downloadResult = new Pair<>(true, url); From e34469b8926bd59261c5f4c05438a99c9d373432 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 12 Apr 2022 21:42:36 +0900 Subject: [PATCH 069/745] refactor: Apply peyautils to installer --- .../plugin/Installer.java | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 2f0621c6..d18ad9b7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -3,6 +3,9 @@ import com.g00fy2.versioncompare.Version; import com.google.gson.Gson; import com.google.gson.JsonObject; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; @@ -388,45 +391,36 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが finalSender.sendMessage(getDiffMessage(PluginUtil.getFile(plugin), false)); finalSender.sendMessage(getDiffMessage(new File("plugins/" + downloadResult.getRight()), true)); finalSender.sendMessage("\n"); - sender.sendMessage(ChatColor.RED + "プラグインを置換しますか?? " + - ChatColor.WHITE + "[" + - ChatColor.GREEN + "y" + - ChatColor.WHITE + "/" + - ChatColor.RED + "N" + - ChatColor.WHITE + "]"); - //ファイナルにコピーする。 - int finalAdd = add; - int finalModify = modify; - String fileName = downloadResult.getRight(); - TeamKunPluginManager.getPlugin().getFunctional().add( - sender instanceof Player ? ((Player) sender).getUniqueId(): null, - new Say2Functional.FunctionalEntry( - StringUtils::startsWithIgnoreCase, - s -> { - //n(No)だった場合は削除しreturn - if (StringUtils.startsWithIgnoreCase(s, "n")) - { - if (!withoutRemove && new File("plugins/" + fileName).exists()) - delete(finalSender, new File("plugins/" + fileName)); - - finalSender.sendMessage(Messages.getStatusMessage(finalAdd, remove, finalModify)); - finalSender.sendMessage(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); - return; - } - - //y(yes)だった場合 - unInstall(null, description.getName(), true); - InstallResult ir = install(finalSender, fileName, false, false, false, true); - finalSender.sendMessage(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); - }, - "y", "n" - ) - ); + try + { + QuestionResult questionResult = Terminals.of(sender).getInput() + .showQuestion("プラグインを置換しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) + .waitAndGetResult(); + + if (questionResult.test(QuestionAttribute.CANCELLABLE)) + { + if (!withoutRemove && new File("plugins/" + fileName).exists()) + delete(finalSender, new File("plugins/" + fileName)); + + finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + finalSender.sendMessage(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); + } + else + { + unInstall(null, description.getName(), true); + InstallResult ir = install(finalSender, fileName, false, false, false, true); + finalSender.sendMessage(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); + } + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } } //削除 From 8d48de86108ebbdf2887302a56ffddb42360ec57 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 16 Apr 2022 15:43:14 +0900 Subject: [PATCH 070/745] feat: New requester --- .../utils/http/HTTPResponse.java | 107 ++++++++ .../utils/http/RequestContext.java | 42 ++++ .../utils/http/Requests.java | 233 ++++++++++++++++++ 3 files changed, 382 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java new file mode 100644 index 00000000..64188385 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -0,0 +1,107 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.http; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import lombok.Value; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; + +@Value +public class HTTPResponse implements AutoCloseable +{ + RequestStatus status; + RequestContext request; + + int statusCode; + + HashMap headers; + + @Nullable + InputStream inputStream; + + public String getAsString() + { + if (inputStream == null) + return null; + StringBuilder sb = new StringBuilder(); + + byte[] buffer = new byte[1024]; + int len; + try + { + while ((len = inputStream.read(buffer)) != -1) + sb.append(new String(buffer, 0, len)); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return sb.toString(); + } + + public JsonElement getAsJson() + { + if (inputStream == null) + return null; + + String json = getAsString(); + return new Gson().fromJson(json, JsonElement.class); + } + + @Override + public void close() throws IOException + { + if (inputStream != null) + this.inputStream.close(); + } + + @Nullable + public String getHeader(@NotNull String header) + { + return headers.getOrDefault(header.toLowerCase(), headers.get(header)); + } + + public boolean isSuccessful() + { + return statusCode >= 200 && statusCode < 300; + } + + public boolean isRedirect() + { + return statusCode >= 300 && statusCode < 400; + } + + public boolean isClientError() + { + return statusCode >= 400 && statusCode < 500; + } + + public boolean isServerError() + { + return statusCode >= 500 && statusCode < 600; + } + + public boolean isError() + { + return isClientError() || isServerError(); + } + + public boolean isOK() + { + return statusCode == 200; + } + + public enum RequestStatus + { + OK, + REDIRECT_LOCATION_MALFORMED, + REDIRECT_LIMIT_EXCEED, + UNABLE_TO_RESOLVE_HOST, + IO_EXCEPTION_OCCURRED + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java new file mode 100644 index 00000000..f4fdcd9f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java @@ -0,0 +1,42 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.http; + +import lombok.Builder; +import lombok.Singular; +import lombok.Value; + +import java.net.URL; +import java.util.Map; + +@Value +@Builder +public class RequestContext +{ + URL url; + + @Builder.Default + RequestMethod method = RequestMethod.GET; + + @Singular("header") + Map extraHeaders; + + @Builder.Default + boolean cacheable = false; + @Builder.Default + boolean followRedirects = true; + @Builder.Default + int timeout = -1; + + @Builder.Default + byte[] body = {}; + + public enum RequestMethod + { + GET, + POST, + PUT, + DELETE, + HEAD, + OPTIONS, + TRACE + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java new file mode 100644 index 00000000..5dfc83a6 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -0,0 +1,233 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.http; + +import lombok.Getter; +import lombok.Setter; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import org.apache.commons.lang.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; + +public class Requests +{ + @Getter + @Setter + private static int REDIRECT_LIMIT = 15; + + private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) + { + if (response.getStatus() == HTTPResponse.RequestStatus.OK && !response.isRedirect()) + return response; + + RequestContext request = response.getRequest(); + + String location = response.getHeader("Location"); + if (location == null) + return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, + request, response.getStatusCode(), response.getHeaders(), null + ); + + if (redirectCount > REDIRECT_LIMIT) + return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LIMIT_EXCEED, + request, response.getStatusCode(), response.getHeaders(), null + ); + + try + { + URL newURL = new URL(location); + + HTTPResponse newResponse = request(RequestContext.builder() + .cacheable(request.isCacheable()) + .method(request.getMethod()) + .extraHeaders(request.getExtraHeaders()) + .followRedirects(false) + .timeout(request.getTimeout()) + .body(request.getBody()) + .url(newURL) + .build()); + + return doRedirect(newResponse, redirectCount + 1); + } + catch (MalformedURLException ex) + { + return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, + response.getRequest(), response.getStatusCode(), response.getHeaders(), null + ); + } + } + + private static Map setupDefaultHeaders(@NotNull String host) + { + HashMap headers = new HashMap<>(); + + headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + + TeamKunPluginManager.getPlugin().getDescription().getVersion()); + + if (host.equalsIgnoreCase("github.com") || + StringUtils.endsWithIgnoreCase(host, ".github.com") || + StringUtils.endsWithIgnoreCase(host, ".githubusercontent.com")) + { + headers.put("Accept", "application/vnd.github.v3+json"); + + if (TeamKunPluginManager.getPlugin().isTokenAvailable()) + headers.put("Authorization", "Token " + TeamKunPluginManager.getPlugin().getVault().getToken()); + + } + else if (host.equalsIgnoreCase("file.io")) + headers.put("Referer", "https://www.file.io/"); + + + return headers; + } + + @NotNull + public static HTTPResponse request(@NotNull RequestContext context) + { + if (context.getUrl() == null) + throw new IllegalArgumentException("URL is null"); + + try + { + HttpURLConnection connection = (HttpURLConnection) context.getUrl().openConnection(); + + connection.setRequestMethod(context.getMethod().name()); + connection.setDoOutput(context.getBody() != null); + connection.setDoInput(true); + connection.setUseCaches(false); + connection.setConnectTimeout(10000); + + if (context.getTimeout() > 0) + connection.setReadTimeout(context.getTimeout()); + + for (Map.Entry entry : context.getExtraHeaders().entrySet()) + connection.setRequestProperty(entry.getKey(), entry.getValue()); + + setupDefaultHeaders(context.getUrl().getHost()) + .forEach(connection::setRequestProperty); + + connection.connect(); + + if (context.getBody() != null) + try (OutputStream outputStream = connection.getOutputStream()) + { + outputStream.write(context.getBody()); + } + + int responseCode = connection.getResponseCode(); + + HashMap serverHeaders = connection.getHeaderFields().entrySet().stream().parallel() + .map(stringListEntry -> new AbstractMap.SimpleEntry<>( + stringListEntry.getKey().toLowerCase(), + String.join(" ", stringListEntry.getValue()) + )) + .collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll); + + HTTPResponse response = new HTTPResponse(HTTPResponse.RequestStatus.OK, + context, responseCode, serverHeaders, connection.getInputStream() + ); + + if (context.isFollowRedirects()) + doRedirect(response, 0); + + return response; + } + catch (UnknownHostException ex) + { + return new HTTPResponse(HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST, context, 0, null, null); + } + catch (IOException ex) + { + return new HTTPResponse(HTTPResponse.RequestStatus.IO_EXCEPTION_OCCURRED, context, 0, null, null); + } + } + + /** + * Download a file from a URL + * + * @param method The HTTP method to use + * @param url The URL to download from + * @param path The path to save the file to + * @param onProgress A callback to be called when the download progresses. + * @return The downloaded file size or -1 if the download failed. + * @throws IOException If the download failed + */ + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, + @NotNull Path path, @Nullable Consumer onProgress) throws IOException + { + try (HTTPResponse response = request(RequestContext.builder() + .url(url) + .method(method) + .followRedirects(true) + .build()); + OutputStream output = Files.newOutputStream(path)) + { + if (response.getStatus() != HTTPResponse.RequestStatus.OK) + throw new IOException("Download failed: " + response.getStatus()); + else if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) + throw new IOException("HTTP error " + response.getStatusCode()); + else if (response.getInputStream() == null) + throw new IOException("No response body was returned"); + + String contentLength = response.getHeader("Content-Length"); + long size = contentLength != null ? Long.parseLong(contentLength): -1; + + byte[] buffer = new byte[1024]; + + int read; + long downloaded = 0; + while ((read = response.getInputStream().read(buffer)) != -1) + { + output.write(buffer, 0, read); + downloaded += read; + + if (onProgress == null) + continue; + + int progress; + if (downloaded != 0 && size != 0) + progress = (int) (downloaded * 100 / size); + else + progress = 0; + + onProgress.accept(new DownloadProgress(progress, downloaded, size)); + } + + return size; + } + catch (IOException e) + { + if (Files.exists(path)) + Files.delete(path); + + throw e; + } + } + + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, + @NotNull Path path) throws IOException + { + return downloadFile(method, url, path, null); + } + + @Value + public static class DownloadProgress + { + long totalSize; + long downloaded; + + double percentage; + } +} From 5b07f87d40a11d2a311a1e45aba7eb7ede1159af Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 16 Apr 2022 20:01:56 +0900 Subject: [PATCH 071/745] refactor: Change parameter URL to String --- .../utils/http/HTTPResponse.java | 3 +- .../utils/http/RequestContext.java | 3 +- .../utils/http/Requests.java | 46 ++++++++----------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 64188385..43913357 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -102,6 +102,7 @@ public enum RequestStatus REDIRECT_LOCATION_MALFORMED, REDIRECT_LIMIT_EXCEED, UNABLE_TO_RESOLVE_HOST, - IO_EXCEPTION_OCCURRED + IO_EXCEPTION_OCCURRED, + URL_MALFORMED } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java index f4fdcd9f..a4ae9415 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java @@ -4,14 +4,13 @@ import lombok.Singular; import lombok.Value; -import java.net.URL; import java.util.Map; @Value @Builder public class RequestContext { - URL url; + String url; @Builder.Default RequestMethod method = RequestMethod.GET; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 5dfc83a6..1804f9e3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -45,28 +45,17 @@ private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) request, response.getStatusCode(), response.getHeaders(), null ); - try - { - URL newURL = new URL(location); - - HTTPResponse newResponse = request(RequestContext.builder() - .cacheable(request.isCacheable()) - .method(request.getMethod()) - .extraHeaders(request.getExtraHeaders()) - .followRedirects(false) - .timeout(request.getTimeout()) - .body(request.getBody()) - .url(newURL) - .build()); - - return doRedirect(newResponse, redirectCount + 1); - } - catch (MalformedURLException ex) - { - return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, - response.getRequest(), response.getStatusCode(), response.getHeaders(), null - ); - } + HTTPResponse newResponse = request(RequestContext.builder() + .cacheable(request.isCacheable()) + .method(request.getMethod()) + .extraHeaders(request.getExtraHeaders()) + .followRedirects(false) + .timeout(request.getTimeout()) + .body(request.getBody()) + .url(location) + .build()); + + return doRedirect(newResponse, redirectCount + 1); } private static Map setupDefaultHeaders(@NotNull String host) @@ -101,7 +90,8 @@ public static HTTPResponse request(@NotNull RequestContext context) try { - HttpURLConnection connection = (HttpURLConnection) context.getUrl().openConnection(); + URL url = new URL(context.getUrl()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(context.getMethod().name()); connection.setDoOutput(context.getBody() != null); @@ -115,7 +105,7 @@ public static HTTPResponse request(@NotNull RequestContext context) for (Map.Entry entry : context.getExtraHeaders().entrySet()) connection.setRequestProperty(entry.getKey(), entry.getValue()); - setupDefaultHeaders(context.getUrl().getHost()) + setupDefaultHeaders(url.getHost()) .forEach(connection::setRequestProperty); connection.connect(); @@ -144,6 +134,10 @@ public static HTTPResponse request(@NotNull RequestContext context) return response; } + catch (MalformedURLException ex) + { + return new HTTPResponse(HTTPResponse.RequestStatus.URL_MALFORMED, context, 0, null, null); + } catch (UnknownHostException ex) { return new HTTPResponse(HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST, context, 0, null, null); @@ -164,7 +158,7 @@ public static HTTPResponse request(@NotNull RequestContext context) * @return The downloaded file size or -1 if the download failed. * @throws IOException If the download failed */ - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, @NotNull Path path, @Nullable Consumer onProgress) throws IOException { try (HTTPResponse response = request(RequestContext.builder() @@ -216,7 +210,7 @@ else if (response.getInputStream() == null) } } - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, @NotNull Path path) throws IOException { return downloadFile(method, url, path, null); From 5d23ec7a6dbafdff2b0cde238d055b29e256f6c3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 14:14:02 +0900 Subject: [PATCH 072/745] refactor: change response of requests --- .../utils/http/HTTPResponse.java | 5 +++++ .../teamkunpluginmanager/utils/http/Requests.java | 14 +++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 43913357..93052ea1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -96,6 +96,11 @@ public boolean isOK() return statusCode == 200; } + public static HTTPResponse error(@NotNull RequestContext request, @NotNull RequestStatus status) + { + return new HTTPResponse(status, request, -1, null, null); + } + public enum RequestStatus { OK, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 1804f9e3..b3db0540 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -36,14 +36,10 @@ private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) String location = response.getHeader("Location"); if (location == null) - return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, - request, response.getStatusCode(), response.getHeaders(), null - ); + return HTTPResponse.error(request, HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED); if (redirectCount > REDIRECT_LIMIT) - return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LIMIT_EXCEED, - request, response.getStatusCode(), response.getHeaders(), null - ); + return HTTPResponse.error(request, HTTPResponse.RequestStatus.REDIRECT_LIMIT_EXCEED); HTTPResponse newResponse = request(RequestContext.builder() .cacheable(request.isCacheable()) @@ -136,15 +132,15 @@ public static HTTPResponse request(@NotNull RequestContext context) } catch (MalformedURLException ex) { - return new HTTPResponse(HTTPResponse.RequestStatus.URL_MALFORMED, context, 0, null, null); + return HTTPResponse.error(context, HTTPResponse.RequestStatus.URL_MALFORMED); } catch (UnknownHostException ex) { - return new HTTPResponse(HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST, context, 0, null, null); + return HTTPResponse.error(context, HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST); } catch (IOException ex) { - return new HTTPResponse(HTTPResponse.RequestStatus.IO_EXCEPTION_OCCURRED, context, 0, null, null); + return HTTPResponse.error(context, HTTPResponse.RequestStatus.IO_EXCEPTION_OCCURRED); } } From cb5cb2083368b63250b7165e7beed21c67314547 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 15:45:49 +0900 Subject: [PATCH 073/745] feat: Header handling --- .../utils/http/HTTPResponse.java | 5 +++- .../utils/http/Requests.java | 23 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 93052ea1..472c42ab 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -16,6 +16,9 @@ public class HTTPResponse implements AutoCloseable RequestStatus status; RequestContext request; + String serverProtocol; + String protocolVersion; + int statusCode; HashMap headers; @@ -98,7 +101,7 @@ public boolean isOK() public static HTTPResponse error(@NotNull RequestContext request, @NotNull RequestStatus status) { - return new HTTPResponse(status, request, -1, null, null); + return new HTTPResponse(status, request, null, null, -1, null, null); } public enum RequestStatus diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index b3db0540..57aeb1a4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -116,13 +116,32 @@ public static HTTPResponse request(@NotNull RequestContext context) HashMap serverHeaders = connection.getHeaderFields().entrySet().stream().parallel() .map(stringListEntry -> new AbstractMap.SimpleEntry<>( - stringListEntry.getKey().toLowerCase(), + stringListEntry.getKey() == null ? null: stringListEntry.getKey().toLowerCase(), String.join(" ", stringListEntry.getValue()) )) .collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll); + String protocol = "HTTP"; + String protocolVersion = "1.1"; + + if (serverHeaders.containsKey(null)) + { + String[] protocolAndStatus = StringUtils.split(serverHeaders.get(null), " "); + if (protocolAndStatus.length > 1) + { + String[] protocolAndVersion = StringUtils.split(protocolAndStatus[0], "/"); + if (protocolAndVersion.length > 0) + protocol = protocolAndVersion[0]; + if (protocolAndVersion.length > 1) + protocolVersion = protocolAndVersion[1]; + } + + serverHeaders.remove(null); + } + HTTPResponse response = new HTTPResponse(HTTPResponse.RequestStatus.OK, - context, responseCode, serverHeaders, connection.getInputStream() + context, protocol, protocolVersion, responseCode, serverHeaders, + connection.getInputStream() ); if (context.isFollowRedirects()) From 01434532a5220531e126a1308b85586beb2fdc0e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 17:00:30 +0900 Subject: [PATCH 074/745] fix: Redirect options --- .../kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 57aeb1a4..2e9b195b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -59,7 +59,7 @@ private static Map setupDefaultHeaders(@NotNull String host) HashMap headers = new HashMap<>(); headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + - TeamKunPluginManager.getPlugin().getDescription().getVersion()); + "1"); if (host.equalsIgnoreCase("github.com") || StringUtils.endsWithIgnoreCase(host, ".github.com") || @@ -89,6 +89,7 @@ public static HTTPResponse request(@NotNull RequestContext context) URL url = new URL(context.getUrl()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setInstanceFollowRedirects(false); connection.setRequestMethod(context.getMethod().name()); connection.setDoOutput(context.getBody() != null); connection.setDoInput(true); @@ -145,7 +146,7 @@ public static HTTPResponse request(@NotNull RequestContext context) ); if (context.isFollowRedirects()) - doRedirect(response, 0); + return doRedirect(response, 0); return response; } From 08924c352a06e9d53a6a1524152d38c9b867c493 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 17:07:28 +0900 Subject: [PATCH 075/745] test: Requests --- .../result/http/RequestsTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java new file mode 100644 index 00000000..829e8da1 --- /dev/null +++ b/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java @@ -0,0 +1,59 @@ +package net.kunmc.lab.teamkunpluginmanager.result.http; + +import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import org.junit.Assert; +import org.junit.Test; + +public class RequestsTest +{ + private static final String mockUrl = "https://run.mocky.io/v3/63f730d5-cb39-413e-a56f-37450aea4df0"; + private static final String redirMockURl = "https://run.mocky.io/v3/3df2a3b9-c9fd-4b44-a69c-2c408d9f93fa"; + + @Test + public void testGetNoRedir() + { + HTTPResponse response = Requests.request(RequestContext.builder() + .url(mockUrl) + .build()); + + Assert.assertEquals(200, response.getStatusCode()); + Assert.assertEquals(response.getHeader("Content-Type"), "application/json; charset=UTF-8"); + + JsonObject json = response.getAsJson().getAsJsonObject(); + + Assert.assertEquals(json.get("hello").getAsString(), "world"); + } + + @Test + public void testGetRedir() + { + HTTPResponse response = Requests.request(RequestContext.builder() + .url(redirMockURl) + .followRedirects(true) + .build()); + + Assert.assertEquals(200, response.getStatusCode()); + Assert.assertEquals(response.getHeader("Content-Type"), "application/json; charset=UTF-8"); + + JsonObject json = response.getAsJson().getAsJsonObject(); + + Assert.assertEquals(json.get("hello").getAsString(), "world"); + } + + @Test + public void testGetRedirButNoRedir() + { + HTTPResponse response = Requests.request(RequestContext.builder() + .url(redirMockURl) + .followRedirects(false) + .build()); + + Assert.assertEquals(301, response.getStatusCode()); + Assert.assertEquals(response.getHeader("Location"), mockUrl); + } + + +} From daada3257b8dbfb6f081f909015698c7377779c3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 18:45:40 +0900 Subject: [PATCH 076/745] feat: SERVER_ERROR and CLIENT_ERROR --- .../lab/teamkunpluginmanager/utils/http/HTTPResponse.java | 3 +++ .../lab/teamkunpluginmanager/utils/http/Requests.java | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 472c42ab..13a340c6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -107,6 +107,9 @@ public static HTTPResponse error(@NotNull RequestContext request, @NotNull Reque public enum RequestStatus { OK, + SERVER_ERROR, + CLIENT_ERROR, + REDIRECT_LOCATION_MALFORMED, REDIRECT_LIMIT_EXCEED, UNABLE_TO_RESOLVE_HOST, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 2e9b195b..579e33ef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -140,7 +140,13 @@ public static HTTPResponse request(@NotNull RequestContext context) serverHeaders.remove(null); } - HTTPResponse response = new HTTPResponse(HTTPResponse.RequestStatus.OK, + HTTPResponse.RequestStatus status = HTTPResponse.RequestStatus.OK; + if (responseCode >= 500) + status = HTTPResponse.RequestStatus.SERVER_ERROR; + else if (responseCode >= 400) + status = HTTPResponse.RequestStatus.CLIENT_ERROR; + + HTTPResponse response = new HTTPResponse(status, context, protocol, protocolVersion, responseCode, serverHeaders, connection.getInputStream() ); From b5a22a24150090a7c521726c961e1a47c162ed6c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 22:57:42 +0900 Subject: [PATCH 077/745] feat: Cache with body --- .../utils/http/HTTPResponse.java | 29 ++++++++++++------- .../result/http/RequestsTest.java | 11 +++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 13a340c6..e8c770e2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -2,7 +2,9 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; -import lombok.Value; +import lombok.AccessLevel; +import lombok.Data; +import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,26 +12,32 @@ import java.io.InputStream; import java.util.HashMap; -@Value +@Data public class HTTPResponse implements AutoCloseable { - RequestStatus status; - RequestContext request; + private final RequestStatus status; + private final RequestContext request; - String serverProtocol; - String protocolVersion; + private final String serverProtocol; + private final String protocolVersion; - int statusCode; + private final int statusCode; - HashMap headers; + private final HashMap headers; @Nullable - InputStream inputStream; + private final InputStream inputStream; + + @Getter(AccessLevel.PRIVATE) + private String bodyCache = null; public String getAsString() { if (inputStream == null) return null; + else if (bodyCache != null) + return bodyCache; + StringBuilder sb = new StringBuilder(); byte[] buffer = new byte[1024]; @@ -44,7 +52,8 @@ public String getAsString() e.printStackTrace(); } - return sb.toString(); + bodyCache = sb.toString(); + return bodyCache; } public JsonElement getAsJson() diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java index 829e8da1..e330e849 100644 --- a/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java +++ b/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java @@ -55,5 +55,16 @@ public void testGetRedirButNoRedir() Assert.assertEquals(response.getHeader("Location"), mockUrl); } + @Test + public void testGetCache() + { + HTTPResponse response = Requests.request(RequestContext.builder() + .url(mockUrl) + .build()); + + String first = response.getAsString(); + String second = response.getAsString(); + Assert.assertEquals(first, second); + } } From 57be3cf4451ee2d7f30710d46d2b453ac9ca8b12 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 23:48:02 +0900 Subject: [PATCH 078/745] chore: Remove unused class: GitHubURLBuilder --- .../utils/GitHubURLBuilder.java | 237 ------------------ 1 file changed, 237 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java deleted file mode 100644 index cb904314..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/GitHubURLBuilder.java +++ /dev/null @@ -1,237 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -import javax.annotation.Nullable; -import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -public class GitHubURLBuilder -{ - /** - * APIのURL。APIが変更されたら変更。 - */ - private static final String GITHUB_REPO_RELEASES_URL = "https://api.github.com/repos/%s/releases"; - - /** - * APIのURL。APIが変更されたら変更。 - */ - private static final String GITHUB_REPO_RELEASE_NAME_URL = GITHUB_REPO_RELEASES_URL + "/tags/%s"; - - /** - * GitHubのURLかどうかを判定/パースをする。 - */ - private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("^/(?[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38}/[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100})(?:/?$|/(?:tag|release)s(?:/?$|/(?:tag/(?[^/]+)/?$|download/(?[^/]+)/(?[^/]+))))/?$"); - - /** - * GitHubのリリースへのAPIのURlをビルドします。 - * tagName をnullにできます。 - * - * @param repository リポジトリ名 - * @param tagName タグ(リリース)バージョン - * @return URlのタイプ, ビルドしたURL - * @throws NullPointerException repositoryがnullだった場合 - */ - private static Pair buildAPIUrl(String repository, @Nullable String tagName) - { - //リポジトリがNullだった場合ERRORのみを返す。 - if (repository == null) - return new Pair<>("ERROR", ""); - - //タグがなかった場合はリリースすべてを返す。 - if (tagName == null) - return new Pair<>("GITHUB_REPO_RELEASES_URL", String.format(GITHUB_REPO_RELEASES_URL, repository)); - else //タグがあったら/tags/までのリソースを返す。 - return new Pair<>("GITHUB_REPO_RELEASE_NAME_URL", String.format(GITHUB_REPO_RELEASE_NAME_URL, repository, tagName)); - } - - /** - * GitHubのURLを適正化 - * https://github.com/examples/ExamplePlugin => https://github.com/examples/ExamplePlugin/releases/download/1.0/ExamplePlugin-1.0.jar - * https://example.com/ => https://example.com/ - * - * @param urlName GitHubの様々なURL - * @return GitHubのURl - */ - public static String urlValidate(String urlName, String version) - { - //URLかどうか検証。 - URL url; - try - { - url = new URL(urlName); - } - catch (Exception e) //URLではない場合はオウム返し。 - { - return urlName; - } - - //URLのホストが github.com もしくは www.github.com かどうか。 - if (!url.getHost().equals("github.com") && !url.getHost().equals("www.github.com")) - return urlName; - - //パターンとマッチするか。 - Matcher matcher = GITHUB_REPO_PATTERN.matcher(url.getPath()); - - String repoName = null; - String tagName = null; - - //グループごと。 - while (matcher.find()) - { - String repository = matcher.group("repo"); - String tag = matcher.group("dlTag"); - String tagNF = matcher.group("tag"); - String file = matcher.group("fileName"); - - //ファイルがない、もしくは""だった場合はオウム返し。 - if (file != null && !file.isEmpty()) - return urlName; - - //この辺は代入なので無視。 - if (!repository.isEmpty()) - repoName = repository; - if (tag != null && !tag.isEmpty()) - tagName = tag; - else if (tagNF != null && !tagNF.isEmpty()) - tagName = tagNF; - } - - //tagがなく、version(@で区切られるやつ)がある場合はこちらを優先。 - if (tagName == null && version != null) - tagName = version; - - //URLをペアから作る。 - Pair urlPair = buildAPIUrl(repoName, tagName); - - switch (urlPair.getLeft()) - { - case "GITHUB_REPO_RELEASES_URL": - { - //APIを叩く。 - Pair json = URLUtils.getAsString(urlPair.getRight()); - switch (json.getLeft()) - { - case 404: - return "ERROR ファイルが見つかりませんでした。"; - case 403: - return "ERROR ファイルを取得できません。しばらくしてからもう一度実行してください。"; - } - - //200ではない場合はエラー。 - if (json.getLeft() != 200) - return "ERROR 不明なエラーが発生しました。"; - - //APIレスポンスがエラーかどうか。 - String error = error(json.getRight()); - if (!error.isEmpty()) - return "ERROR " + error; - - JsonArray array = new Gson().fromJson(json.getRight(), JsonArray.class); - - if (array.size() == 0) - return "ERROR リリースが見つかりませんでした。"; - - //最新(i:0)をとり、assetsまでもってくる。 - JsonArray asset = ((JsonObject) array.get(0)).get("assets").getAsJsonArray(); - - if (array.size() == 0) - return "ERROR アーティファクトが見つかりませんでした。"; - - //assetが一つしかなかったら返す。 - if (asset.size() == 1) - return ((JsonObject) asset.get(0)).get("browser_download_url").getAsString(); - - //assetが2つ以上あるのでMULTIフラグを立てて返す。 - return "MULTI " + StreamSupport.stream(asset.spliterator(), true) - .map(element -> { - JsonObject obj = (JsonObject) element; - String assetName = obj.get("name").getAsString(); - String assetDownloadUrl = obj.get("browser_download_url").getAsString(); - return assetName.replace("|", "\\|") + "|" + assetDownloadUrl.replace("|", "\\|"); - }) - .collect(Collectors.joining("|")) + "|"; - - - } - case "GITHUB_REPO_RELEASE_NAME_URL": - { - //APIを叩く。 - Pair json = URLUtils.getAsString(urlPair.getRight()); - switch (json.getLeft()) - { - case 404: - return "ERROR ファイルが見つかりませんでした。"; - case 403: - return "ERROR ファイルを取得できません。しばらくしてからもう一度実行してください。"; - } - - //200ではない場合はエラー。 - if (json.getLeft() != 200) - return "ERROR 不明なエラーが発生しました。"; - - //APIレスポンスがエラーかどうか。 - String error = error(json.getRight()); - if (!error.isEmpty()) - return "ERROR " + error; - - //アセットを上からなめる - JsonObject array = new Gson().fromJson(json.getRight(), JsonObject.class); - JsonArray asset = array.get("assets").getAsJsonArray(); - - //assetが一つしかなかったら返す。 - if (asset.size() == 1) - return ((JsonObject) asset.get(0)).get("browser_download_url").getAsString(); - - //assetが2つ以上あるのでMULTIフラグを立てて返す。 - return "MULTI " + StreamSupport.stream(asset.spliterator(), true) - .map(element -> { - JsonObject obj = (JsonObject) element; - String assetName = obj.get("name").getAsString(); - String assetDownloadUrl = obj.get("browser_download_url").getAsString(); - return assetName.replace("|", "\\|") + "|" + assetDownloadUrl.replace("|", "\\|"); - }) - .collect(Collectors.joining("|")) + "|"; - } - case "ERROR": //ERRORだった場合はオウム返し。 - default: - return url.toString(); - } - } - - private static String error(String json) - { - try - { - JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class); - if (!jsonObject.has("message")) - return ""; - return jsonObject.get("message").getAsString(); - } - catch (Exception ignored) - { - return ""; - } - } - - public static boolean isRepoExists(String name) - { - return String.valueOf(URLUtils.fetch("https://api.github.com/repos/" + name + "", "HEAD")).startsWith("2"); - } - - public static boolean isPermissionGranted(String path) - { - return URLUtils.fetch("https://api.github.com" + path, "HEAD") != 401; - } - - public static class BuildResult - { - public String name; - public String url; - } -} From 6fa1ee955e354743f688c046dfd0cbd966c084e6 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 18 Apr 2022 13:07:39 +0900 Subject: [PATCH 079/745] refactor: URL Utils requester --- .../commands/CommandRegister.java | 65 +++++----- .../resolver/impl/CurseBukkitResolver.java | 32 +++-- .../impl/CurseBukkitSuccessResult.java | 15 +-- .../resolver/impl/GitHubURLResolver.java | 20 ++- .../resolver/impl/SpigotMCResolver.java | 19 ++- .../resolver/interfaces/URLResolver.java | 37 +++++- .../teamkunpluginmanager/utils/URLUtils.java | 119 ------------------ 7 files changed, 118 insertions(+), 189 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index ccdc1f0f..3359a308 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.commands; -import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; @@ -9,8 +8,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import net.kyori.adventure.text.TextComponent; import org.bukkit.ChatColor; import org.bukkit.command.BlockCommandSender; @@ -24,22 +24,32 @@ public class CommandRegister extends CommandBase { - private final static String CLIENT_ID = "94c5d446dbc765895979"; + private static final String CLIENT_ID = "94c5d446dbc765895979"; + private static final String OAUTH_SCOPE = "repo%20public_repo"; + private static final String OAUTH_PREPARE_URL = + "https://github.com/login/device/code?client_id=" + CLIENT_ID + "&scope=" + OAUTH_SCOPE; + private static final String OAUTH_ACCESS_URL = + "https://github.com/login/oauth/access_token?client_id=" + CLIENT_ID + + "&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&device_code="; + private static final TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - private static void parseErrorAndPost(Terminal terminal, String data, int code) + private static void parseErrorAndPost(Terminal terminal, HTTPResponse response) { try { - JsonObject response = new Gson().fromJson(data, JsonObject.class); - if (response.has("error")) - terminal.error("エラーが発生しました。:Server response with " + parseError(response.get("error").getAsString())); + JsonObject json = response.getAsJson().getAsJsonObject(); + if (json.has("error")) + terminal.error("エラーが発生しました。:Server response with " + parseError(json.get("error").getAsString())); else - terminal.error("エラーが発生しました。:Server response with code " + code); + terminal.error("エラーが発生しました。:Server response with code " + response.getStatusCode()); } - catch (JsonSyntaxException e) + catch (JsonSyntaxException | IllegalStateException e) { - terminal.error("サーバから不正なデータを受信しました。:" + data.substring(0, Math.min(data.length(), 50))); + String responseString = response.getAsString(); + + terminal.error("サーバから不正なデータを受信しました。:" + + responseString.substring(0, Math.min(responseString.length(), 50))); } } @@ -47,18 +57,17 @@ private static void performAction(Terminal terminal) { terminal.info(ChatColor.LIGHT_PURPLE + "サーバと通信しています..."); - Pair data = URLUtils.postAsString( - "https://github.com/login/device/code?client_id=" + CLIENT_ID + "&scope=repo%20public_repo", - "", "application/json", "text/plain" - ); + HTTPResponse response = Requests.request(RequestContext.builder() + .method(RequestContext.RequestMethod.GET) + .url(OAUTH_PREPARE_URL) + .build()); - if (data.getLeft() != 200) + if (response.getStatus() != HTTPResponse.RequestStatus.OK) { - parseErrorAndPost(terminal, data.getRight(), data.getLeft()); - return; + parseErrorAndPost(terminal, response); } - JsonObject object = new Gson().fromJson(data.getRight(), JsonObject.class); + JsonObject object = response.getAsJson().getAsJsonObject(); String deviceCode = object.get("device_code").getAsString(); String userCode = object.get("user_code").getAsString(); @@ -93,20 +102,18 @@ private static void performAction(Terminal terminal) private static Runner.GeneralExceptableRunner polling(Terminal terminal, String device_code, AtomicBoolean successFlag) { return () -> { - Pair pollingData = URLUtils.postAsString( - "https://github.com/login/oauth/access_token?client_id=" + CLIENT_ID + - "&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&device_code=" + device_code, - "", - "application/json", - "text/plain" - ); - if (pollingData.getLeft() != 200) + HTTPResponse httpResponse = Requests.request(RequestContext.builder() + .method(RequestContext.RequestMethod.POST) + .url(OAUTH_ACCESS_URL + device_code) + .build()); + + if (httpResponse.getStatus() != HTTPResponse.RequestStatus.OK) { - parseErrorAndPost(terminal, pollingData.getRight(), pollingData.getLeft()); + parseErrorAndPost(terminal, httpResponse); throw new RuntimeException(); // For cancel bukkit task } - JsonObject response = new Gson().fromJson(pollingData.getRight(), JsonObject.class); + JsonObject response = httpResponse.getAsJson().getAsJsonObject(); if (response.has("error")) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 7d81bcf8..6e4cd265 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; -import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -9,8 +8,9 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.jetbrains.annotations.Nullable; @@ -67,12 +67,18 @@ public ResolveResult resolve(QueryContext query) if (slug == null) return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, errorSource); - Pair projectSearchResponse = URLUtils.getAsString("https://servermods.forgesvc.net/servermods/projects?search=" + slug); + HTTPResponse response = Requests.request(RequestContext.builder() + .url("https://servermods.forgesvc.net/servermods/projects?search=" + slug) + .build()); - if (projectSearchResponse.getLeft() != 200) - return processErrorResponse(projectSearchResponse.getLeft(), errorSource); + if (response.getStatus() != HTTPResponse.RequestStatus.OK) + return processErrorResponse(response, errorSource); - JsonArray projectSearchResult = new Gson().fromJson(projectSearchResponse.getRight(), JsonArray.class); + JsonElement json = response.getAsJson(); + if (!json.isJsonArray()) + return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED, errorSource); + + JsonArray projectSearchResult = (JsonArray) json; String name = null; long projectId = -1; @@ -96,13 +102,19 @@ public ResolveResult resolve(QueryContext query) private ResolveResult processFiles(String slug, String name, long projectId, String version, ResolveResult.Source source) { - Pair projectFilesResponse = URLUtils.getAsString("https://servermods.forgesvc.net/servermods/files?projectIds=" + projectId); + HTTPResponse response = Requests.request(RequestContext.builder() + .url("https://servermods.forgesvc.net/servermods/files?projectIds=" + projectId) + .build()); - ErrorResult mayError = processErrorResponse(projectFilesResponse.getLeft(), source); + ErrorResult mayError = processErrorResponse(response, source); if (mayError != null) return mayError; - JsonArray projectFilesResult = new Gson().fromJson(projectFilesResponse.getRight(), JsonArray.class); + JsonElement json = response.getAsJson(); + if (!json.isJsonArray()) + return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED, source); + + JsonArray projectFilesResult = (JsonArray) json; if (projectFilesResult.size() == 0) return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND, source); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index ebc19d45..571bb933 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -3,8 +3,9 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -52,13 +53,13 @@ public String getDescription() if (this.description != null) return this.description; - Pair description = - URLUtils.getAsString("https://addons-ecs.forgesvc.net/api/v2/addon/" + this.id +"/description"); - - if (description.getLeft() != 200) + HTTPResponse response = Requests.request(RequestContext.builder() + .url("https://addons-ecs.forgesvc.net/api/v2/addon/" + this.id + "/description") + .build()); + if (response.isError()) return "Failed to get description"; - this.description = description.getRight(); + this.description = response.getAsString(); return this.description; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 997a8d45..c2bd53c5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; -import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -10,8 +9,9 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -89,25 +89,23 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri else apiURL = String.format(GITHUB_REPO_RELEASES_URL, repository); - Pair response = URLUtils.getAsString(apiURL); + HTTPResponse response = Requests.request(RequestContext.builder() + .url(apiURL) + .build()); - ErrorResult mayError = processErrorResponse(response.getLeft(), ResolveResult.Source.GITHUB); + ErrorResult mayError = processErrorResponse(response, ResolveResult.Source.GITHUB); if (mayError != null) return mayError; - String json = response.getRight(); - - Gson gson = new Gson(); - if (tag != null) { - JsonObject jsonObject = gson.fromJson(json, JsonObject.class); + JsonObject jsonObject = response.getAsJson().getAsJsonObject(); return buildResultSingle(owner, repositoryName, jsonObject, version); } - JsonArray jsonArray = gson.fromJson(json, JsonArray.class); + JsonArray jsonArray = response.getAsJson().getAsJsonArray(); List results = new ArrayList<>(); boolean isFound = false; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 1e56f6a3..c5aec3c8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; -import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; @@ -8,8 +7,9 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -51,19 +51,16 @@ public ResolveResult resolve(QueryContext query) String spigotAPIUrl = "https://apple.api.spiget.org/v2/resources/" + id; - Pair data = URLUtils.getAsString(spigotAPIUrl); + HTTPResponse data = Requests.request(RequestContext.builder() + .url(spigotAPIUrl) + .build()); - - ErrorResult mayError = processErrorResponse(data.getLeft(), ResolveResult.Source.SPIGOT_MC); + ErrorResult mayError = processErrorResponse(data, ResolveResult.Source.SPIGOT_MC); if (mayError != null) return mayError; - String json = data.getRight(); - Gson gson = new Gson(); - JsonObject jsonObject = gson.fromJson(json, JsonObject.class); - - return buildResult(jsonObject, version); + return buildResult(data.getAsJson().getAsJsonObject(), version); } private ResolveResult buildResult(JsonObject jsonObject, @Nullable String version) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index bbb2bf58..90c1d402 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -3,6 +3,7 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import java.net.MalformedURLException; import java.net.URL; @@ -61,10 +62,42 @@ default Matcher urlMatcher(Pattern pattern, String urlString) return pattern.matcher(url.getPath()); } - default ErrorResult processErrorResponse(int code, ResolveResult.Source source) + default ErrorResult processErrorResponse(HTTPResponse response, ResolveResult.Source source) { - ErrorResult.ErrorCause cause = ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR; + switch (response.getStatus()) + { + case URL_MALFORMED: + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY.value("不正なURLが指定されました。"), source); + case UNABLE_TO_RESOLVE_HOST: + URL url = null; + try + { + url = new URL(response.getRequest().getUrl()); + } + catch (MalformedURLException ignored) + { + } + return new ErrorResult(this, + ErrorResult.ErrorCause.INVALID_QUERY.value("ホストが解決できませんでした:" + + (url == null ? "Unknown host": url.getHost())), source + ); + case REDIRECT_LIMIT_EXCEED: + return new ErrorResult(this, + ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED.value("リダイレクト回数が上限に達しました。"), source + ); + case IO_EXCEPTION_OCCURRED: + return new ErrorResult(this, ErrorResult.ErrorCause.UNKNOWN_ERROR, source); + case REDIRECT_LOCATION_MALFORMED: + return new ErrorResult( + this, + ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED.value("リダイレクト先が不正です:" + response.getHeader("Location")), + source + ); + } + + ErrorResult.ErrorCause cause = ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR; + int code = response.getStatusCode(); switch (code) { case 200: diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java index 63f93b6d..2cb6f38e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java @@ -5,111 +5,15 @@ import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.PrintStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.UnknownHostException; -import java.nio.charset.StandardCharsets; import java.nio.file.NoSuchFileException; public class URLUtils { - /** - * URLにPOSTした結果を返す。 - * - * @param urlString URL - * @param data データ - * @param accept 受け入れるタイプ。 application/ - * @return レスポンスコード, 結果 - */ - public static Pair postAsString(String urlString, String data, String accept, String content_type) - { - try - { - URL url = new URL(urlString); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - if (url.getHost().endsWith("github.com") || url.getHost().equals("raw.githubusercontent.com")) - connection.setRequestProperty( - "Authorization", - "token " + TeamKunPluginManager.getPlugin().getVault().getToken() - ); - if (url.getHost().equals("file.io")) - connection.setRequestProperty("Referer", "https://www.file.io/"); - connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); - connection.setRequestProperty("Accept", accept); - connection.setRequestProperty("Content-Type", content_type); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.connect(); - - try (OutputStream os = connection.getOutputStream()) - { - PrintStream prtstr = new PrintStream(os); - prtstr.println(data); - prtstr.close(); - int resp = connection.getResponseCode(); - if (resp < 200 || resp > 299) - return new Pair<>(resp, ""); - - try (InputStream is = connection.getInputStream()) - { - return new Pair<>(resp, IOUtils.toString(is, StandardCharsets.UTF_8)); - } - } - - } - catch (Exception e) - { - e.printStackTrace(); - return new Pair<>(-1, ""); - } - } - - /** - * URLから取得した結果を返す。 - * - * @param urlString URL - * @return レスポンスコード, 結果 - */ - public static Pair getAsString(String urlString) - { - try - { - URL url = new URL(urlString); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - if ((url.getHost().endsWith("github.com") || url.getHost().equals("raw.githubusercontent.com")) && - !TeamKunPluginManager.getPlugin().getVault().getToken().isEmpty()) - connection.setRequestProperty( - "Authorization", - "token " + TeamKunPluginManager.getPlugin().getVault().getToken() - ); - if (url.getHost().equals("file.io")) - connection.setRequestProperty("Referer", "https://www.file.io/"); - connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); - connection.connect(); - - try - { - return new Pair<>(connection.getResponseCode(), IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8)); - } - catch (IOException e) - { - return new Pair<>(connection.getResponseCode(), null); - } - - } - catch (Exception e) - { - e.printStackTrace(); - return new Pair<>(-1, ""); - } - } - /** * ファイルをだうんろーど! * @@ -228,27 +132,4 @@ public static Pair downloadFile(String url, String fileName) } } - - public static int fetch(String urlString, String method) - { - try - { - URL url = new URL(urlString); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(method); - if (url.getHost().endsWith("github.com") || url.getHost().equals("raw.githubusercontent.com")) - connection.setRequestProperty( - "Authorization", - "token " + TeamKunPluginManager.getPlugin().getVault().getToken() - ); - connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); - connection.connect(); - return connection.getResponseCode(); - - } - catch (Exception e) - { - return 500; - } - } } From 7d92cba0856754dc7fdba74c142b0cd377ca3af0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 20:09:59 +0000 Subject: [PATCH 080/745] chore(deps): bump lombok from 1.18.22 to 1.18.24 Bumps [lombok](https://github.com/projectlombok/lombok) from 1.18.22 to 1.18.24. - [Release notes](https://github.com/projectlombok/lombok/releases) - [Changelog](https://github.com/projectlombok/lombok/blob/master/doc/changelog.markdown) - [Commits](https://github.com/projectlombok/lombok/compare/v1.18.22...v1.18.24) --- updated-dependencies: - dependency-name: org.projectlombok:lombok dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 85c41599..213f0919 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ org.projectlombok lombok - 1.18.22 + 1.18.24 provided From 991c304347c5d047e7c11771d707adebfe62b048 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 21 Jun 2022 22:56:15 +0900 Subject: [PATCH 081/745] feat: Resolve command --- .../TeamKunPluginManager.java | 2 + .../commands/CommandResolve.java | 152 ++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index eeefdd10..5f352921 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -12,6 +12,7 @@ import net.kunmc.lab.teamkunpluginmanager.commands.CommandInstall; import net.kunmc.lab.teamkunpluginmanager.commands.CommandRegister; import net.kunmc.lab.teamkunpluginmanager.commands.CommandReload; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandResolve; import net.kunmc.lab.teamkunpluginmanager.commands.CommandStatus; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUninstall; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; @@ -113,6 +114,7 @@ public static void registerCommands(CommandManager commandManager) commandManager.registerCommand("install", new CommandInstall()); commandManager.registerCommand("register", new CommandRegister()); commandManager.registerCommand("reload", new CommandReload()); + commandManager.registerCommand("resolve", new CommandResolve()); commandManager.registerCommand("status", new CommandStatus()); commandManager.registerCommand("uninstall", new CommandUninstall()); commandManager.registerCommand("update", new CommandUpdate()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java new file mode 100644 index 00000000..032d3c4d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java @@ -0,0 +1,152 @@ +package net.kunmc.lab.teamkunpluginmanager.commands; + +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kyori.adventure.text.TextComponent; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class CommandResolve extends CommandBase +{ + private static final String DELIMITER_SMALL; + + private static final String DELIMITER; + + static + { + DELIMITER_SMALL = ChatColor.BLUE + "=============================="; + DELIMITER = StringUtils.repeat(DELIMITER_SMALL, 2); + } + + private static void printResult(Terminal terminal, ResolveResult result, boolean smallDelimiter) + { + if (smallDelimiter) + terminal.info(DELIMITER_SMALL); + else + terminal.info(DELIMITER); + + terminal.info("使用されたリザルバ:" + result.getResolver().getClass().getSimpleName()); + + if (result instanceof ErrorResult) + { + ErrorResult errorResult = (ErrorResult) result; + terminal.error("プラグインの名前解決に失敗しました:" + errorResult.getCause()); + } + else if (result instanceof SuccessResult) + { + SuccessResult successResult = (SuccessResult) result; + terminal.info("ファイル名:" + successResult.getFileName()); + terminal.info("バージョン:" + successResult.getVersion()); + terminal.info("ダウンロード:" + successResult.getDownloadUrl()); + + printAdditionalInformation(terminal, result); + } + else if (result instanceof MultiResult) + { + MultiResult multiResult = (MultiResult) result; + terminal.info("複数のファイルが見つかりました。"); + for (ResolveResult subResult : multiResult.getResults()) + printResult(terminal, subResult, true); + } + } + + private static void printAdditionalInformation(Terminal terminal, ResolveResult result) + { + if (result instanceof CurseBukkitSuccessResult) + { + CurseBukkitSuccessResult curseBukkitSuccessResult = (CurseBukkitSuccessResult) result; + + terminal.info("[CURSE_FORGE]"); + terminal.info("バージョン:" + curseBukkitSuccessResult.getVersion()); + terminal.info("ID:" + curseBukkitSuccessResult.getSlug() + "#" + curseBukkitSuccessResult.getSlug()); + terminal.info("説明:" + curseBukkitSuccessResult.getDescription()); + terminal.writeLine(DELIMITER_SMALL); + } + + if (result instanceof GitHubSuccessResult) + { + GitHubSuccessResult githubSuccessResult = (GitHubSuccessResult) result; + + terminal.info("[GITHUB]"); + terminal.info("リポジトリ:%s/%s" + githubSuccessResult.getOwner(), githubSuccessResult.getRepoName()); + terminal.info("ファイルサイズ:" + githubSuccessResult.getSize()); + terminal.info("リリース名:" + githubSuccessResult.getReleaseName()); + terminal.info("リリースID:" + githubSuccessResult.getReleaseId()); + terminal.info("リリース内容:" + githubSuccessResult.getReleaseBody()); + terminal.writeLine(DELIMITER_SMALL); + } + + if (result instanceof SpigotMCSuccessResult) + { + SpigotMCSuccessResult spigotMCSuccessResult = (SpigotMCSuccessResult) result; + + terminal.info("[SPIGOT_MC]"); + terminal.info("バージョン:" + String.join(", ", spigotMCSuccessResult.getVersions())); + terminal.writeLine(DELIMITER_SMALL); + } + + if (result instanceof MarketplaceResult) + { + MarketplaceResult marketplaceResult = (MarketplaceResult) result; + terminal.info("[MARKETPLACE]"); + terminal.info("タイトル:", marketplaceResult.getTitle()); + terminal.info("説明:", marketplaceResult.getDescription()); + terminal.info("公開先:", marketplaceResult.getUrl()); + terminal.writeLine(DELIMITER_SMALL); + } + } + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 1, 1)) + return; + + String query = args[0]; + + terminal.info("プラグインの名前解決をしています..."); + ResolveResult result = TeamKunPluginManager.getPlugin().getResolver().resolve(query); + + printResult(terminal, result, false); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.resolve"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("プラグインを名前解決します。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("query", "string") + }; + } +} From d19ac7d24b525604897a7879070e18944d63228c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 24 Jun 2022 01:00:57 +0900 Subject: [PATCH 082/745] fix: Parse error on repository name contains _ Closes #82 --- .../teamkunpluginmanager/resolver/impl/GitHubURLResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index c2bd53c5..b428b095 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -25,7 +25,7 @@ public class GitHubURLResolver implements URLResolver private static final String GITHUB_REPO_RELEASE_NAME_URL = GITHUB_REPO_RELEASES_URL + "/tags/%s"; private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("^/(?(?[a-zA-Z\\d]" + - "(?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38})/(?[a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,100}))" + + "(?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38})/(?\\w(?:\\w|-(?=\\w)){0,100}))" + "(?:/(?:tags|releases(?:/(?:tag/(?[^/]+)/?$|download/(?[^/]+)/" + "(?[^/]+)))?))?/?$"); From 0a42d06083d27cfc422409e3f57784757a760ed2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 16 Apr 2022 15:43:14 +0900 Subject: [PATCH 083/745] feat: New requester --- .../utils/http/HTTPResponse.java | 39 ++------ .../utils/http/RequestContext.java | 3 +- .../utils/http/Requests.java | 94 ++++++++----------- 3 files changed, 50 insertions(+), 86 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index e8c770e2..64188385 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -2,9 +2,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; -import lombok.AccessLevel; -import lombok.Data; -import lombok.Getter; +import lombok.Value; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,32 +10,23 @@ import java.io.InputStream; import java.util.HashMap; -@Data +@Value public class HTTPResponse implements AutoCloseable { - private final RequestStatus status; - private final RequestContext request; + RequestStatus status; + RequestContext request; - private final String serverProtocol; - private final String protocolVersion; + int statusCode; - private final int statusCode; - - private final HashMap headers; + HashMap headers; @Nullable - private final InputStream inputStream; - - @Getter(AccessLevel.PRIVATE) - private String bodyCache = null; + InputStream inputStream; public String getAsString() { if (inputStream == null) return null; - else if (bodyCache != null) - return bodyCache; - StringBuilder sb = new StringBuilder(); byte[] buffer = new byte[1024]; @@ -52,8 +41,7 @@ else if (bodyCache != null) e.printStackTrace(); } - bodyCache = sb.toString(); - return bodyCache; + return sb.toString(); } public JsonElement getAsJson() @@ -108,21 +96,12 @@ public boolean isOK() return statusCode == 200; } - public static HTTPResponse error(@NotNull RequestContext request, @NotNull RequestStatus status) - { - return new HTTPResponse(status, request, null, null, -1, null, null); - } - public enum RequestStatus { OK, - SERVER_ERROR, - CLIENT_ERROR, - REDIRECT_LOCATION_MALFORMED, REDIRECT_LIMIT_EXCEED, UNABLE_TO_RESOLVE_HOST, - IO_EXCEPTION_OCCURRED, - URL_MALFORMED + IO_EXCEPTION_OCCURRED } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java index a4ae9415..f4fdcd9f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java @@ -4,13 +4,14 @@ import lombok.Singular; import lombok.Value; +import java.net.URL; import java.util.Map; @Value @Builder public class RequestContext { - String url; + URL url; @Builder.Default RequestMethod method = RequestMethod.GET; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 579e33ef..5dfc83a6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -36,22 +36,37 @@ private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) String location = response.getHeader("Location"); if (location == null) - return HTTPResponse.error(request, HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED); + return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, + request, response.getStatusCode(), response.getHeaders(), null + ); if (redirectCount > REDIRECT_LIMIT) - return HTTPResponse.error(request, HTTPResponse.RequestStatus.REDIRECT_LIMIT_EXCEED); - - HTTPResponse newResponse = request(RequestContext.builder() - .cacheable(request.isCacheable()) - .method(request.getMethod()) - .extraHeaders(request.getExtraHeaders()) - .followRedirects(false) - .timeout(request.getTimeout()) - .body(request.getBody()) - .url(location) - .build()); + return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LIMIT_EXCEED, + request, response.getStatusCode(), response.getHeaders(), null + ); - return doRedirect(newResponse, redirectCount + 1); + try + { + URL newURL = new URL(location); + + HTTPResponse newResponse = request(RequestContext.builder() + .cacheable(request.isCacheable()) + .method(request.getMethod()) + .extraHeaders(request.getExtraHeaders()) + .followRedirects(false) + .timeout(request.getTimeout()) + .body(request.getBody()) + .url(newURL) + .build()); + + return doRedirect(newResponse, redirectCount + 1); + } + catch (MalformedURLException ex) + { + return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, + response.getRequest(), response.getStatusCode(), response.getHeaders(), null + ); + } } private static Map setupDefaultHeaders(@NotNull String host) @@ -59,7 +74,7 @@ private static Map setupDefaultHeaders(@NotNull String host) HashMap headers = new HashMap<>(); headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + - "1"); + TeamKunPluginManager.getPlugin().getDescription().getVersion()); if (host.equalsIgnoreCase("github.com") || StringUtils.endsWithIgnoreCase(host, ".github.com") || @@ -86,10 +101,8 @@ public static HTTPResponse request(@NotNull RequestContext context) try { - URL url = new URL(context.getUrl()); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + HttpURLConnection connection = (HttpURLConnection) context.getUrl().openConnection(); - connection.setInstanceFollowRedirects(false); connection.setRequestMethod(context.getMethod().name()); connection.setDoOutput(context.getBody() != null); connection.setDoInput(true); @@ -102,7 +115,7 @@ public static HTTPResponse request(@NotNull RequestContext context) for (Map.Entry entry : context.getExtraHeaders().entrySet()) connection.setRequestProperty(entry.getKey(), entry.getValue()); - setupDefaultHeaders(url.getHost()) + setupDefaultHeaders(context.getUrl().getHost()) .forEach(connection::setRequestProperty); connection.connect(); @@ -117,56 +130,27 @@ public static HTTPResponse request(@NotNull RequestContext context) HashMap serverHeaders = connection.getHeaderFields().entrySet().stream().parallel() .map(stringListEntry -> new AbstractMap.SimpleEntry<>( - stringListEntry.getKey() == null ? null: stringListEntry.getKey().toLowerCase(), + stringListEntry.getKey().toLowerCase(), String.join(" ", stringListEntry.getValue()) )) .collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll); - String protocol = "HTTP"; - String protocolVersion = "1.1"; - - if (serverHeaders.containsKey(null)) - { - String[] protocolAndStatus = StringUtils.split(serverHeaders.get(null), " "); - if (protocolAndStatus.length > 1) - { - String[] protocolAndVersion = StringUtils.split(protocolAndStatus[0], "/"); - if (protocolAndVersion.length > 0) - protocol = protocolAndVersion[0]; - if (protocolAndVersion.length > 1) - protocolVersion = protocolAndVersion[1]; - } - - serverHeaders.remove(null); - } - - HTTPResponse.RequestStatus status = HTTPResponse.RequestStatus.OK; - if (responseCode >= 500) - status = HTTPResponse.RequestStatus.SERVER_ERROR; - else if (responseCode >= 400) - status = HTTPResponse.RequestStatus.CLIENT_ERROR; - - HTTPResponse response = new HTTPResponse(status, - context, protocol, protocolVersion, responseCode, serverHeaders, - connection.getInputStream() + HTTPResponse response = new HTTPResponse(HTTPResponse.RequestStatus.OK, + context, responseCode, serverHeaders, connection.getInputStream() ); if (context.isFollowRedirects()) - return doRedirect(response, 0); + doRedirect(response, 0); return response; } - catch (MalformedURLException ex) - { - return HTTPResponse.error(context, HTTPResponse.RequestStatus.URL_MALFORMED); - } catch (UnknownHostException ex) { - return HTTPResponse.error(context, HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST); + return new HTTPResponse(HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST, context, 0, null, null); } catch (IOException ex) { - return HTTPResponse.error(context, HTTPResponse.RequestStatus.IO_EXCEPTION_OCCURRED); + return new HTTPResponse(HTTPResponse.RequestStatus.IO_EXCEPTION_OCCURRED, context, 0, null, null); } } @@ -180,7 +164,7 @@ else if (responseCode >= 400) * @return The downloaded file size or -1 if the download failed. * @throws IOException If the download failed */ - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, @NotNull Path path, @Nullable Consumer onProgress) throws IOException { try (HTTPResponse response = request(RequestContext.builder() @@ -232,7 +216,7 @@ else if (response.getInputStream() == null) } } - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, @NotNull Path path) throws IOException { return downloadFile(method, url, path, null); From 74be47fcbeb013d60d4efdaf71c69c82bf4707ed Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 16 Apr 2022 20:01:56 +0900 Subject: [PATCH 084/745] refactor: Change parameter URL to String --- .../utils/http/HTTPResponse.java | 3 +- .../utils/http/RequestContext.java | 3 +- .../utils/http/Requests.java | 46 ++++++++----------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 64188385..43913357 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -102,6 +102,7 @@ public enum RequestStatus REDIRECT_LOCATION_MALFORMED, REDIRECT_LIMIT_EXCEED, UNABLE_TO_RESOLVE_HOST, - IO_EXCEPTION_OCCURRED + IO_EXCEPTION_OCCURRED, + URL_MALFORMED } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java index f4fdcd9f..a4ae9415 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java @@ -4,14 +4,13 @@ import lombok.Singular; import lombok.Value; -import java.net.URL; import java.util.Map; @Value @Builder public class RequestContext { - URL url; + String url; @Builder.Default RequestMethod method = RequestMethod.GET; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 5dfc83a6..1804f9e3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -45,28 +45,17 @@ private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) request, response.getStatusCode(), response.getHeaders(), null ); - try - { - URL newURL = new URL(location); - - HTTPResponse newResponse = request(RequestContext.builder() - .cacheable(request.isCacheable()) - .method(request.getMethod()) - .extraHeaders(request.getExtraHeaders()) - .followRedirects(false) - .timeout(request.getTimeout()) - .body(request.getBody()) - .url(newURL) - .build()); - - return doRedirect(newResponse, redirectCount + 1); - } - catch (MalformedURLException ex) - { - return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, - response.getRequest(), response.getStatusCode(), response.getHeaders(), null - ); - } + HTTPResponse newResponse = request(RequestContext.builder() + .cacheable(request.isCacheable()) + .method(request.getMethod()) + .extraHeaders(request.getExtraHeaders()) + .followRedirects(false) + .timeout(request.getTimeout()) + .body(request.getBody()) + .url(location) + .build()); + + return doRedirect(newResponse, redirectCount + 1); } private static Map setupDefaultHeaders(@NotNull String host) @@ -101,7 +90,8 @@ public static HTTPResponse request(@NotNull RequestContext context) try { - HttpURLConnection connection = (HttpURLConnection) context.getUrl().openConnection(); + URL url = new URL(context.getUrl()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(context.getMethod().name()); connection.setDoOutput(context.getBody() != null); @@ -115,7 +105,7 @@ public static HTTPResponse request(@NotNull RequestContext context) for (Map.Entry entry : context.getExtraHeaders().entrySet()) connection.setRequestProperty(entry.getKey(), entry.getValue()); - setupDefaultHeaders(context.getUrl().getHost()) + setupDefaultHeaders(url.getHost()) .forEach(connection::setRequestProperty); connection.connect(); @@ -144,6 +134,10 @@ public static HTTPResponse request(@NotNull RequestContext context) return response; } + catch (MalformedURLException ex) + { + return new HTTPResponse(HTTPResponse.RequestStatus.URL_MALFORMED, context, 0, null, null); + } catch (UnknownHostException ex) { return new HTTPResponse(HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST, context, 0, null, null); @@ -164,7 +158,7 @@ public static HTTPResponse request(@NotNull RequestContext context) * @return The downloaded file size or -1 if the download failed. * @throws IOException If the download failed */ - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, @NotNull Path path, @Nullable Consumer onProgress) throws IOException { try (HTTPResponse response = request(RequestContext.builder() @@ -216,7 +210,7 @@ else if (response.getInputStream() == null) } } - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull URL url, + public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, @NotNull Path path) throws IOException { return downloadFile(method, url, path, null); From 9665dbfe9893e8dd7aa1d4cbb8756b0e57fc68c4 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 14:14:02 +0900 Subject: [PATCH 085/745] refactor: change response of requests --- .../utils/http/HTTPResponse.java | 5 +++++ .../teamkunpluginmanager/utils/http/Requests.java | 14 +++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 43913357..93052ea1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -96,6 +96,11 @@ public boolean isOK() return statusCode == 200; } + public static HTTPResponse error(@NotNull RequestContext request, @NotNull RequestStatus status) + { + return new HTTPResponse(status, request, -1, null, null); + } + public enum RequestStatus { OK, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 1804f9e3..b3db0540 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -36,14 +36,10 @@ private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) String location = response.getHeader("Location"); if (location == null) - return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED, - request, response.getStatusCode(), response.getHeaders(), null - ); + return HTTPResponse.error(request, HTTPResponse.RequestStatus.REDIRECT_LOCATION_MALFORMED); if (redirectCount > REDIRECT_LIMIT) - return new HTTPResponse(HTTPResponse.RequestStatus.REDIRECT_LIMIT_EXCEED, - request, response.getStatusCode(), response.getHeaders(), null - ); + return HTTPResponse.error(request, HTTPResponse.RequestStatus.REDIRECT_LIMIT_EXCEED); HTTPResponse newResponse = request(RequestContext.builder() .cacheable(request.isCacheable()) @@ -136,15 +132,15 @@ public static HTTPResponse request(@NotNull RequestContext context) } catch (MalformedURLException ex) { - return new HTTPResponse(HTTPResponse.RequestStatus.URL_MALFORMED, context, 0, null, null); + return HTTPResponse.error(context, HTTPResponse.RequestStatus.URL_MALFORMED); } catch (UnknownHostException ex) { - return new HTTPResponse(HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST, context, 0, null, null); + return HTTPResponse.error(context, HTTPResponse.RequestStatus.UNABLE_TO_RESOLVE_HOST); } catch (IOException ex) { - return new HTTPResponse(HTTPResponse.RequestStatus.IO_EXCEPTION_OCCURRED, context, 0, null, null); + return HTTPResponse.error(context, HTTPResponse.RequestStatus.IO_EXCEPTION_OCCURRED); } } From feb0f1c21eb6887baa8eeabb68a419b8e1ba0835 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 15:45:49 +0900 Subject: [PATCH 086/745] feat: Header handling --- .../utils/http/HTTPResponse.java | 5 +++- .../utils/http/Requests.java | 23 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 93052ea1..472c42ab 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -16,6 +16,9 @@ public class HTTPResponse implements AutoCloseable RequestStatus status; RequestContext request; + String serverProtocol; + String protocolVersion; + int statusCode; HashMap headers; @@ -98,7 +101,7 @@ public boolean isOK() public static HTTPResponse error(@NotNull RequestContext request, @NotNull RequestStatus status) { - return new HTTPResponse(status, request, -1, null, null); + return new HTTPResponse(status, request, null, null, -1, null, null); } public enum RequestStatus diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index b3db0540..57aeb1a4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -116,13 +116,32 @@ public static HTTPResponse request(@NotNull RequestContext context) HashMap serverHeaders = connection.getHeaderFields().entrySet().stream().parallel() .map(stringListEntry -> new AbstractMap.SimpleEntry<>( - stringListEntry.getKey().toLowerCase(), + stringListEntry.getKey() == null ? null: stringListEntry.getKey().toLowerCase(), String.join(" ", stringListEntry.getValue()) )) .collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll); + String protocol = "HTTP"; + String protocolVersion = "1.1"; + + if (serverHeaders.containsKey(null)) + { + String[] protocolAndStatus = StringUtils.split(serverHeaders.get(null), " "); + if (protocolAndStatus.length > 1) + { + String[] protocolAndVersion = StringUtils.split(protocolAndStatus[0], "/"); + if (protocolAndVersion.length > 0) + protocol = protocolAndVersion[0]; + if (protocolAndVersion.length > 1) + protocolVersion = protocolAndVersion[1]; + } + + serverHeaders.remove(null); + } + HTTPResponse response = new HTTPResponse(HTTPResponse.RequestStatus.OK, - context, responseCode, serverHeaders, connection.getInputStream() + context, protocol, protocolVersion, responseCode, serverHeaders, + connection.getInputStream() ); if (context.isFollowRedirects()) From 66f38163128a4c17d3321bf69b6f75b370868a9a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 17:00:30 +0900 Subject: [PATCH 087/745] fix: Redirect options --- .../kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 57aeb1a4..2e9b195b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -59,7 +59,7 @@ private static Map setupDefaultHeaders(@NotNull String host) HashMap headers = new HashMap<>(); headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + - TeamKunPluginManager.getPlugin().getDescription().getVersion()); + "1"); if (host.equalsIgnoreCase("github.com") || StringUtils.endsWithIgnoreCase(host, ".github.com") || @@ -89,6 +89,7 @@ public static HTTPResponse request(@NotNull RequestContext context) URL url = new URL(context.getUrl()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setInstanceFollowRedirects(false); connection.setRequestMethod(context.getMethod().name()); connection.setDoOutput(context.getBody() != null); connection.setDoInput(true); @@ -145,7 +146,7 @@ public static HTTPResponse request(@NotNull RequestContext context) ); if (context.isFollowRedirects()) - doRedirect(response, 0); + return doRedirect(response, 0); return response; } From 343a3ba04e67b2949c97314cca034237cadf8351 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 18:45:40 +0900 Subject: [PATCH 088/745] feat: SERVER_ERROR and CLIENT_ERROR --- .../lab/teamkunpluginmanager/utils/http/HTTPResponse.java | 3 +++ .../lab/teamkunpluginmanager/utils/http/Requests.java | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 472c42ab..13a340c6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -107,6 +107,9 @@ public static HTTPResponse error(@NotNull RequestContext request, @NotNull Reque public enum RequestStatus { OK, + SERVER_ERROR, + CLIENT_ERROR, + REDIRECT_LOCATION_MALFORMED, REDIRECT_LIMIT_EXCEED, UNABLE_TO_RESOLVE_HOST, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 2e9b195b..579e33ef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -140,7 +140,13 @@ public static HTTPResponse request(@NotNull RequestContext context) serverHeaders.remove(null); } - HTTPResponse response = new HTTPResponse(HTTPResponse.RequestStatus.OK, + HTTPResponse.RequestStatus status = HTTPResponse.RequestStatus.OK; + if (responseCode >= 500) + status = HTTPResponse.RequestStatus.SERVER_ERROR; + else if (responseCode >= 400) + status = HTTPResponse.RequestStatus.CLIENT_ERROR; + + HTTPResponse response = new HTTPResponse(status, context, protocol, protocolVersion, responseCode, serverHeaders, connection.getInputStream() ); From 4cf3d9b4e2a360440f187d9f0f9f62884e98e450 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 17 Apr 2022 22:57:42 +0900 Subject: [PATCH 089/745] feat: Cache with body --- .../utils/http/HTTPResponse.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 13a340c6..e8c770e2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -2,7 +2,9 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; -import lombok.Value; +import lombok.AccessLevel; +import lombok.Data; +import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,26 +12,32 @@ import java.io.InputStream; import java.util.HashMap; -@Value +@Data public class HTTPResponse implements AutoCloseable { - RequestStatus status; - RequestContext request; + private final RequestStatus status; + private final RequestContext request; - String serverProtocol; - String protocolVersion; + private final String serverProtocol; + private final String protocolVersion; - int statusCode; + private final int statusCode; - HashMap headers; + private final HashMap headers; @Nullable - InputStream inputStream; + private final InputStream inputStream; + + @Getter(AccessLevel.PRIVATE) + private String bodyCache = null; public String getAsString() { if (inputStream == null) return null; + else if (bodyCache != null) + return bodyCache; + StringBuilder sb = new StringBuilder(); byte[] buffer = new byte[1024]; @@ -44,7 +52,8 @@ public String getAsString() e.printStackTrace(); } - return sb.toString(); + bodyCache = sb.toString(); + return bodyCache; } public JsonElement getAsJson() From a7582c6f4712c6f7220e507a68ba163a8b241b9b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 25 Apr 2022 18:42:30 +0900 Subject: [PATCH 090/745] fix: Invalid else-if --- .../kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 579e33ef..46ea3bec 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -190,9 +190,7 @@ public static long downloadFile(@NotNull RequestContext.RequestMethod method, @N .build()); OutputStream output = Files.newOutputStream(path)) { - if (response.getStatus() != HTTPResponse.RequestStatus.OK) - throw new IOException("Download failed: " + response.getStatus()); - else if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) + if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) throw new IOException("HTTP error " + response.getStatusCode()); else if (response.getInputStream() == null) throw new IOException("No response body was returned"); From 8fa34f31a3abdac157fad467ce2f5276235ef7d1 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:12:47 +0900 Subject: [PATCH 091/745] fix: Download size asserting --- .../kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 46ea3bec..cafb42c9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -196,8 +196,12 @@ else if (response.getInputStream() == null) throw new IOException("No response body was returned"); String contentLength = response.getHeader("Content-Length"); + long size = contentLength != null ? Long.parseLong(contentLength): -1; + if (size > 0) + throw new IOException("No response body was returned"); + byte[] buffer = new byte[1024]; int read; From 294b30b9aecdd7e41102fe256043b85faed18aee Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 25 Apr 2022 22:05:02 +0900 Subject: [PATCH 092/745] refactor: Extract DownloadProgress to outer. --- .../utils/http/DownloadProgress.java | 12 ++++++++++++ .../teamkunpluginmanager/utils/http/Requests.java | 9 --------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java new file mode 100644 index 00000000..033ef0c1 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.http; + +import lombok.Value; + +@Value +public class DownloadProgress +{ + long totalSize; + long downloaded; + + double percentage; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index cafb42c9..5c8e4107 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -2,7 +2,6 @@ import lombok.Getter; import lombok.Setter; -import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; @@ -240,12 +239,4 @@ public static long downloadFile(@NotNull RequestContext.RequestMethod method, @N return downloadFile(method, url, path, null); } - @Value - public static class DownloadProgress - { - long totalSize; - long downloaded; - - double percentage; - } } From 4cd672f7384b1a008a958a069ac1d459551c0254 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 25 Apr 2022 22:19:19 +0900 Subject: [PATCH 093/745] refactor: Extract RequestMethod to outer. --- .../commands/CommandRegister.java | 5 +- .../plugin/Installer.java | 487 +++++++----------- .../utils/http/RequestContext.java | 10 - .../utils/http/RequestMethod.java | 12 + .../utils/http/Requests.java | 4 +- 5 files changed, 198 insertions(+), 320 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 3359a308..071078ce 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -10,6 +10,7 @@ import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import net.kyori.adventure.text.TextComponent; import org.bukkit.ChatColor; @@ -58,7 +59,7 @@ private static void performAction(Terminal terminal) terminal.info(ChatColor.LIGHT_PURPLE + "サーバと通信しています..."); HTTPResponse response = Requests.request(RequestContext.builder() - .method(RequestContext.RequestMethod.GET) + .method(RequestMethod.GET) .url(OAUTH_PREPARE_URL) .build()); @@ -103,7 +104,7 @@ private static Runner.GeneralExceptableRunner polling(Terminal terminal, String { return () -> { HTTPResponse httpResponse = Requests.request(RequestContext.builder() - .method(RequestContext.RequestMethod.POST) + .method(RequestMethod.POST) .url(OAUTH_ACCESS_URL + device_code) .build()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index d18ad9b7..cc9b2e6d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -5,7 +5,8 @@ import com.google.gson.JsonObject; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; @@ -16,44 +17,33 @@ import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import javax.annotation.Nonnull; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; -import java.util.Set; -import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -import java.util.stream.IntStream; @SuppressWarnings("unused") public class Installer @@ -62,23 +52,20 @@ public class Installer /** * アンインストールをする * - * @param sender 発行者(Nullable) - * @param name 対象プラグ - * @param force 強制削除かどうか + * @param terminal 発行者(Nullable) + * @param name 対象プラグ + * @param force 強制削除かどうか */ - public static void unInstall(CommandSender sender, String name, boolean force) + public static void unInstall(@NotNull Terminal terminal, @NotNull String name, boolean force) { - //senderがnullだった場合はダミーと差し替え - if (sender == null) - sender = dummySender(); //ぬるぽ抑制 - sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); + terminal.writeLine(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); DependencyTree.Info info = DependencyTree.getInfo(name, false); //プラグインが見つからない場合はreturn if (info == null) { - sender.sendMessage(ChatColor.RED + "E: プラグインが見つかりませんでした。"); + terminal.error("プラグインが見つかりませんでした。"); return; } @@ -88,7 +75,7 @@ public static void unInstall(CommandSender sender, String name, boolean force) //アンインストール対象が存在するかチェック if (!PluginUtil.isPluginLoaded(info.name)) { - sender.sendMessage(ChatColor.RED + "E: プラグインが見つかりませんでした。"); + terminal.error("プラグインが見つかりませんでした。"); return; } @@ -96,9 +83,9 @@ public static void unInstall(CommandSender sender, String name, boolean force) if (TeamKunPluginManager.getPlugin().getPluginConfig(). getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name))) { - sender.sendMessage(ChatColor.YELLOW + "W: このプラグインは保護されています。\n" + + terminal.warn("このプラグインは保護されています。\n" + ChatColor.YELLOW + " 保護されているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - sender.sendMessage(ChatColor.RED + "E: システムが保護されました。"); + terminal.error("システムが保護されました。"); return; } @@ -106,19 +93,18 @@ public static void unInstall(CommandSender sender, String name, boolean force) // 強制アンインストールである場合は無視 if (!info.rdepends.isEmpty() && !force) { - sender.sendMessage(ChatColor.YELLOW + "W: このプラグインは以下のプラグインの依存関係です。"); - sender.sendMessage(ChatColor.BLUE + info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.joining(" "))); - sender.sendMessage(ChatColor.YELLOW + " 依存関係になっているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - sender.sendMessage(ChatColor.RED + "E: システムが保護されました。"); + terminal.warn("このプラグインは以下のプラグインの依存関係です。"); + terminal.writeLine(ChatColor.BLUE + info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.joining(" "))); + terminal.writeLine(ChatColor.YELLOW + " 依存関係になっているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); + terminal.error("システムが保護されました。"); return; } - sender.sendMessage(ChatColor.LIGHT_PURPLE + "プラグインを削除中..."); + terminal.writeLine(ChatColor.LIGHT_PURPLE + "プラグインを削除中..."); //プラグインをアンロード PluginUtil.unload(plugin); - CommandSender finalSender = sender; //非同期実行 Runner.runLaterAsync(() -> { //プラグインのファイルを取得 @@ -129,20 +115,20 @@ public static void unInstall(CommandSender sender, String name, boolean force) //依存関係ツリーをワイプする DependencyTree.wipePlugin(plugin); - finalSender.sendMessage(ChatColor.RED + "- " + plugin.getName() + ":" + plugin.getDescription().getVersion()); + terminal.writeLine(ChatColor.RED + "- " + plugin.getName() + ":" + plugin.getDescription().getVersion()); // エラーが有っる場合は表示 String statusError = Messages.getErrorMessage(); if (!statusError.isEmpty()) - finalSender.sendMessage(statusError); + terminal.writeLine(statusError); // 削除できるプラグイン(使われない依存関係等)があれば通知 String autoRemovable = Messages.getUnInstallableMessage(); if (!autoRemovable.isEmpty()) - finalSender.sendMessage(autoRemovable); - finalSender.sendMessage(Messages.getStatusMessage(0, 1, 0)); - finalSender.sendMessage(ChatColor.GREEN + "S: " + plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); + terminal.writeLine(autoRemovable); + terminal.writeLine(Messages.getStatusMessage(0, 1, 0)); + terminal.success(plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); }, 20L); } @@ -172,7 +158,7 @@ private static String error(String json) /** * URlからぶちこむ! * - * @param sender 結果を表示する対象の人 + * @param terminal 結果を表示する対象の人 * @param url URL!!! * @param ignoreInstall インストールを除外するかどうか * @param withoutResolveDepends 依存関係解決をしない @@ -180,16 +166,10 @@ private static String error(String json) * @param withoutDownload ダウンロードしない * @return ファイル名, プラグイン名 */ - public static InstallResult install(CommandSender sender, String url, boolean ignoreInstall, boolean withoutResolveDepends, boolean withoutRemove, boolean withoutDownload) + public static InstallResult install(@NotNull Terminal terminal, String url, boolean ignoreInstall, boolean withoutResolveDepends, boolean withoutRemove, boolean withoutDownload) { - //senderがnullだった場合はダミーと差し替え - if (sender == null) - sender = dummySender(); //ぬるぽ抑制 - //jarのURL String jarURL = url; - //finalしないと非同期できない。 - CommandSender finalSender = sender; //追加されたプラグインとステータス。 ArrayList added = new ArrayList<>(); @@ -209,10 +189,9 @@ public static InstallResult install(CommandSender sender, String url, boolean ig { ErrorResult errorResult = (ErrorResult) resolveResult; - sender.sendMessage(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + - " リゾルバ:" + errorResult.getSource().getName()); + terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } else if (resolveResult instanceof MultiResult) @@ -221,17 +200,17 @@ else if (resolveResult instanceof MultiResult) try { - if (sender.getName().equals("DUMMY1145141919810931")) // TODO: なんやねんこのクソコード + if (terminal.isQuiet()) { resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); if (resolveResult instanceof ErrorResult) { ErrorResult errorResult = (ErrorResult) resolveResult; - sender.sendMessage(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } else if (resolveResult instanceof SuccessResult) @@ -241,15 +220,15 @@ else if (resolveResult instanceof SuccessResult) } else { - List> multi = Arrays.stream(multiResult.getResults()) - .filter(result -> result instanceof SuccessResult) - .map(result -> { - SuccessResult successResult = (SuccessResult) result; - return new Pair<>(successResult.getVersion(), successResult.getDownloadUrl()); - }).collect(Collectors.toList()); - - depend_askToCommandSender(sender, multi, ignoreInstall, withoutResolveDepends, withoutRemove); - return new InstallResult(add, remove, modify, false); + SuccessResult result = dependAskToTerminal(terminal, multiResult); + + if (result == null) + { + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); + return new InstallResult(add, remove, modify, false); + } + + jarURL = result.getDownloadUrl(); } } catch (IllegalArgumentException ignored) @@ -260,73 +239,85 @@ else if (resolveResult instanceof SuccessResult) jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); } - Pair downloadResult; + long downloadResult; + Path downloadPath; //ダウンロード if (!withoutDownload) { - finalSender.sendMessage(ChatColor.GOLD + "ファイルのダウンロード中..."); + terminal.writeLine(ChatColor.GOLD + "ファイルのダウンロード中..."); //ダウンロード開始時間を控えておく long startTime = System.currentTimeMillis(); //ファイルをダウンロード - downloadResult = URLUtils.downloadFile(jarURL); - if (downloadResult.getLeft() == null && downloadResult.getRight().startsWith("ERROR ")) + try + { + downloadPath = Paths.get("plugins", jarURL.substring(url.lastIndexOf("/") + 1)); + downloadResult = Requests.downloadFile( + RequestMethod.GET, + jarURL, + downloadPath + ); + } + catch (IOException e) { - finalSender.sendMessage(ChatColor.YELLOW + "W: " + downloadResult.getRight().substring(6)); - finalSender.sendMessage(ChatColor.RED + "E: ファイルのダウンロードに失敗しました。"); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + terminal.error("ファイルのダウンロードに失敗しました:" + e.getMessage()); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } - finalSender.sendMessage(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadResult.getRight())); + + terminal.writeLine(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadPath.getFileName().toString())); add++; - finalSender.sendMessage(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())) + terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())) .subtract(new BigDecimal(String.valueOf(startTime))) .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN) + "秒で取得しました。"); } else //ダウンロードしない - downloadResult = new Pair<>(true, url); + { + downloadResult = -1; + downloadPath = Paths.get(url); + } - finalSender.sendMessage(ChatColor.LIGHT_PURPLE + "情報を読み込み中..."); + terminal.writeLine(ChatColor.LIGHT_PURPLE + "情報を読み込み中..."); //plugin.yml PluginDescriptionFile description; try { //plugin.ymlを読み取り - description = PluginUtil.loadDescription(new File("plugins/" + downloadResult.getRight())); + description = PluginUtil.loadDescription(downloadPath.toFile()); } catch (FileNotFoundException e) //ファイルが見つからない場合はreturn { - finalSender.sendMessage(ChatColor.RED + "E: ファイルが見つかりませんでした。"); + terminal.error("ファイルが見つかりませんでした。"); if (!withoutRemove) - delete(finalSender, new File("plugins/" + downloadResult.getRight())); + delete(terminal, downloadPath.toFile()); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } catch (IOException | InvalidDescriptionException e) //plugin.ymlがおかしい場合はreturn { - finalSender.sendMessage(ChatColor.RED + "E: 情報を読み込めませんでした。"); + terminal.error("情報を読み込めませんでした。"); if (!withoutRemove) - delete(finalSender, new File("plugins/" + downloadResult.getRight())); + delete(terminal, downloadPath.toFile()); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } //保護されているプラグインの場合はインスコ・変換せずreturn if (TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) { - sender.sendMessage(ChatColor.RED + "E: このプラグインは保護されています。"); + terminal.error("このプラグインは保護されています。"); add--; if (!withoutRemove) - delete(finalSender, new File("plugins/" + downloadResult.getRight())); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); + delete(terminal, downloadPath.toFile()); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } @@ -343,10 +334,10 @@ else if (resolveResult instanceof SuccessResult) //ファイルを移動 //114514.jar => YJSNPIPlugin-1.0.jar FileUtils.moveFile( - new File("plugins/" + downloadResult.getRight()), + downloadPath.toFile(), new File("plugins/" + fileName) ); - downloadResult = new Pair<>(false, fileName); + downloadPath = Paths.get("plugins/" + fileName); } catch (IOException e) { @@ -364,7 +355,7 @@ else if (resolveResult instanceof SuccessResult) { modify++; add--; - finalSender.sendMessage(Messages.getModifyMessage( + terminal.writeLine(Messages.getModifyMessage( Messages.ModifyType.MODIFY, plugin.getName() + ":" + plugin.getDescription().getVersion() + " => " + description.getName() + ":" + description.getVersion() @@ -376,45 +367,47 @@ else if (resolveResult instanceof SuccessResult) Runner.runLater(() -> { //削除する場合は削除 if (!withoutRemove) - delete(finalSender, PluginUtil.getFile(plugin)); + delete(terminal, PluginUtil.getFile(plugin)); }, 10L); } else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが変わらない(もしくは低い)。 { add--; - finalSender.sendMessage(ChatColor.YELLOW + "W: 既に同じプラグインが存在します。"); + terminal.warn("既に同じプラグインが存在します。"); //それでもインストールするかどうかを尋 - if (!dummySender().equals(sender)) + if (terminal.isPlayer()) // TODO: Remove this if statement { //ファイルの比較を行う - finalSender.sendMessage(getDiffMessage(PluginUtil.getFile(plugin), false)); - finalSender.sendMessage(getDiffMessage(new File("plugins/" + downloadResult.getRight()), true)); - finalSender.sendMessage("\n"); + terminal.writeLine(getDiffMessage(PluginUtil.getFile(plugin), false)); + terminal.writeLine(getDiffMessage(downloadPath.toFile(), true)); + terminal.writeLine("\n"); //ファイナルにコピーする。 - String fileName = downloadResult.getRight(); + String fileName = downloadPath.getFileName().toString(); try { - QuestionResult questionResult = Terminals.of(sender).getInput() + QuestionResult questionResult = terminal.getInput() .showQuestion("プラグインを置換しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) .waitAndGetResult(); if (questionResult.test(QuestionAttribute.CANCELLABLE)) { if (!withoutRemove && new File("plugins/" + fileName).exists()) - delete(finalSender, new File("plugins/" + fileName)); + delete(terminal, new File("plugins/" + fileName)); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); - finalSender.sendMessage(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); + terminal.success(description.getFullName() + " を正常にインストールしました。"); } else { - unInstall(null, description.getName(), true); - InstallResult ir = install(finalSender, fileName, false, false, false, true); - finalSender.sendMessage(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); + unInstall(terminal.quiet(), description.getName(), true); + InstallResult ir = install(terminal, fileName, false, false, false, true); + terminal.writeLine(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); } - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } catch (InterruptedException e) @@ -424,16 +417,18 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが } //削除 - if (!withoutRemove && new File("plugins/" + downloadResult.getRight()).exists()) - delete(finalSender, new File("plugins/" + downloadResult.getRight())); + if (!withoutRemove && downloadPath.toFile().exists()) + delete(terminal, downloadPath.toFile()); - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); - finalSender.sendMessage(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); + terminal.success(description.getFullName() + " を正常にインストールしました。"); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } - added.add(new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true)); + added.add(new InstallResult(downloadPath.getFileName().toString(), description.getName(), add, remove, modify, true)); //==================依存関係解決処理 ここから================== @@ -458,7 +453,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが //最初の依存関係解決の場合 if (dependFirst) { - finalSender.sendMessage(ChatColor.GOLD + "依存関係をダウンロード中..."); + terminal.writeLine(ChatColor.GOLD + "依存関係をダウンロード中..."); dependFirst = false; } @@ -471,9 +466,9 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが { ErrorResult errorResult = (ErrorResult) resolveResult; - sender.sendMessage(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); - finalSender.sendMessage(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); + terminal.warn(dependency + ": " + dependency.substring(5)); failedResolve.add(dependency); continue; } @@ -484,7 +479,7 @@ else if (resolveResult instanceof MultiResult) resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); if (resolveResult instanceof ErrorResult) { - finalSender.sendMessage(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); + terminal.warn(dependency + ": " + dependency.substring(5)); failedResolve.add(dependency); continue; } @@ -499,7 +494,7 @@ else if (resolveResult instanceof SuccessResult) throw new IllegalStateException("resolveResultが不正です:プラグイン作成者に報告してください。"); //依存関係のインストール - InstallResult dependResolve = Installer.install(null, dependUrl, true, false, true, false); + InstallResult dependResolve = Installer.install(terminal.quiet(), dependUrl, true, false, true, false); //ファイルの名前がない場合は失敗としてマーク if (dependResolve.getFileName().isEmpty()) { @@ -508,11 +503,11 @@ else if (resolveResult instanceof SuccessResult) } if (Bukkit.getPluginManager().getPlugin(dependUrl.substring(dependUrl.lastIndexOf("/"))) == null) - finalSender.sendMessage(ChatColor.GREEN + "+ " + dependUrl.substring(dependUrl.lastIndexOf("/") + 1)); + terminal.writeLine(ChatColor.GREEN + "+ " + dependUrl.substring(dependUrl.lastIndexOf("/") + 1)); else { Plugin dependPlugin = Bukkit.getPluginManager().getPlugin(dependUrl.substring(dependUrl.lastIndexOf("/"))); - finalSender.sendMessage(ChatColor.GREEN + "+ " + dependPlugin.getName() + ":" + dependPlugin.getDescription().getVersion()); + terminal.writeLine(ChatColor.GREEN + "+ " + dependPlugin.getName() + ":" + dependPlugin.getDescription().getVersion()); } added.add(dependResolve); add++; @@ -521,19 +516,21 @@ else if (resolveResult instanceof SuccessResult) //依存関係が1つでも読まれた場合はかかった時間を表示 if (!dependFirst) - finalSender.sendMessage(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_DOWN) + "秒で取得しました。"); + terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_DOWN) + "秒で取得しました。"); //結果を表示しないモードで依存関係エラーが発生した場合はreturn - if (sender.equals(dummySender()) && !failedResolve.isEmpty()) + if (!terminal.isPlayer() && !failedResolve.isEmpty()) return new InstallResult(add, remove, modify, true); //依存関係エラーが発生した場合は表示 if (!failedResolve.isEmpty()) { - finalSender.sendMessage(Messages.getStatusMessage(add, remove, modify)); - finalSender.sendMessage(ChatColor.YELLOW + "W: " + description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); - finalSender.sendMessage(ChatColor.RED + String.join(", ", failedResolve)); - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); + terminal.warn(description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); + terminal.writeLine(ChatColor.RED + String.join(", ", failedResolve)); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } AtomicBoolean success = new AtomicBoolean(true); @@ -551,11 +548,11 @@ else if (resolveResult instanceof SuccessResult) //プラグインが既に読まれてい場合はreturn if (PluginUtil.isPluginLoaded(description.getName())) { - finalSender.sendMessage(ChatColor.RED + "E: Bukkitのインジェクションに失敗しました。"); + terminal.error("Bukkitのインジェクションに失敗しました。"); //削除する場合は削除 if (!withoutRemove) - delete(finalSender, new File("plugins/" + f.getFileName())); + delete(terminal, new File("plugins/" + f.getFileName())); //プラグインをアンロード PluginUtil.unload(plugin); @@ -574,7 +571,7 @@ else if (resolveResult instanceof SuccessResult) { //削除する場合は削除 if (!withoutRemove) - delete(finalSender, new File("plugins/" + f.getFileName())); + delete(terminal, new File("plugins/" + f.getFileName())); e.printStackTrace(); //失敗フラグを建てる success.set(false); @@ -584,7 +581,7 @@ else if (resolveResult instanceof SuccessResult) //失敗フラグが立っていた場合は表示 if (!success.get()) - finalSender.sendMessage(ChatColor.RED + "E: プラグインの読み込みに失敗しました。"); + terminal.error("プラグインの読み込みに失敗しました。"); int finalAdd1 = add; int finalModify1 = modify; @@ -597,18 +594,20 @@ public void run() //エラーが発生した場合 String statusError = Messages.getErrorMessage(); if (!statusError.isEmpty()) - finalSender.sendMessage(statusError); + terminal.writeLine(statusError); // 削除できるプラグイン(使われない依存関係等)があれば通知 String autoRemovable = Messages.getUnInstallableMessage(); if (!autoRemovable.isEmpty()) - finalSender.sendMessage(autoRemovable); + terminal.writeLine(autoRemovable); - finalSender.sendMessage(Messages.getStatusMessage(finalAdd1, remove, finalModify1)); - finalSender.sendMessage(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); + terminal.writeLine(Messages.getStatusMessage(finalAdd1, remove, finalModify1)); + terminal.success(description.getFullName() + " を正常にインストールしました。"); /*} }.runTaskLater(TeamKunPluginManager.plugin, 10L);*/ - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } private static String getDiffMessage(File f, boolean isNew) @@ -654,7 +653,7 @@ public static String[] getRemovableDataDirs() } } - public static void delete(CommandSender sender, File f) + public static void delete(Terminal terminal, File f) { try { @@ -662,60 +661,63 @@ public static void delete(CommandSender sender, File f) } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "E: ファイルの削除に失敗しました: " + f.getName()); + terminal.error("ファイルの削除に失敗しました: " + f.getName()); } } - private static void depend_askToCommandSender(CommandSender sender, List> jar, boolean ignoreInstall, boolean withoutResolveDepends, boolean withoutRemove) + private static HashMap buildChoicesRecursive(int count, MultiResult result) { - UUID uuid = null; - if (sender instanceof Player) - uuid = ((Player) sender).getUniqueId(); - - sender.sendMessage(ChatColor.YELLOW + "W: リソースが複数見つかりました。インストールするリソースを選択するか、キャンセルを行ってください。"); - AtomicInteger integer = new AtomicInteger(0); - jar.forEach(pair -> { - int index = integer.incrementAndGet(); - sender.sendMessage(new ComponentBuilder(ChatColor.LIGHT_PURPLE + "- [" + index + "] " + ChatColor.GREEN + pair.getLeft()) - .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/kpm i " + pair.getRight())) - .event(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder(ChatColor.GREEN + "クリックしてこのリリースをインストール").create() - )) - .create() - ); - }); - sender.sendMessage(new ComponentBuilder(ChatColor.LIGHT_PURPLE + "- [c] " + ChatColor.RED + "キャンセル") - .event(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder(ChatColor.RED + "クリックしてこのリリースをキャンセル").create() - )) - .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/kpm i $-CF$")) - .create()); - - TeamKunPluginManager.getPlugin().getFunctional().add(uuid, new Say2Functional.FunctionalEntry(StringUtils::equalsIgnoreCase, s -> { - if (s.equalsIgnoreCase("c")) - { - sender.sendMessage(ChatColor.RED + "E: キャンセルされました。"); - return; - } + HashMap choices = new HashMap<>(); - int i = Integer.parseInt(s); - if (i < 1 || i > jar.size() + 1) - { - sender.sendMessage(ChatColor.RED + "リソースは 1 以上、" + (jar.size() + 1) + " 以下である必要があります。"); - sender.sendMessage(ChatColor.RED + "E: キャンセルされました。"); - return; - } + for (ResolveResult resolveResult : result.getResults()) + { + if (resolveResult instanceof SuccessResult) + { + choices.put(count + "." + resolveResult.hashCode(), (SuccessResult) resolveResult); + continue; + } - Pair resource = jar.get(--i); - install(sender, resource.getRight(), ignoreInstall, withoutResolveDepends, withoutRemove, false); + if (resolveResult instanceof MultiResult) + choices.putAll(buildChoicesRecursive(count + 1, (MultiResult) resolveResult)); + } - }, (String[]) ArrayUtils.add(IntStream.range(1, jar.size() + 1).parallel() - .mapToObj(String::valueOf) - .toArray(String[]::new), "c")) - ); + return choices; + } + + private static SuccessResult dependAskToTerminal(Terminal terminal, MultiResult result) + { + terminal.warn("複数のリソースが見つかりました。"); + + Map hashResultMap = buildChoicesRecursive(1, result); + Map hashTextMap = hashResultMap.entrySet().stream() + .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(), entry.getValue().getFileName())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + + QuestionResult questionResult; + + try + { + questionResult = + terminal.getInput().showQuestion("インストールするリリースを選択してください。", + new AttributeChoice(hashTextMap), QuestionAttribute.CANCELLABLE + ) + .waitAndGetResult(); + } + catch (InterruptedException e) + { + terminal.error("処理が中断されました。"); + return null; + } + + if (questionResult.test(QuestionAttribute.CANCELLABLE)) + { + terminal.warn("インストールがキャンセルされました。"); + return null; + } + + return hashResultMap.get(questionResult.getRawAnswer()); } private static String pickPluginJar(List> jar) @@ -848,131 +850,4 @@ public static boolean clean(String name) return false; } } - - public static CommandSender dummySender() - { - return new CommandSender() - { - @Override - public void sendMessage(@NotNull String message) - { - - } - - @Override - public void sendMessage(@Nonnull @NotNull String[] messages) - { - - } - - @Override - public void sendMessage(@Nullable UUID sender, @NotNull String message) - { - - } - - @Override - public void sendMessage(@Nullable UUID sender, @Nonnull @NotNull String[] messages) - { - - } - - @Override - public @NotNull Server getServer() - { - return Bukkit.getServer(); - } - - @Override - public @NotNull String getName() - { - return "DUMMY1145141919810931"; - } - - @Override - public @NotNull Spigot spigot() - { - return null; - } - - @Override - public boolean isPermissionSet(@NotNull String name) - { - return false; - } - - @Override - public boolean isPermissionSet(@NotNull Permission perm) - { - return false; - } - - @Override - public boolean hasPermission(@NotNull String name) - { - return false; - } - - @Override - public boolean hasPermission(@NotNull Permission perm) - { - return false; - } - - @Override - public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) - { - return null; - } - - @Override - public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin) - { - return null; - } - - @Override - public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) - { - return null; - } - - @Override - public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) - { - return null; - } - - @Override - public void removeAttachment(@NotNull PermissionAttachment attachment) - { - - } - - @Override - public void recalculatePermissions() - { - - } - - @Override - public @NotNull Set getEffectivePermissions() - { - return null; - } - - @Override - public boolean isOp() - { - return false; - } - - @Override - public void setOp(boolean value) - { - - } - }; - } - } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java index a4ae9415..e6d8a7f8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java @@ -28,14 +28,4 @@ public class RequestContext @Builder.Default byte[] body = {}; - public enum RequestMethod - { - GET, - POST, - PUT, - DELETE, - HEAD, - OPTIONS, - TRACE - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java new file mode 100644 index 00000000..96d70756 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.http; + +public enum RequestMethod +{ + GET, + POST, + PUT, + DELETE, + HEAD, + OPTIONS, + TRACE +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 5c8e4107..0ef7d2b4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -179,7 +179,7 @@ else if (responseCode >= 400) * @return The downloaded file size or -1 if the download failed. * @throws IOException If the download failed */ - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, + public static long downloadFile(@NotNull RequestMethod method, @NotNull String url, @NotNull Path path, @Nullable Consumer onProgress) throws IOException { try (HTTPResponse response = request(RequestContext.builder() @@ -233,7 +233,7 @@ else if (response.getInputStream() == null) } } - public static long downloadFile(@NotNull RequestContext.RequestMethod method, @NotNull String url, + public static long downloadFile(@NotNull RequestMethod method, @NotNull String url, @NotNull Path path) throws IOException { return downloadFile(method, url, path, null); From b28710dc5301c945200205b5f56b749a7eba0a6f Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 4 Jun 2022 06:31:16 +0900 Subject: [PATCH 094/745] fix: Requests unneeded redirect --- .../kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 0ef7d2b4..75f4055a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -28,7 +28,7 @@ public class Requests private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) { - if (response.getStatus() == HTTPResponse.RequestStatus.OK && !response.isRedirect()) + if (!response.isRedirect()) return response; RequestContext request = response.getRequest(); @@ -147,7 +147,7 @@ else if (responseCode >= 400) HTTPResponse response = new HTTPResponse(status, context, protocol, protocolVersion, responseCode, serverHeaders, - connection.getInputStream() + responseCode >= 400 ? connection.getErrorStream(): connection.getInputStream() ); if (context.isFollowRedirects()) From 6b29b6979a24a759aef09cf44c3e913ae20fad80 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 4 Jun 2022 13:05:25 +0900 Subject: [PATCH 095/745] fix: Unneeded outputs on requests --- .../lab/teamkunpluginmanager/utils/http/RequestContext.java | 2 +- .../kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 4 +--- .../lab/teamkunpluginmanager/result/http/RequestsTest.java | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java index e6d8a7f8..1db67c6e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java @@ -26,6 +26,6 @@ public class RequestContext int timeout = -1; @Builder.Default - byte[] body = {}; + byte[] body = null; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 75f4055a..5812e732 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -58,7 +58,7 @@ private static Map setupDefaultHeaders(@NotNull String host) HashMap headers = new HashMap<>(); headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + - "1"); + TeamKunPluginManager.getPlugin().getDescription().getVersion()); if (host.equalsIgnoreCase("github.com") || StringUtils.endsWithIgnoreCase(host, ".github.com") || @@ -90,8 +90,6 @@ public static HTTPResponse request(@NotNull RequestContext context) connection.setInstanceFollowRedirects(false); connection.setRequestMethod(context.getMethod().name()); - connection.setDoOutput(context.getBody() != null); - connection.setDoInput(true); connection.setUseCaches(false); connection.setConnectTimeout(10000); diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java index e330e849..6c71184b 100644 --- a/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java +++ b/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java @@ -5,8 +5,10 @@ import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; +@Ignore public class RequestsTest { private static final String mockUrl = "https://run.mocky.io/v3/63f730d5-cb39-413e-a56f-37450aea4df0"; From 36ae95e6a013ad48900ccb6425beda0edff6ec8b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 10 Jun 2022 01:00:11 +0900 Subject: [PATCH 096/745] fix: Remove invalid if --- .../net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 5812e732..947fcd15 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -196,8 +196,6 @@ else if (response.getInputStream() == null) long size = contentLength != null ? Long.parseLong(contentLength): -1; - if (size > 0) - throw new IOException("No response body was returned"); byte[] buffer = new byte[1024]; From 77dc7bce3d1a17254a6fcf68155e17047d2c7ae3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 10 Jun 2022 01:08:45 +0900 Subject: [PATCH 097/745] fix: Invalid download consumer arguments --- .../net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 947fcd15..fb906501 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -215,7 +215,7 @@ else if (response.getInputStream() == null) else progress = 0; - onProgress.accept(new DownloadProgress(progress, downloaded, size)); + onProgress.accept(new DownloadProgress(size, downloaded, progress)); } return size; From 650ee95c312b5317e1f9518cc16247fda1658614 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 24 Jun 2022 16:59:13 +0900 Subject: [PATCH 098/745] fix: Merge error --- .../kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java | 2 +- .../lab/teamkunpluginmanager/commands/CommandUninstall.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index d0f79d2a..c323b191 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -44,7 +44,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, } Runner.runAsync(() -> { - Installer.install(sender, args[0], false, false, false, false); + Installer.install(terminal, args[0], false, false, false, false); kpmInstance.getSession().unlock(); }); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index 97711999..f5f43ea1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -31,7 +31,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, } Runner.runAsync(() -> { - Installer.unInstall(sender, args[0], false); + Installer.unInstall(terminal, args[0], false); TeamKunPluginManager.getPlugin().getSession().unlock(); }); } From e66dc9bcaec61c58f0d3c49910ae9d47b7400a36 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 25 Jun 2022 03:36:49 +0900 Subject: [PATCH 099/745] fix: Resolve command error --- .../lab/teamkunpluginmanager/commands/CommandResolve.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java index 032d3c4d..93b9e78c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java @@ -82,7 +82,7 @@ private static void printAdditionalInformation(Terminal terminal, ResolveResult GitHubSuccessResult githubSuccessResult = (GitHubSuccessResult) result; terminal.info("[GITHUB]"); - terminal.info("リポジトリ:%s/%s" + githubSuccessResult.getOwner(), githubSuccessResult.getRepoName()); + terminal.info("リポジトリ:" + githubSuccessResult.getOwner() + "/" + githubSuccessResult.getRepoName()); terminal.info("ファイルサイズ:" + githubSuccessResult.getSize()); terminal.info("リリース名:" + githubSuccessResult.getReleaseName()); terminal.info("リリースID:" + githubSuccessResult.getReleaseId()); @@ -103,9 +103,9 @@ private static void printAdditionalInformation(Terminal terminal, ResolveResult { MarketplaceResult marketplaceResult = (MarketplaceResult) result; terminal.info("[MARKETPLACE]"); - terminal.info("タイトル:", marketplaceResult.getTitle()); - terminal.info("説明:", marketplaceResult.getDescription()); - terminal.info("公開先:", marketplaceResult.getUrl()); + terminal.info("タイトル:" + marketplaceResult.getTitle()); + terminal.info("説明:" + marketplaceResult.getDescription()); + terminal.info("公開先:" + marketplaceResult.getUrl()); terminal.writeLine(DELIMITER_SMALL); } } From f4d8b82f23f91ba833c0343d85e54cf8051c5350 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 25 Jun 2022 03:58:01 +0900 Subject: [PATCH 100/745] fix: Mismatched message --- .../resolver/interfaces/URLResolver.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 90c1d402..6827ca6b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -96,26 +96,28 @@ default ErrorResult processErrorResponse(HTTPResponse response, ResolveResult.So ); } - ErrorResult.ErrorCause cause = ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR; int code = response.getStatusCode(); switch (code) { case 200: return null; case 403: - return new ErrorResult(this, cause + return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR .value(errorCodeWith("サーバからリソースをダウンロードする権限がありません。", code)), source); case 404: - return new ErrorResult(this, cause + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND .value(errorCodeWith("サーバからリソースを見つけることができません。", code)), source); case 418: - return new ErrorResult(this, cause.value(errorCodeWith("ティーポットでコーヒーを淹れようとしました。", code)), source); + return new ErrorResult(this, + ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR + .value(errorCodeWith("ティーポットでコーヒーを淹れようとしました。", code)), source + ); default: if (code >= 500 && code < 600) - return new ErrorResult(this, cause + return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR .value(errorCodeWith("サーバーがダウンしています。", code)), source); - return new ErrorResult(this, cause + return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR .value(errorCodeWith("サーバーがエラーレスポンスを返答しました。。", code)), source ); From d7304c5773274cc314376a1cfd589595ed207206 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 25 Jun 2022 04:04:25 +0900 Subject: [PATCH 101/745] fix: Change invalid spiget link: - apple.api.spiget.org + api.spiget.org --- .../teamkunpluginmanager/resolver/impl/SpigotMCResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index c5aec3c8..c9c22cb4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -49,7 +49,7 @@ public ResolveResult resolve(QueryContext query) if (id == null) return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); - String spigotAPIUrl = "https://apple.api.spiget.org/v2/resources/" + id; + String spigotAPIUrl = "https://api.spiget.org/v2/resources/" + id; HTTPResponse data = Requests.request(RequestContext.builder() .url(spigotAPIUrl) From f9047650606545df168f52cb991959a46d459815 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 25 Jun 2022 04:21:14 +0900 Subject: [PATCH 102/745] chore(deps): Version bump of PeyangPaperUtils --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 38300df0..a93856d5 100644 --- a/pom.xml +++ b/pom.xml @@ -139,9 +139,9 @@ test - com.github.TeamKUN + com.github.TeamKun PeyangPaperUtils - 1.0.4 + 1.0.5 From 149c6c93be161ed532aceed95e422201eb718f85 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 25 Jun 2022 06:29:17 +0900 Subject: [PATCH 103/745] fix: HTTPResponse is used without try-with-resources --- .../impl/CurseBukkitSuccessResult.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index 571bb933..2c06971d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -9,6 +9,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; + /** * CurseForge または Bukkit.org の成功結果を表すクラス */ @@ -53,14 +55,20 @@ public String getDescription() if (this.description != null) return this.description; - HTTPResponse response = Requests.request(RequestContext.builder() + try (HTTPResponse response = Requests.request(RequestContext.builder() .url("https://addons-ecs.forgesvc.net/api/v2/addon/" + this.id + "/description") - .build()); - if (response.isError()) - return "Failed to get description"; + .build())) + { + if (response.isError()) + return "Failed to get description"; - this.description = response.getAsString(); - return this.description; + this.description = response.getAsString(); + return this.description; + } + catch (IOException e) + { + throw new RuntimeException(e); + } } From 293e98fe606760b3ab5f2a48553b96f7dd5d44c8 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 10 Jun 2022 04:46:24 +0900 Subject: [PATCH 104/745] fix: NoSuchMethod exception: getMethod --- .../utils/PluginUtil.java | 30 ++--- .../utils/ReflectionUtils.java | 123 ++++++++++++++---- 2 files changed, 110 insertions(+), 43 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index 09505669..80647b67 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -49,12 +49,14 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -public class PluginUtil +public class PluginUtil // TODO: Rewrite this class { - private static Method getCommandMap; - private static Object craftServer; - private static Object minecraftServer; - private static Object commandDispatcher; + private static final Method getCommandMap; + private static final Object craftServer; + private static final Object minecraftServer; + private static final Object commandDispatcher; + + private static final Method pluginGetFile; static { @@ -62,14 +64,16 @@ public class PluginUtil { craftServer = ReflectionUtils.PackageType.CRAFTBUKKIT.getClass("CraftServer").cast(Bukkit.getServer()); minecraftServer = ReflectionUtils.getMethod(craftServer.getClass(), "getServer").invoke(craftServer); - getCommandMap = ReflectionUtils.getMethod(craftServer.getClass(), "getCommandMap"); commandDispatcher = ReflectionUtils.getMethod(minecraftServer.getClass(), "getCommandDispatcher") .invoke(minecraftServer); + + pluginGetFile = ReflectionUtils.getAccessibleMethod(JavaPlugin.class, "getFile"); + pluginGetFile.setAccessible(true); } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); + throw new RuntimeException(e); } } @@ -168,19 +172,15 @@ public static String loadToString(PluginLoadOrder order) public static File getFile(Plugin plugin) { - Method getFileMethod; try { - getFileMethod = JavaPlugin.class.getDeclaredMethod("getFile"); - getFileMethod.setAccessible(true); - - return (File) getFileMethod.invoke(plugin); + return (File) pluginGetFile.invoke(plugin); } - catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) + catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); + throw new RuntimeException(e); } - return null; } @SuppressWarnings("unchecked") @@ -253,7 +253,7 @@ private static boolean containValue(String contain, ArrayList key } public static PluginDescriptionFile loadDescription(File file) throws InvalidDescriptionException, IOException - { + { // TODO: File -> Path if (!file.exists()) throw new FileNotFoundException("Not found a file."); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java index 8b3a7798..73487c31 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java @@ -23,7 +23,9 @@ * It would be nice if you provide credit to me if you use this class in a published project * * @author DarkBlade12 - * @version 1.1 + * @author Peyang + * + * @version 1.1-PYG */ public final class ReflectionUtils { @@ -46,14 +48,10 @@ private ReflectionUtils() public static Constructor getConstructor(Class clazz, Class... parameterTypes) throws NoSuchMethodException { Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); - for (Constructor constructor : clazz.getConstructors()) - { - if (!DataType.compare(DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) - { - continue; - } - return constructor; - } + for (Constructor constructor : clazz.getDeclaredConstructors()) + if (DataType.compare(DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) + return constructor; + throw new NoSuchMethodException("There is no such constructor in this class with the specified parameter types"); } @@ -65,7 +63,7 @@ public static Constructor getConstructor(Class clazz, Class... paramete * @param parameterTypes Parameter types of the desired constructor * @return The constructor of the desired target class with the specified parameter types * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found - * @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found + * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @see #getConstructor(Class, Class...) */ public static Constructor getConstructor(String className, PackageType packageType, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException @@ -73,6 +71,42 @@ public static Constructor getConstructor(String className, PackageType packag return getConstructor(packageType.getClass(className), parameterTypes); } + /** + * Returns the constructor of a desired class with the given parameter types that is accessible + * + * @param clazz Target class + * @param parameterTypes Parameter types of the desired constructor + * @return The constructor of the target class with the specified parameter types that are accessible + * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found + * @see DataType + * @see DataType#getPrimitive(Class[]) + * @see DataType#compare(Class[], Class[]) + */ + public static Constructor getAccessibleConstructor(Class clazz, Class... parameterTypes) throws NoSuchMethodException + { + Constructor constructor = getConstructor(clazz, parameterTypes); + constructor.setAccessible(true); + return constructor; + } + + /** + * Returns the constructor of a desired class with the given parameter types that is accessible + * + * @param className Name of the desired target class + * @param packageType Package where the desired target class is located + * @param parameterTypes Parameter types of the desired constructor + * @return The constructor of the desired target class with the specified parameter types that are accessible + * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found + * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found + * @see #getAccessibleConstructor(Class, Class...) + */ + public static Constructor getAccessibleConstructor(String className, PackageType packageType, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException + { + Constructor constructor = getAccessibleConstructor(packageType.getClass(className), parameterTypes); + constructor.setAccessible(true); + return constructor; + } + /** * Returns an instance of a class with the given arguments * @@ -124,14 +158,9 @@ public static Object instantiateObject(String className, PackageType packageType public static Method getMethod(Class clazz, String methodName, Class... parameterTypes) throws NoSuchMethodException { Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); - for (Method method : clazz.getMethods()) - { - if (!method.getName().equals(methodName) || !DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) - { - continue; - } - return method; - } + for (Method method : clazz.getDeclaredMethods()) + if (method.getName().equals(methodName) && DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) + return method; throw new NoSuchMethodException("There is no such method in this class with the specified name and parameter types"); } @@ -152,6 +181,46 @@ public static Method getMethod(String className, PackageType packageType, String return getMethod(packageType.getClass(className), methodName, parameterTypes); } + /** + * Returns a method of a class with the given parameter types that is accessible + * + * @param clazz Target class + * @param methodName Name of the desired method + * @param parameterTypes Parameter types of the desired method + * @return The method of the target class with the specified name and parameter types + * @throws NoSuchMethodException If the desired method of the target class with the specified name and parameter types cannot be found + * @see DataType#getPrimitive(Class[]) + * @see DataType#compare(Class[], Class[]) + */ + public static Method getAccessibleMethod(Class clazz, String methodName, Class... parameterTypes) throws NoSuchMethodException + { + Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); + for (Method method : clazz.getMethods()) + if (method.getName().equals(methodName) && DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) + { + method.setAccessible(true); + return method; + } + throw new NoSuchMethodException("There is no such method in this class with the specified name and parameter types"); + } + + /** + * Returns a method of a desired class with the given parameter types that is accessible + * + * @param className Name of the desired target class + * @param packageType Package where the desired target class is located + * @param methodName Name of the desired method + * @param parameterTypes Parameter types of the desired method + * @return The method of the desired target class with the specified name and parameter types + * @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found + * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found + * @see #getAccessibleMethod(Class, String, Class...) + */ + public static Method getAccessibleMethod(String className, PackageType packageType, String methodName, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException + { + return getAccessibleMethod(packageType.getClass(className), methodName, parameterTypes); + } + /** * Invokes a method on an object with the given arguments * @@ -565,10 +634,10 @@ public static Class[] getReference(Class[] classes) { int length = classes == null ? 0: classes.length; Class[] types = new Class[length]; + for (int index = 0; index < length; index++) - { types[index] = getReference(classes[index]); - } + return types; } @@ -582,10 +651,10 @@ public static Class[] getPrimitive(Object[] objects) { int length = objects == null ? 0: objects.length; Class[] types = new Class[length]; + for (int index = 0; index < length; index++) - { types[index] = getPrimitive(objects[index].getClass()); - } + return types; } @@ -599,10 +668,10 @@ public static Class[] getReference(Object[] objects) { int length = objects == null ? 0: objects.length; Class[] types = new Class[length]; + for (int index = 0; index < length; index++) - { types[index] = getReference(objects[index].getClass()); - } + return types; } @@ -616,17 +685,15 @@ public static Class[] getReference(Object[] objects) public static boolean compare(Class[] primary, Class[] secondary) { if (primary == null || secondary == null || primary.length != secondary.length) - { return false; - } + for (int index = 0; index < primary.length; index++) { Class primaryClass = primary[index]; Class secondaryClass = secondary[index]; if (primaryClass.equals(secondaryClass) || primaryClass.isAssignableFrom(secondaryClass)) - { continue; - } + return false; } return true; From e338ef7433bf290ff4d0f8cb9c0ab203d56bef40 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 3 Jul 2022 20:50:48 +0900 Subject: [PATCH 105/745] chore(deps): v bump PeyangPaperUtils 1.0.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a93856d5..c43e2181 100644 --- a/pom.xml +++ b/pom.xml @@ -141,7 +141,7 @@ com.github.TeamKun PeyangPaperUtils - 1.0.5 + 1.0.6 From 005b98e6911f078193e20898fde56df91767b07f Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 29 Jun 2022 05:49:38 +0900 Subject: [PATCH 106/745] feat: New plugin loader --- .../TeamKunPluginManager.java | 2 + .../commands/CommandReload.java | 4 +- .../plugin/Installer.java | 9 +- .../plugin/loader/CommandsPatcher.java | 248 +++++++++++++ .../plugin/loader/PluginLoadResult.java | 52 +++ .../plugin/loader/PluginLoader.java | 271 ++++++++++++++ .../utils/PluginUtil.java | 335 +----------------- 7 files changed, 581 insertions(+), 340 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoadResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 5f352921..055daf4c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -19,6 +19,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.BruteforceGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; @@ -130,6 +131,7 @@ public void onEnable() functional = new Say2Functional(this); resolver = new PluginResolver(); commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); + new PluginLoader(); // Initialize plugin loader registerCommands(commandManager); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java index 80869868..b0c8a3f7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java @@ -4,7 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -40,7 +40,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, Runner.runAsync(() -> { terminal.info("プラグイン %s を再読み込み中...", args[0]); - PluginUtil.reload(plugin); + PluginLoader.getInstance().reloadPlugin(plugin); terminal.success("プラグイン %s を正常に再読み込み中しました。", args[0]); TeamKunPluginManager.getPlugin().getSession().unlock(); }); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index cc9b2e6d..6e0c9aef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -9,6 +9,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; @@ -103,7 +104,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b terminal.writeLine(ChatColor.LIGHT_PURPLE + "プラグインを削除中..."); //プラグインをアンロード - PluginUtil.unload(plugin); + PluginLoader.getInstance().unloadPlugin(plugin); //非同期実行 Runner.runLaterAsync(() -> { @@ -362,7 +363,7 @@ else if (resolveResult instanceof SuccessResult) )); //バージョンの低いプラグインをアンインストール。 - PluginUtil.unload(plugin); + PluginLoader.getInstance().unloadPlugin(plugin); Runner.runLater(() -> { //削除する場合は削除 @@ -555,7 +556,7 @@ else if (resolveResult instanceof SuccessResult) delete(terminal, new File("plugins/" + f.getFileName())); //プラグインをアンロード - PluginUtil.unload(plugin); + PluginLoader.getInstance().unloadPlugin(plugin); Runner.runLaterAsync(() -> { File file = PluginUtil.getFile(plugin); @@ -565,7 +566,7 @@ else if (resolveResult instanceof SuccessResult) } //依存関係をロード - PluginUtil.load(f.getFileName().substring(0, f.getFileName().length() - 4)); + PluginLoader.getInstance().loadPlugin(new File("plugins", f.getFileName()).toPath()); } catch (Exception e) //例外が発生した場合 { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java new file mode 100644 index 00000000..d9d02fda --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java @@ -0,0 +1,248 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.loader; + +import com.mojang.brigadier.CommandDispatcher; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.utils.ReflectionUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.PluginIdentifiableCommand; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Map; + +/** + * Bukkitのコマンドをラップするクラス。 + */ +public class CommandsPatcher +{ + private CommandDispatcher iBrigadierCommandDispatcher; + + private Constructor coBukkitCommandWrapper; // Lorg/bukkit/craftbukkit//command/BukkitCommandWrapper; + + private Method mRegisterCommand; // Lorg/bukkit/craftbukkit//command/BukkitCommandWrapper; + // ->registerCommand(Lcom/mojang/brigadier/CommandDispatcher;Ljava/lang/String);V + private Method mSyncCommands; // Lorg/bukkit/craftbukkit//CraftServer; + // ->syncCommands();V + + @Getter + private CommandMap commandMap; + @Getter + private Map knownCommands; + + /** + * BukkitCommandWrapperのコンストラクタ。 + * + * @throws IllegalArgumentException 初期化に失敗したりした場合 + */ + public CommandsPatcher() + { + checkAvailable(); + this.initReflections(); + } + + private static void checkAvailable() + { + try + { + Class.forName("com.mojang.brigadier.CommandDispatcher"); + } + catch (ClassNotFoundException e) + { + throw new IllegalStateException(generateFailedMessage("Couldn't find the class 'com.mojang.brigadier.CommandDispatcher'")); + } + } + + private static String generateFailedMessage(String cause) + { + return String.format("Failed to initialize BukkitCommandWrapper: %s, Please check your server version and flavor.", cause); + } + + private void initReflections() + { + // Lnet/minecraft/server//MinecraftServer; + Class cMinecraftServer; + Object iMinecraftServer; + + // Get MinecraftServer instance + try + { + cMinecraftServer = ReflectionUtils.PackageType.MINECRAFT_SERVER.getClass("MinecraftServer"); + Method mGetServer = ReflectionUtils.getAccessibleMethod(cMinecraftServer, "getServer"); + iMinecraftServer = mGetServer.invoke(null); + } + catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) + { + throw new IllegalStateException(generateFailedMessage("Failed to get MinecraftServer instance"), e); + } + + // Lnet/minecraft/command/CommandDispatcher; + Object iCommandDispatcher; + + // Get CommandDispatcher instance + try + { + Method fCommandDispatcher = ReflectionUtils.getAccessibleMethod(cMinecraftServer, "getCommandDispatcher"); + iCommandDispatcher = fCommandDispatcher.invoke(iMinecraftServer); + } + catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) + { + throw new IllegalStateException(generateFailedMessage("Failed to get CommandDispatcher instance"), e); + } + + // Get CommandDispatcher(Brigadier) instance + try + { + Method mA = ReflectionUtils.getAccessibleMethod(iCommandDispatcher.getClass(), "a"); + this.iBrigadierCommandDispatcher = (CommandDispatcher) mA.invoke(iCommandDispatcher); + } + catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException | ClassCastException e) + { + throw new IllegalStateException(generateFailedMessage("Failed to get CommandDispatcher(Brigadier) instance"), e); + } + + Class cBukkitCommandWrapper; + Class cCraftServer; + + // Get BukkitCommandWrapper constructor + try + { + cBukkitCommandWrapper = ReflectionUtils.PackageType.CRAFTBUKKIT_COMMAND.getClass("BukkitCommandWrapper"); + cCraftServer = ReflectionUtils.PackageType.CRAFTBUKKIT.getClass("CraftServer"); + this.coBukkitCommandWrapper = ReflectionUtils.getAccessibleConstructor(cBukkitCommandWrapper, cCraftServer, Command.class); + } + catch (ClassNotFoundException | NoSuchMethodException e) + { + throw new IllegalStateException(generateFailedMessage("Failed to get BukkitCommandWrapper constructor"), e); + } + + // Get registerCommand method + try + { + this.mRegisterCommand = ReflectionUtils.getAccessibleMethod(cBukkitCommandWrapper, "registerCommand", + CommandDispatcher.class, String.class + ); + } + catch (NoSuchMethodException e) + { + throw new IllegalStateException(generateFailedMessage("Failed to get registerCommand method"), e); + } + + // Get syncCommands method + try + { + this.mSyncCommands = ReflectionUtils.getAccessibleMethod(cCraftServer, "syncCommands"); + } + catch (NoSuchMethodException e) + { + throw new IllegalStateException(generateFailedMessage("Failed to get syncCommands method"), e); + } + + // Get getKnownCommands method + try + { + Field fCommandMap = ReflectionUtils.getField(cCraftServer, true, "commandMap"); + this.commandMap = (SimpleCommandMap) fCommandMap.get(iMinecraftServer); + this.knownCommands = commandMap.getKnownCommands(); + } + catch (IllegalAccessException | NoSuchFieldException e) + { + throw new IllegalStateException(generateFailedMessage("Failed to get getKnownCommands method"), e); + } + } + + public void wrapCommand(Command command, String alias) + { + try + { + Object oBukkitCommandWrapper = this.coBukkitCommandWrapper.newInstance(Bukkit.getServer(), command); + this.mRegisterCommand.invoke(oBukkitCommandWrapper, this.iBrigadierCommandDispatcher, alias); + } + catch (InstantiationException | IllegalAccessException | InvocationTargetException e) + { + throw new IllegalStateException("Failed to wrap command", e); + } + } + + public void syncCommandsCraftBukkit() + { + try + { + this.mSyncCommands.invoke(Bukkit.getServer()); + } + catch (IllegalAccessException | InvocationTargetException e) + { + throw new IllegalStateException("Failed to sync commands", e); + } + } + + public void unWrapCommand(String command) + { + iBrigadierCommandDispatcher.getRoot().removeCommand(command); + } + + public void patchCommand(@NotNull Plugin plugin) + { + Map commandMap = this.getKnownCommands(); + + commandMap.entrySet().stream() + .filter(entry -> entry.getValue() instanceof PluginIdentifiableCommand) + .filter(entry -> { + PluginIdentifiableCommand command = (PluginIdentifiableCommand) entry.getValue(); + return command.getPlugin().getName().equalsIgnoreCase(plugin.getName()); + }) + .forEach(entry -> this.wrapCommand(entry.getValue(), entry.getKey())); + + this.syncCommandsCraftBukkit(); + + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + } + + public void unPatchCommand(@NotNull Plugin plugin) + { + Map commandMap = this.getKnownCommands(); + + commandMap.entrySet().stream() + .filter(entry -> entry.getValue() instanceof PluginIdentifiableCommand) + .filter(entry -> { + PluginIdentifiableCommand command = (PluginIdentifiableCommand) entry.getValue(); + return command.getPlugin().getName().equalsIgnoreCase(plugin.getName()); + }) + .map(Map.Entry::getKey) + .forEach(this::unWrapCommand); + + commandMap.entrySet().stream() + .filter(entry -> Plugin.class.isAssignableFrom(entry.getValue().getClass())) + .filter(entry -> { + Field fPlugin = Arrays.stream(entry.getValue().getClass().getDeclaredFields()).parallel() + .filter(field -> field.getType().isAssignableFrom(Plugin.class)) + .findFirst().orElse(null); + if (fPlugin == null) + return false; + + fPlugin.setAccessible(true); + try + { + return ((Plugin) fPlugin.get(entry.getValue())).getName().equalsIgnoreCase(plugin.getName()); + } + catch (IllegalAccessException e) + { + return false; + } + }) + .map(Map.Entry::getKey) + .forEach(this::unWrapCommand); + + this.syncCommandsCraftBukkit(); + + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoadResult.java new file mode 100644 index 00000000..131aad00 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoadResult.java @@ -0,0 +1,52 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.loader; + +import lombok.Getter; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +/** + * プラグイン読込結果を表すクラスです。 + */ +public enum PluginLoadResult +{ + /** + * 正常 + */ + OK, + + // Errors + /** + * ファイルが存在しない + */ + FILE_NOT_FOUND, + /** + * pluigin.yml が不適切 + */ + INVALID_PLUGIN_DESCRIPTION, + /** + * プラグインのファイルが間違っている(メインクラスが存在しない等) + */ + INVALID_PLUGIN_FILE, + /** + * プラグインの依存関係が読み込まれていない + */ + DEPENDENCY_NOT_FOUND, + /** + * {@link Plugin#onLoad()} の実行中に例外が発生した + */ + EXCEPTION_ON_ONLOAD_HANDLING, + /** + * その他のエラーでプラグインを有効にできなかった + */ + ENABLE_PLUGIN_FAILED; + + @Getter + private Exception exception; // implicitly final + + public PluginLoadResult withException(@NotNull Exception exception) + { + if (this.exception != null) + this.exception = exception; + return this; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java new file mode 100644 index 00000000..f14c91b0 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java @@ -0,0 +1,271 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.loader; + +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.command.Command; +import org.bukkit.command.PluginCommand; +import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.UnknownDependencyException; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.net.URLClassLoader; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * プラグインを読み込むためのクラスです。 + */ +public class PluginLoader +{ + private static PluginLoader INSTANCE; + + private final PluginManager pluginManager; + private final CommandsPatcher commandsPatcher; + + private List plugins; + private Map lookupNames; + + private Field fPlugin; // Lorg/bukkit/plugin/JavaPlugin; + private Field fPluginInit; // Lorg/bukkit/plugin/JavaPlugin; + + public PluginLoader() + { + setInstance(this); + + this.pluginManager = Bukkit.getPluginManager(); + this.commandsPatcher = new CommandsPatcher(); + + this.initReflections(); + } + + public static PluginLoader getInstance() + { + return INSTANCE; + } + + private static void setInstance(@NotNull PluginLoader instance) + { + if (INSTANCE != null) + throw new IllegalStateException("PluginLoader is already initialized."); + + INSTANCE = instance; + } + + @SuppressWarnings("unchecked") + private void initReflections() + { + try + { + Field fPlugins = this.pluginManager.getClass().getDeclaredField("plugins"); + fPlugins.setAccessible(true); + this.plugins = (List) fPlugins.get(this.pluginManager); + + Field fLookupNames = this.pluginManager.getClass().getDeclaredField("lookupNames"); + fLookupNames.setAccessible(true); + this.lookupNames = (Map) fLookupNames.get(this.pluginManager); + + Field fPlugin = this.pluginManager.getClass().getDeclaredField("plugin"); + fPlugin.setAccessible(true); + this.fPlugin = fPlugin; + + Field fPluginInit = this.pluginManager.getClass().getDeclaredField("pluginInit"); + fPluginInit.setAccessible(true); + this.fPluginInit = fPluginInit; + } + catch (NoSuchFieldException | IllegalAccessException e) + { + throw new RuntimeException(e); + } + } + + /** + * プラグインを読み込みます. + * + * @param pluginPath プラグインのパス + * @return プラグインの読み込み結果 + */ + public PluginLoadResult loadPlugin(@NotNull Path pluginPath) + { + if (!pluginPath.toFile().exists()) + return PluginLoadResult.FILE_NOT_FOUND; + + Plugin plugin; + try + { + plugin = Bukkit.getPluginManager().loadPlugin(pluginPath.toFile()); + } + catch (InvalidPluginException e) + { + return PluginLoadResult.INVALID_PLUGIN_FILE.withException(e); + } + catch (InvalidDescriptionException e) + { + return PluginLoadResult.INVALID_PLUGIN_DESCRIPTION.withException(e); + } + catch (UnknownDependencyException e) + { + return PluginLoadResult.DEPENDENCY_NOT_FOUND.withException(e); + } + + assert plugin != null; + + try + { + // Process Plugin loaded handler + plugin.onLoad(); + } + catch (Exception e) + { + return PluginLoadResult.EXCEPTION_ON_ONLOAD_HANDLING.withException(e); + } + + Bukkit.getPluginManager().enablePlugin(plugin); + + if (!plugin.isEnabled()) + return PluginLoadResult.ENABLE_PLUGIN_FAILED; + + Runner.runLater(() -> this.commandsPatcher.patchCommand(plugin), 1L); + + return PluginLoadResult.OK; + } + + public void unloadPlugin(@NotNull Plugin plugin) + { + this.getPluginRecipes(plugin.getName()) + .forEach(Bukkit::removeRecipe); + + this.commandsPatcher.unPatchCommand(plugin); + + PluginManager pluginManager = Bukkit.getPluginManager(); + pluginManager.disablePlugin(plugin); + + this.removePluginCommands(plugin); + + this.plugins.remove(plugin); + this.lookupNames.remove(plugin.getName()); + + this.unloadClasses(plugin); + } + + private void unloadClasses(Plugin plugin) + { + ClassLoader classLoader = plugin.getClass().getClassLoader(); + + if (!(classLoader instanceof URLClassLoader)) + return; + + URLClassLoader urlClassLoader = (URLClassLoader) classLoader; + + try + { + this.fPlugin.set(classLoader, null); + this.fPluginInit.set(classLoader, null); + + urlClassLoader.close(); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + TeamKunPluginManager.getPlugin().getLogger().warning("Unable to unload classes of plugin " + plugin.getName()); + } + catch (IOException e) + { + e.printStackTrace(); + TeamKunPluginManager.getPlugin().getLogger().warning("Unable to close class loader of plugin " + plugin.getName()); + } + + // Check +XX:+DisableExplicitGC flag + System.gc(); + } + + private void removePluginCommands(Plugin plugin) + { + Map knownCommands = this.commandsPatcher.getKnownCommands(); + Iterator> it = knownCommands.entrySet().iterator(); + + while (it.hasNext()) + { + Map.Entry entry = it.next(); + if (entry.getValue() instanceof PluginCommand) + { + PluginCommand pluginCommand = (PluginCommand) entry.getValue(); + if (pluginCommand.getPlugin().getName().equalsIgnoreCase(plugin.getName())) + it.remove(); + continue; + } + + Field fPlugin = Arrays.stream(entry.getValue().getClass().getDeclaredFields()).parallel() + .filter(field -> field.getType().isAssignableFrom(Plugin.class)) + .findFirst().orElse(null); + if (fPlugin == null) + return; + + fPlugin.setAccessible(true); + try + { + if (!((Plugin) fPlugin.get(entry.getValue())).getName().equalsIgnoreCase(plugin.getName())) + continue; + + entry.getValue().unregister(this.commandsPatcher.getCommandMap()); + it.remove(); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + } + catch (IllegalStateException e) + { + if (!e.getMessage().equals("zip file closed")) + { + e.printStackTrace(); + return; + } + + entry.getValue().unregister(this.commandsPatcher.getCommandMap()); + it.remove(); + } + } + } + + private List getPluginRecipes(String pluginName) + { + List result = new ArrayList<>(); + + Iterator iterator = Bukkit.recipeIterator(); + while (iterator.hasNext()) + { + Recipe recipe = iterator.next(); + if (recipe instanceof ShapedRecipe) + { + ShapedRecipe sr = (ShapedRecipe) recipe; + if (sr.getKey().getNamespace().equals(pluginName.toLowerCase(Locale.ENGLISH))) + result.add(sr.getKey()); + } + } + + return result; + } + + public void reloadPlugin(Plugin plugin) + { + Path pluginPath = PluginUtil.getFile(plugin).toPath(); + + this.unloadPlugin(plugin); + this.loadPlugin(pluginPath); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index 80647b67..10723b66 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -1,26 +1,12 @@ package net.kunmc.lab.teamkunpluginmanager.utils; -import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.InstallResult; import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; -import org.bukkit.command.Command; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.PluginIdentifiableCommand; -import org.bukkit.command.SimpleCommandMap; import org.bukkit.configuration.MemorySection; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.inventory.Recipe; -import org.bukkit.inventory.ShapedRecipe; import org.bukkit.plugin.InvalidDescriptionException; -import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoadOrder; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.PluginClassLoader; @@ -33,28 +19,17 @@ import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.RoundingMode; -import java.net.URLClassLoader; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; import java.util.Map; -import java.util.Objects; -import java.util.SortedSet; import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class PluginUtil // TODO: Rewrite this class { - private static final Method getCommandMap; - private static final Object craftServer; - private static final Object minecraftServer; - private static final Object commandDispatcher; private static final Method pluginGetFile; @@ -62,16 +37,10 @@ public class PluginUtil // TODO: Rewrite this class { try { - craftServer = ReflectionUtils.PackageType.CRAFTBUKKIT.getClass("CraftServer").cast(Bukkit.getServer()); - minecraftServer = ReflectionUtils.getMethod(craftServer.getClass(), "getServer").invoke(craftServer); - getCommandMap = ReflectionUtils.getMethod(craftServer.getClass(), "getCommandMap"); - commandDispatcher = ReflectionUtils.getMethod(minecraftServer.getClass(), "getCommandDispatcher") - .invoke(minecraftServer); - pluginGetFile = ReflectionUtils.getAccessibleMethod(JavaPlugin.class, "getFile"); pluginGetFile.setAccessible(true); } - catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException | InvocationTargetException e) + catch (NoSuchMethodException e) { throw new RuntimeException(e); } @@ -277,306 +246,4 @@ public static PluginDescriptionFile loadDescription(File file) throws InvalidDes return desc; } - - /** - * Unload a plugin. - * - * @param plugin the plugin to unload - * @author https://dev.bukkit.org/projects/plugman - */ - @SuppressWarnings("unchecked") - public static void unload(Plugin plugin) - { - getKnownCommands().entrySet().stream().parallel() - .filter(stringCommandEntry -> stringCommandEntry.getValue() instanceof PluginIdentifiableCommand) - .filter(stringCommandEntry -> { - PluginIdentifiableCommand command = (PluginIdentifiableCommand) stringCommandEntry.getValue(); - return command.getPlugin().getName().equalsIgnoreCase(plugin.getName()); - }) - .forEach(stringCommandEntry -> { - unWrapCommand(stringCommandEntry.getKey()); - }); - - getPluginRecipes(plugin.getName()).forEach(Bukkit::removeRecipe); - - Bukkit.getOnlinePlayers().stream().parallel().forEach(Player::updateCommands); - - String name = plugin.getName(); - - PluginManager pluginManager = Bukkit.getPluginManager(); - - SimpleCommandMap commandMap; - - List plugins; - - Map names; - Map commands; - Map> listeners = null; - - pluginManager.disablePlugin(plugin); - - try - { - - Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins"); - pluginsField.setAccessible(true); - plugins = (List) pluginsField.get(pluginManager); - - Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames"); - lookupNamesField.setAccessible(true); - names = (Map) lookupNamesField.get(pluginManager); - - try - { - Field listenersField = Bukkit.getPluginManager().getClass().getDeclaredField("listeners"); - listenersField.setAccessible(true); - listeners = (Map>) listenersField.get(pluginManager); - } - catch (Exception ignored) - { - } - - Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - commandMap = (SimpleCommandMap) commandMapField.get(pluginManager); - - Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands"); - knownCommandsField.setAccessible(true); - commands = (Map) knownCommandsField.get(commandMap); - - } - catch (NoSuchFieldException | IllegalAccessException e) - { - e.printStackTrace(); - return; - } - - pluginManager.disablePlugin(plugin); - - if (plugins != null) - plugins.remove(plugin); - - if (names != null) - names.remove(name); - - if (listeners != null) - { - for (SortedSet set : listeners.values()) - { - set.removeIf(value -> value.getPlugin() == plugin); - } - } - - if (commandMap != null) - { - for (Iterator> it = commands.entrySet().iterator(); it.hasNext(); ) - { - Map.Entry entry = it.next(); - if (entry.getValue() instanceof PluginCommand) - { - PluginCommand c = (PluginCommand) entry.getValue(); - if (c.getPlugin() == plugin) - { - c.setTabCompleter((a, b, c1, d) -> null); - c.unregister(commandMap); - it.remove(); - } - } - } - } - - // Attempt to close the classloader to unlock any handles on the plugin's jar file. - ClassLoader cl = plugin.getClass().getClassLoader(); - - if (cl instanceof URLClassLoader) - { - - try - { - - Field pluginField = cl.getClass().getDeclaredField("plugin"); - pluginField.setAccessible(true); - pluginField.set(cl, null); - - Field pluginInitField = cl.getClass().getDeclaredField("pluginInit"); - pluginInitField.setAccessible(true); - pluginInitField.set(cl, null); - - } - catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ignored) - { - } - - try - { - - ((URLClassLoader) cl).close(); - } - catch (IOException ignored) - { - } - - } - - // Will not work on processes started with the -XX:+DisableExplicitGC flag, but lets try it anyway. - // This tries to get around the issue where Windows refuses to unlock jar files that were previously loaded into the JVM. - System.gc(); - } - - private static void load(Plugin plugin) - { - load(plugin.getName()); - } - - public static void load(String name) - { - File pluginDir = new File("plugins"); - if (!pluginDir.isDirectory()) - { - return; - } - File pluginFile = new File(pluginDir, name + ".jar"); - if (!pluginFile.isFile()) - { - File[] listFiles = pluginDir.listFiles(); - if (listFiles == null) - return; - int length = listFiles.length; - int i = 0; - while (true) - { - if (i < length) - { - File f = listFiles[i]; - if (f.getName().endsWith(".jar")) - { - try - { - if (TeamKunPluginManager.getPlugin().getPluginLoader().getPluginDescription(f).getName().equalsIgnoreCase(name)) - { - pluginFile = f; - break; - } - } - catch (InvalidDescriptionException ignored) - { - return; - } - } - i++; - } - else - break; - } - } - - - File finalPluginFile = pluginFile; - Runner.run(() -> { - try - { - Plugin target = Bukkit.getPluginManager().loadPlugin(finalPluginFile); - Objects.requireNonNull(target).onLoad(); - Bukkit.getPluginManager().enablePlugin(target); - Runner.runLater(() -> { // TODO: Remove this runLater cuz PluginManager#enablePlugin() seems return on Plugin's enable method has returned. - getKnownCommands().entrySet().stream().parallel() - .filter(stringCommandEntry -> stringCommandEntry.getValue() instanceof PluginIdentifiableCommand) - .forEach(stringCommandEntry -> { - wrapCommand(stringCommandEntry.getValue(), stringCommandEntry.getKey()); - }); - - - Bukkit.getOnlinePlayers().stream().parallel().forEach(Player::updateCommands); - }, 10L); - } - catch (InvalidDescriptionException | InvalidPluginException e2) - { - e2.printStackTrace(); - } - }); - } - - public static void reload(Plugin plugin) - { - unload(plugin); - load(plugin); - } - - public static Map getKnownCommands() - { - try - { - SimpleCommandMap commandMap = - (SimpleCommandMap) getCommandMap.invoke(craftServer); - return commandMap.getKnownCommands(); - } - catch (Exception e) - { - e.printStackTrace(); - } - return new HashMap<>(); - } - - public static List getPluginRecipes(String pluginName) - { - List result = new ArrayList<>(); - Recipe recipe; - Iterator iterator = Bukkit.recipeIterator(); - while (iterator.hasNext()) - { - recipe = iterator.next(); - if (recipe instanceof ShapedRecipe) - { - ShapedRecipe sr = (ShapedRecipe) recipe; - if (sr.getKey().getNamespace().equals(pluginName.toLowerCase(Locale.ROOT))) - result.add(sr.getKey()); - } - } - - return result; - } - - public static void wrapCommand(Command command, String alias) - { - try - { - Class bukkitCommandWrapper = ReflectionUtils.PackageType.CRAFTBUKKIT_COMMAND.getClass("BukkitCommandWrapper"); - Object commandWrapper = bukkitCommandWrapper - .getConstructor(craftServer.getClass(), Command.class) - .newInstance(craftServer, command); - - Method bukkitCommandWrapperRegister = ReflectionUtils.getMethod( - bukkitCommandWrapper, - "register", - com.mojang.brigadier.CommandDispatcher.class, - String.class - ); - - Method a = ReflectionUtils.getMethod(ReflectionUtils.PackageType.MINECRAFT_SERVER.getClass("CommandDispatcher"), "a"); - - bukkitCommandWrapperRegister.invoke(commandWrapper, a.invoke(commandDispatcher), alias); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @SuppressWarnings("rawtypes") - public static void unWrapCommand(String command) - { - - try - { - Field b = ReflectionUtils.getField(commandDispatcher.getClass(), true, "b"); - ((com.mojang.brigadier.CommandDispatcher) b.get(commandDispatcher)) - .getRoot().removeCommand(command); - } - catch (IllegalAccessException | NoSuchFieldException e) - { - e.printStackTrace(); - } - - } - } From 7702ebcbe56aab2eb0cf97e8a212c3c4f4573bb2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 30 Jun 2022 04:51:42 +0900 Subject: [PATCH 107/745] fix: Invalid method name --- .../lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java index d9d02fda..995be061 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java @@ -127,7 +127,7 @@ private void initReflections() // Get registerCommand method try { - this.mRegisterCommand = ReflectionUtils.getAccessibleMethod(cBukkitCommandWrapper, "registerCommand", + this.mRegisterCommand = ReflectionUtils.getAccessibleMethod(cBukkitCommandWrapper, "register", CommandDispatcher.class, String.class ); } From 79f966d9b890d6cd167c90a0c1d764118eca7c29 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 30 Jun 2022 19:59:40 +0900 Subject: [PATCH 108/745] feat: getAccessibleField in ReflectionUtils.java --- .../utils/ReflectionUtils.java | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java index 73487c31..d23ce928 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java @@ -72,11 +72,11 @@ public static Constructor getConstructor(String className, PackageType packag } /** - * Returns the constructor of a desired class with the given parameter types that is accessible + * Returns the accessible constructor of a desired class with the given parameter types * * @param clazz Target class * @param parameterTypes Parameter types of the desired constructor - * @return The constructor of the target class with the specified parameter types that are accessible + * @return The accessible constructor of the target class with the specified parameter types * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found * @see DataType * @see DataType#getPrimitive(Class[]) @@ -90,12 +90,12 @@ public static Constructor getAccessibleConstructor(Class clazz, Class.. } /** - * Returns the constructor of a desired class with the given parameter types that is accessible + * Returns the accessible constructor of a desired class with the given parameter types * * @param className Name of the desired target class * @param packageType Package where the desired target class is located * @param parameterTypes Parameter types of the desired constructor - * @return The constructor of the desired target class with the specified parameter types that are accessible + * @return The accessible constructor of the desired target class with the specified parameter types * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @see #getAccessibleConstructor(Class, Class...) @@ -182,7 +182,7 @@ public static Method getMethod(String className, PackageType packageType, String } /** - * Returns a method of a class with the given parameter types that is accessible + * Returns an accessible method of a class with the given parameter types * * @param clazz Target class * @param methodName Name of the desired method @@ -205,7 +205,7 @@ public static Method getAccessibleMethod(Class clazz, String methodName, Clas } /** - * Returns a method of a desired class with the given parameter types that is accessible + * Returns an accessible method of a desired class with the given parameter types * * @param className Name of the desired target class * @param packageType Package where the desired target class is located @@ -316,6 +316,41 @@ public static Field getField(String className, PackageType packageType, boolean return getField(packageType.getClass(className), declared, fieldName); } + /** + * Returns an accessible field of the target class with the given name + * + * @param clazz Target class + * @param declared Whether the desired field is declared or not + * @param fieldName Name of the desired field + * @return The field of the target class with the specified name + * @throws NoSuchFieldException If the desired field of the given class cannot be found + * @throws SecurityException If the desired field cannot be made accessible + */ + public static Field getAccessibleField(Class clazz, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException + { + Field field = declared ? clazz.getDeclaredField(fieldName): clazz.getField(fieldName); + field.setAccessible(true); + return field; + } + + /** + * Returns an accessible field of a desired class with the given name + * + * @param className Name of the desired target class + * @param packageType Package where the desired target class is located + * @param declared Whether the desired field is declared or not + * @param fieldName Name of the desired field + * @return The field of the desired target class with the specified name + * @throws NoSuchFieldException If the desired field of the desired class cannot be found + * @throws SecurityException If the desired field cannot be made accessible + * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found + * @see #getAccessibleField(Class, boolean, String) + */ + public static Field getAccessibleField(String className, PackageType packageType, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException, ClassNotFoundException + { + return getAccessibleField(packageType.getClass(className), declared, fieldName); + } + /** * Returns the value of a field of the given class of an object * From 239cecc5d0552459a1c840b4520b7f0d9952d989 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 30 Jun 2022 20:00:01 +0900 Subject: [PATCH 109/745] fix: IllegalArgumentException in CommandsPatcher --- .../teamkunpluginmanager/plugin/loader/CommandsPatcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java index 995be061..f155e14a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java @@ -149,8 +149,8 @@ private void initReflections() // Get getKnownCommands method try { - Field fCommandMap = ReflectionUtils.getField(cCraftServer, true, "commandMap"); - this.commandMap = (SimpleCommandMap) fCommandMap.get(iMinecraftServer); + Field fCommandMap = ReflectionUtils.getAccessibleField(cCraftServer, true, "commandMap"); + this.commandMap = (SimpleCommandMap) fCommandMap.get(Bukkit.getServer()); this.knownCommands = commandMap.getKnownCommands(); } catch (IllegalAccessException | NoSuchFieldException e) From af1a27325f3604142646a2e2ad9109a5d5a9aa33 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 30 Jun 2022 20:04:24 +0900 Subject: [PATCH 110/745] fix: NoSuchFieldException: PluginLoader --- .../lab/teamkunpluginmanager/plugin/loader/PluginLoader.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java index f14c91b0..7ae387a0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java @@ -14,6 +14,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.UnknownDependencyException; +import org.bukkit.plugin.java.PluginClassLoader; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -79,11 +80,11 @@ private void initReflections() fLookupNames.setAccessible(true); this.lookupNames = (Map) fLookupNames.get(this.pluginManager); - Field fPlugin = this.pluginManager.getClass().getDeclaredField("plugin"); + Field fPlugin = PluginClassLoader.class.getDeclaredField("plugin"); fPlugin.setAccessible(true); this.fPlugin = fPlugin; - Field fPluginInit = this.pluginManager.getClass().getDeclaredField("pluginInit"); + Field fPluginInit = PluginClassLoader.class.getDeclaredField("pluginInit"); fPluginInit.setAccessible(true); this.fPluginInit = fPluginInit; } From 31046f24d682f86104e690cd82af06fdec395e45 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 6 Jul 2022 18:55:27 +0900 Subject: [PATCH 111/745] fix: Installer error --- .../net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 6e0c9aef..8249829a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -254,7 +254,7 @@ else if (resolveResult instanceof SuccessResult) //ファイルをダウンロード try { - downloadPath = Paths.get("plugins", jarURL.substring(url.lastIndexOf("/") + 1)); + downloadPath = Paths.get("plugins", jarURL.substring(jarURL.lastIndexOf("/") + 1)); downloadResult = Requests.downloadFile( RequestMethod.GET, jarURL, @@ -675,7 +675,7 @@ private static HashMap buildChoicesRecursive(int count, M { if (resolveResult instanceof SuccessResult) { - choices.put(count + "." + resolveResult.hashCode(), (SuccessResult) resolveResult); + choices.put(String.valueOf(count++), (SuccessResult) resolveResult); continue; } From 4eab6a8d02ac65574bdaf8b69272c35c14da38fa Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 12 Jul 2022 22:11:03 +0900 Subject: [PATCH 112/745] fix: method search error --- .../kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java index d23ce928..c279fb72 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java @@ -195,7 +195,7 @@ public static Method getMethod(String className, PackageType packageType, String public static Method getAccessibleMethod(Class clazz, String methodName, Class... parameterTypes) throws NoSuchMethodException { Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); - for (Method method : clazz.getMethods()) + for (Method method : clazz.getDeclaredMethods()) if (method.getName().equals(methodName) && DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) { method.setAccessible(true); From 0b6b8541e23c1bdfe05d423386d8339c6065620c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 12 Jul 2022 23:46:44 +0900 Subject: [PATCH 113/745] fix: Command processing error --- .../plugin/loader/CommandsPatcher.java | 34 +++++++++++++------ .../plugin/loader/PluginLoader.java | 10 ++++-- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java index f155e14a..b3a862d1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.loader; import com.mojang.brigadier.CommandDispatcher; -import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.utils.ReflectionUtils; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -33,10 +32,8 @@ public class CommandsPatcher private Method mSyncCommands; // Lorg/bukkit/craftbukkit//CraftServer; // ->syncCommands();V - @Getter - private CommandMap commandMap; - @Getter - private Map knownCommands; + private Field fCommandMap; // Lorg/bukkit/craftbukkit//CraftServer; + // ->org/bukkit/command/SimpleCommandMap; commandMap; /** * BukkitCommandWrapperのコンストラクタ。 @@ -146,19 +143,34 @@ private void initReflections() throw new IllegalStateException(generateFailedMessage("Failed to get syncCommands method"), e); } - // Get getKnownCommands method + // Get commandMap field try { - Field fCommandMap = ReflectionUtils.getAccessibleField(cCraftServer, true, "commandMap"); - this.commandMap = (SimpleCommandMap) fCommandMap.get(Bukkit.getServer()); - this.knownCommands = commandMap.getKnownCommands(); + fCommandMap = ReflectionUtils.getAccessibleField(cCraftServer, true, "commandMap"); } - catch (IllegalAccessException | NoSuchFieldException e) + catch (NoSuchFieldException e) { - throw new IllegalStateException(generateFailedMessage("Failed to get getKnownCommands method"), e); + throw new IllegalStateException(generateFailedMessage("Failed to get commandMap field"), e); } } + public CommandMap getCommandMap() + { + try + { + return (SimpleCommandMap) this.fCommandMap.get(Bukkit.getServer()); + } + catch (IllegalAccessException e) + { + throw new RuntimeException(e); + } + } + + public Map getKnownCommands() + { + return this.getCommandMap().getKnownCommands(); + } + public void wrapCommand(Command command, String alias) { try diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java index 7ae387a0..d5d8198e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java @@ -7,6 +7,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.command.Command; import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Player; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.plugin.InvalidDescriptionException; @@ -206,7 +207,10 @@ private void removePluginCommands(Plugin plugin) { PluginCommand pluginCommand = (PluginCommand) entry.getValue(); if (pluginCommand.getPlugin().getName().equalsIgnoreCase(plugin.getName())) + { + pluginCommand.unregister(this.commandsPatcher.getCommandMap()); it.remove(); + } continue; } @@ -214,7 +218,7 @@ private void removePluginCommands(Plugin plugin) .filter(field -> field.getType().isAssignableFrom(Plugin.class)) .findFirst().orElse(null); if (fPlugin == null) - return; + continue; fPlugin.setAccessible(true); try @@ -234,13 +238,15 @@ private void removePluginCommands(Plugin plugin) if (!e.getMessage().equals("zip file closed")) { e.printStackTrace(); - return; + continue; } entry.getValue().unregister(this.commandsPatcher.getCommandMap()); it.remove(); } } + + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); } private List getPluginRecipes(String pluginName) From 0e4955dbaab04ef81f88fbde362107a017fd368a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 13 Jul 2022 18:25:11 +0900 Subject: [PATCH 114/745] fix: Exception occurs when install a plugin thats file name is null --- .../teamkunpluginmanager/plugin/Installer.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 8249829a..4ac37d0b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -36,7 +36,6 @@ import java.math.RoundingMode; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -691,10 +690,20 @@ private static SuccessResult dependAskToTerminal(Terminal terminal, MultiResult terminal.warn("複数のリソースが見つかりました。"); Map hashResultMap = buildChoicesRecursive(1, result); - Map hashTextMap = hashResultMap.entrySet().stream() - .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(), entry.getValue().getFileName())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + Map hashTextMap = new HashMap<>(); + for (Map.Entry entry : hashResultMap.entrySet()) + { + String key = entry.getKey(); + SuccessResult value = entry.getValue(); + + String fileName = value.getFileName(); + + if (fileName == null) + fileName = ChatColor.RED + "不明なファイル名(バージョン " + value.getVersion() + ")"; + + hashTextMap.put(key, fileName); + } QuestionResult questionResult; @@ -712,6 +721,7 @@ private static SuccessResult dependAskToTerminal(Terminal terminal, MultiResult return null; } + if (questionResult.test(QuestionAttribute.CANCELLABLE)) { terminal.warn("インストールがキャンセルされました。"); From a94b7559e481eb902bbe5af20a404d13cb65693c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 27 Jul 2022 00:05:12 +0900 Subject: [PATCH 115/745] feat: Alias of commands --- pom.xml | 6 +++--- .../lab/teamkunpluginmanager/TeamKunPluginManager.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index c43e2181..d0439509 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ org.projectlombok lombok - 1.18.22 + 1.18.24 provided @@ -139,9 +139,9 @@ test - com.github.TeamKun + com.github.TeamKUN PeyangPaperUtils - 1.0.6 + 1.0.7 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 055daf4c..c07a722e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -112,12 +112,12 @@ public static void registerCommands(CommandManager commandManager) commandManager.registerCommand("clean", new CommandClean()); commandManager.registerCommand("fix", new CommandFix()); commandManager.registerCommand("info", new CommandInfo()); - commandManager.registerCommand("install", new CommandInstall()); - commandManager.registerCommand("register", new CommandRegister()); + commandManager.registerCommand("install", new CommandInstall(), "add", "i"); + commandManager.registerCommand("register", new CommandRegister(), "login"); commandManager.registerCommand("reload", new CommandReload()); commandManager.registerCommand("resolve", new CommandResolve()); commandManager.registerCommand("status", new CommandStatus()); - commandManager.registerCommand("uninstall", new CommandUninstall()); + commandManager.registerCommand("uninstall", new CommandUninstall(), "remove", "rm"); commandManager.registerCommand("update", new CommandUpdate()); } From a97e18037716d302149a4bd6c51ed2127f433e8d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 27 Jul 2022 00:09:13 +0900 Subject: [PATCH 116/745] feat: Ignoring uninstall PeyangPaperUtils --- src/main/resources/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c3b36d3b..356d8836 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,5 +22,6 @@ config: auth: true # 保護 ignore: - - bStats #削除しないでください - - TeamKunPluginManager #削除しないでください + - bStats #削除しないでください + - TeamKunPluginManager #削除しないでください + - PeyangPaperUtils #削除しないでください From a2cca5757a784475a0e3113bf301151adc9a4bb4 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 27 Jul 2022 00:16:54 +0900 Subject: [PATCH 117/745] chore: v3.0.0-pre1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d0439509..ef362727 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kunmc.lab TeamKunPluginManager - 2.8.3 + 3.0.0-pre1 jar TeamKunPluginManager From 495d125843598cc0c0ab515efcc4daf17e513f32 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 27 Jul 2022 02:59:32 +0900 Subject: [PATCH 118/745] chore(deps): fix invalid dependency scopes --- pom.xml | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index ef362727..48961af4 100644 --- a/pom.xml +++ b/pom.xml @@ -41,15 +41,6 @@ false - - - commons-validator:* - commons-io:* - org.slf4j:* - com.zaxxer:* - *:version-compare - - @@ -89,30 +80,23 @@ 1.16.5-R0.1-SNAPSHOT provided - - commons-validator - commons-validator - 1.7 - commons-io commons-io 2.11.0 + runtime com.github.G00fY2 version-compare 1.3.7 + runtime com.zaxxer HikariCP 4.0.3 - - - fr.minuskube.inv - smart-invs - 1.2.7 + runtime org.spigotmc @@ -142,6 +126,7 @@ com.github.TeamKUN PeyangPaperUtils 1.0.7 + runtime From e49bc307ef61f0adcd592930bfde29d8928b71ca Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 27 Jul 2022 03:34:47 +0900 Subject: [PATCH 119/745] chore(deps): optimize deps --- pom.xml | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 48961af4..b8ff6883 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,40 @@ + + true + + + org.slf4j:* + + + + + *:* + + META-INF/MANIFEST.MF + + + + com.github.TeamKUN:PeyangPaperUtils + + plugin.yml + + + + commons-io + + META-INF/*.txt + + + + com.github.G00fY2:version-compare + + META-INF/proguard/* + + + + @@ -84,19 +118,19 @@ commons-io commons-io 2.11.0 - runtime + compile com.github.G00fY2 version-compare 1.3.7 - runtime + compile com.zaxxer HikariCP 4.0.3 - runtime + compile org.spigotmc @@ -126,7 +160,7 @@ com.github.TeamKUN PeyangPaperUtils 1.0.7 - runtime + compile From 283069dde4a35fd4ad1fe9190b36390a29ccb830 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 27 Jul 2022 04:17:34 +0900 Subject: [PATCH 120/745] refactor: Reduce unused Class: Say2Functional --- .../TeamKunPluginManager.java | 4 +- .../utils/Say2Functional.java | 169 ------------------ 2 files changed, 1 insertion(+), 172 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index c07a722e..54ba686b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -27,7 +27,6 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.impl.KnownPluginsResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; -import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.Session; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; @@ -44,7 +43,7 @@ public final class TeamKunPluginManager extends JavaPlugin private FileConfiguration pluginConfig; private TokenVault vault; - private Say2Functional functional; + @Setter private boolean enableBuildTree = true; private Session session; @@ -128,7 +127,6 @@ public void onEnable() saveDefaultConfig(); plugin = this; pluginConfig = getConfig(); - functional = new Say2Functional(this); resolver = new PluginResolver(); commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); new PluginLoader(); // Initialize plugin loader diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java deleted file mode 100644 index 48199931..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Say2Functional.java +++ /dev/null @@ -1,169 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -import io.papermc.paper.event.player.AsyncChatEvent; -import org.bukkit.Bukkit; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.server.ServerCommandEvent; -import org.bukkit.plugin.Plugin; - -import java.awt.*; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashMap; -import java.util.UUID; -import java.util.function.BiPredicate; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -public class Say2Functional implements Listener -{ - - private final HashMap say2func; - private FunctionalEntry consoleFunc; - - private static Class LATEST_PAPER_CLASS; - private static Method LATEST_GET_CONTENT; - private static boolean LATEST; - - static { - try - { - LATEST_PAPER_CLASS = Class.forName("net.kyori.adventure.text.TextComponentImpl"); - LATEST_GET_CONTENT = LATEST_PAPER_CLASS.getDeclaredMethod("content"); - LATEST_GET_CONTENT.setAccessible(true); - LATEST = true; - } - catch (ClassNotFoundException | NoSuchMethodException e) - { - LATEST = false; - } - } - - public Say2Functional(Plugin plugin) - { - Bukkit.getPluginManager().registerEvents(this, plugin); - say2func = new HashMap<>(); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onSay(AsyncChatEvent e) - { - if (!say2func.containsKey(e.getPlayer().getUniqueId())) - return; - - FunctionalEntry entry = this.say2func.get(e.getPlayer().getUniqueId()); - - String message; - - if (!LATEST) - message = ((TextComponent) e.originalMessage()).getText(); - else - { - try - { - message = (String) LATEST_GET_CONTENT.invoke(LATEST_PAPER_CLASS.cast(e.message())); - } - catch (Exception ex) - { - throw new RuntimeException(ex); - } - } - - if (entry.keywords != null && Arrays.stream(entry.keywords).noneMatch(s -> entry.matchType.test(message, s))) - return; - e.setCancelled(true); - - say2func.remove(e.getPlayer().getUniqueId()); - if (entry.keywords == null) - { - entry.func.accept(message); - return; - } - - entry.func.accept(Arrays.stream(entry.keywords). - filter(s -> entry.matchType.test(message, s)) - .collect(Collectors.toList()).get(0)); - - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onConsole(ServerCommandEvent e) - { - if (consoleFunc == null || !(e.getSender() instanceof ConsoleCommandSender)) - return; - - e.setCancelled(true); - - FunctionalEntry entry = consoleFunc; - if (entry.keywords != null && Arrays.stream(entry.keywords).noneMatch(s -> entry.matchType.test(e.getCommand(), s))) - return; - e.setCancelled(true); - - consoleFunc = null; - if (entry.keywords == null) - { - entry.func.accept(e.getCommand()); - return; - } - - entry.func.accept(Arrays.stream(entry.keywords) - .filter(s -> entry.matchType.test(e.getCommand(), s)) - .collect(Collectors.toList()).get(0)); - - } - - @EventHandler - public void onQuit(PlayerQuitEvent e) - { - this.say2func.remove(e.getPlayer().getUniqueId()); - } - - public void add(UUID player, FunctionalEntry func) - { - if (player == null) - consoleFunc = func; - else - this.say2func.put(player, func); - } - - public void remove(UUID player) - { - if (player == null) - consoleFunc = null; - else - this.say2func.remove(player); - } - - public FunctionalEntry get(UUID player) - { - if (player == null) - return consoleFunc; - return this.say2func.get(player); - } - - public static class FunctionalEntry - { - public final String[] keywords; - public final Consumer func; - public final BiPredicate matchType; - - public FunctionalEntry(BiPredicate matchType, Consumer runas, String... keywords) - { - this(null, matchType, runas, keywords); - } - - public FunctionalEntry(String comment, BiPredicate matchType, Consumer runas, String... keywords) - { - if (keywords.length == 0) - this.keywords = null; - else - this.keywords = keywords; - this.func = runas; - this.matchType = matchType; - } - } -} From 8106200fef1770534a0db3490fc2ddeae817d672 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Jul 2022 20:09:48 +0000 Subject: [PATCH 121/745] chore(deps-dev): bump junit-jupiter-api from 5.8.2 to 5.9.0 Bumps [junit-jupiter-api](https://github.com/junit-team/junit5) from 5.8.2 to 5.9.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.2...r5.9.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b8ff6883..ca06cb03 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ org.junit.jupiter junit-jupiter-api - 5.8.2 + 5.9.0 test From 5ff0248b617bfecb2c4b3754cec61d2479eedf53 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Jul 2022 20:09:52 +0000 Subject: [PATCH 122/745] chore(deps-dev): bump junit-jupiter-engine from 5.8.2 to 5.9.0 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.8.2 to 5.9.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.2...r5.9.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b8ff6883..62afc94d 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.9.0 test From 2eccafdc50769f2b36a4338bb632b36c1b5b5d7d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 30 Jul 2022 04:17:16 +0900 Subject: [PATCH 123/745] chore(deps): v bump PeyangPaperUtils to 1.0.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bdc5f5e9..2d45d2a8 100644 --- a/pom.xml +++ b/pom.xml @@ -159,7 +159,7 @@ com.github.TeamKUN PeyangPaperUtils - 1.0.7 + 1.0.8 compile From b913a5f910a8151f4ed39744b1809ef767dba57e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 19 Apr 2022 19:23:44 +0900 Subject: [PATCH 124/745] refactor: Terminalize installer --- .../plugin/Installer.java | 252 ++++++++---------- 1 file changed, 108 insertions(+), 144 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 4ac37d0b..cc05b10c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -6,10 +6,8 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; @@ -18,12 +16,17 @@ import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; +import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.entity.Player; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; @@ -34,16 +37,15 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Objects; +import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.stream.IntStream; @SuppressWarnings("unused") public class Installer @@ -65,7 +67,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b //プラグインが見つからない場合はreturn if (info == null) { - terminal.error("プラグインが見つかりませんでした。"); + terminal.writeLine(ChatColor.RED + "E: プラグインが見つかりませんでした。"); return; } @@ -75,7 +77,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b //アンインストール対象が存在するかチェック if (!PluginUtil.isPluginLoaded(info.name)) { - terminal.error("プラグインが見つかりませんでした。"); + terminal.writeLine(ChatColor.RED + "E: プラグインが見つかりませんでした。"); return; } @@ -83,9 +85,9 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b if (TeamKunPluginManager.getPlugin().getPluginConfig(). getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name))) { - terminal.warn("このプラグインは保護されています。\n" + + terminal.writeLine(ChatColor.YELLOW + "W: このプラグインは保護されています。\n" + ChatColor.YELLOW + " 保護されているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - terminal.error("システムが保護されました。"); + terminal.writeLine(ChatColor.RED + "E: システムが保護されました。"); return; } @@ -93,17 +95,17 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b // 強制アンインストールである場合は無視 if (!info.rdepends.isEmpty() && !force) { - terminal.warn("このプラグインは以下のプラグインの依存関係です。"); + terminal.writeLine(ChatColor.YELLOW + "W: このプラグインは以下のプラグインの依存関係です。"); terminal.writeLine(ChatColor.BLUE + info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.joining(" "))); terminal.writeLine(ChatColor.YELLOW + " 依存関係になっているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - terminal.error("システムが保護されました。"); + terminal.writeLine(ChatColor.RED + "E: システムが保護されました。"); return; } terminal.writeLine(ChatColor.LIGHT_PURPLE + "プラグインを削除中..."); //プラグインをアンロード - PluginLoader.getInstance().unloadPlugin(plugin); + PluginUtil.unload(plugin); //非同期実行 Runner.runLaterAsync(() -> { @@ -128,7 +130,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b if (!autoRemovable.isEmpty()) terminal.writeLine(autoRemovable); terminal.writeLine(Messages.getStatusMessage(0, 1, 0)); - terminal.success(plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); + terminal.writeLine(ChatColor.GREEN + "S: " + plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); }, 20L); } @@ -189,7 +191,8 @@ public static InstallResult install(@NotNull Terminal terminal, String url, bool { ErrorResult errorResult = (ErrorResult) resolveResult; - terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); + terminal.writeLine(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + " リゾルバ:" + errorResult.getSource().getName()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); @@ -200,14 +203,14 @@ else if (resolveResult instanceof MultiResult) try { - if (terminal.isQuiet()) + if (terminal.isQuiet()) // TODO: なんやねんこのクソコード { resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); if (resolveResult instanceof ErrorResult) { ErrorResult errorResult = (ErrorResult) resolveResult; - terminal.error(errorResult.getCause().getMessage() + + terminal.writeLine(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); @@ -220,15 +223,15 @@ else if (resolveResult instanceof SuccessResult) } else { - SuccessResult result = dependAskToTerminal(terminal, multiResult); - - if (result == null) - { - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - return new InstallResult(add, remove, modify, false); - } - - jarURL = result.getDownloadUrl(); + List> multi = Arrays.stream(multiResult.getResults()) + .filter(result -> result instanceof SuccessResult) + .map(result -> { + SuccessResult successResult = (SuccessResult) result; + return new Pair<>(successResult.getVersion(), successResult.getDownloadUrl()); + }).collect(Collectors.toList()); + + depend_askToCommandSender(terminal, multi, ignoreInstall, withoutResolveDepends, withoutRemove); + return new InstallResult(add, remove, modify, false); } } catch (IllegalArgumentException ignored) @@ -239,8 +242,7 @@ else if (resolveResult instanceof SuccessResult) jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); } - long downloadResult; - Path downloadPath; + Pair downloadResult; //ダウンロード if (!withoutDownload) @@ -251,24 +253,16 @@ else if (resolveResult instanceof SuccessResult) long startTime = System.currentTimeMillis(); //ファイルをダウンロード - try - { - downloadPath = Paths.get("plugins", jarURL.substring(jarURL.lastIndexOf("/") + 1)); - downloadResult = Requests.downloadFile( - RequestMethod.GET, - jarURL, - downloadPath - ); - } - catch (IOException e) + downloadResult = URLUtils.downloadFile(jarURL); + if (downloadResult.getLeft() == null && downloadResult.getRight().startsWith("ERROR ")) { - terminal.error("ファイルのダウンロードに失敗しました:" + e.getMessage()); + terminal.writeLine(ChatColor.YELLOW + "W: " + downloadResult.getRight().substring(6)); + terminal.writeLine(ChatColor.RED + "E: ファイルのダウンロードに失敗しました。"); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } - - terminal.writeLine(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadPath.getFileName().toString())); + terminal.writeLine(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadResult.getRight())); add++; terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())) @@ -276,10 +270,7 @@ else if (resolveResult instanceof SuccessResult) .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN) + "秒で取得しました。"); } else //ダウンロードしない - { - downloadResult = -1; - downloadPath = Paths.get(url); - } + downloadResult = new Pair<>(true, url); terminal.writeLine(ChatColor.LIGHT_PURPLE + "情報を読み込み中..."); @@ -288,13 +279,13 @@ else if (resolveResult instanceof SuccessResult) try { //plugin.ymlを読み取り - description = PluginUtil.loadDescription(downloadPath.toFile()); + description = PluginUtil.loadDescription(new File("plugins/" + downloadResult.getRight())); } catch (FileNotFoundException e) //ファイルが見つからない場合はreturn { - terminal.error("ファイルが見つかりませんでした。"); + terminal.writeLine(ChatColor.RED + "E: ファイルが見つかりませんでした。"); if (!withoutRemove) - delete(terminal, downloadPath.toFile()); + delete(terminal, new File("plugins/" + downloadResult.getRight())); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); @@ -302,9 +293,9 @@ else if (resolveResult instanceof SuccessResult) } catch (IOException | InvalidDescriptionException e) //plugin.ymlがおかしい場合はreturn { - terminal.error("情報を読み込めませんでした。"); + terminal.writeLine(ChatColor.RED + "E: 情報を読み込めませんでした。"); if (!withoutRemove) - delete(terminal, downloadPath.toFile()); + delete(terminal, new File("plugins/" + downloadResult.getRight())); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); @@ -313,10 +304,10 @@ else if (resolveResult instanceof SuccessResult) //保護されているプラグインの場合はインスコ・変換せずreturn if (TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) { - terminal.error("このプラグインは保護されています。"); + terminal.writeLine(ChatColor.RED + "E: このプラグインは保護されています。"); add--; if (!withoutRemove) - delete(terminal, downloadPath.toFile()); + delete(terminal, new File("plugins/" + downloadResult.getRight())); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } @@ -334,10 +325,10 @@ else if (resolveResult instanceof SuccessResult) //ファイルを移動 //114514.jar => YJSNPIPlugin-1.0.jar FileUtils.moveFile( - downloadPath.toFile(), + new File("plugins/" + downloadResult.getRight()), new File("plugins/" + fileName) ); - downloadPath = Paths.get("plugins/" + fileName); + downloadResult = new Pair<>(false, fileName); } catch (IOException e) { @@ -362,7 +353,7 @@ else if (resolveResult instanceof SuccessResult) )); //バージョンの低いプラグインをアンインストール。 - PluginLoader.getInstance().unloadPlugin(plugin); + PluginUtil.unload(plugin); Runner.runLater(() -> { //削除する場合は削除 @@ -373,17 +364,17 @@ else if (resolveResult instanceof SuccessResult) else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが変わらない(もしくは低い)。 { add--; - terminal.warn("既に同じプラグインが存在します。"); + terminal.writeLine(ChatColor.YELLOW + "W: 既に同じプラグインが存在します。"); //それでもインストールするかどうかを尋 if (terminal.isPlayer()) // TODO: Remove this if statement { //ファイルの比較を行う terminal.writeLine(getDiffMessage(PluginUtil.getFile(plugin), false)); - terminal.writeLine(getDiffMessage(downloadPath.toFile(), true)); + terminal.writeLine(getDiffMessage(new File("plugins/" + downloadResult.getRight()), true)); terminal.writeLine("\n"); //ファイナルにコピーする。 - String fileName = downloadPath.getFileName().toString(); + String fileName = downloadResult.getRight(); try { @@ -397,7 +388,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが delete(terminal, new File("plugins/" + fileName)); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.success(description.getFullName() + " を正常にインストールしました。"); + terminal.writeLine(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); } else { @@ -405,9 +396,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが InstallResult ir = install(terminal, fileName, false, false, false, true); terminal.writeLine(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); } - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } catch (InterruptedException e) @@ -417,18 +406,16 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが } //削除 - if (!withoutRemove && downloadPath.toFile().exists()) - delete(terminal, downloadPath.toFile()); + if (!withoutRemove && new File("plugins/" + downloadResult.getRight()).exists()) + delete(terminal, new File("plugins/" + downloadResult.getRight())); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.success(description.getFullName() + " を正常にインストールしました。"); - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); + terminal.writeLine(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } - added.add(new InstallResult(downloadPath.getFileName().toString(), description.getName(), add, remove, modify, true)); + added.add(new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true)); //==================依存関係解決処理 ここから================== @@ -466,9 +453,9 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが { ErrorResult errorResult = (ErrorResult) resolveResult; - terminal.error(errorResult.getCause().getMessage() + + terminal.writeLine(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); - terminal.warn(dependency + ": " + dependency.substring(5)); + terminal.writeLine(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); failedResolve.add(dependency); continue; } @@ -479,7 +466,7 @@ else if (resolveResult instanceof MultiResult) resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); if (resolveResult instanceof ErrorResult) { - terminal.warn(dependency + ": " + dependency.substring(5)); + terminal.writeLine(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); failedResolve.add(dependency); continue; } @@ -526,11 +513,9 @@ else if (resolveResult instanceof SuccessResult) if (!failedResolve.isEmpty()) { terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.warn(description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); + terminal.writeLine(ChatColor.YELLOW + "W: " + description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); terminal.writeLine(ChatColor.RED + String.join(", ", failedResolve)); - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } AtomicBoolean success = new AtomicBoolean(true); @@ -548,14 +533,14 @@ else if (resolveResult instanceof SuccessResult) //プラグインが既に読まれてい場合はreturn if (PluginUtil.isPluginLoaded(description.getName())) { - terminal.error("Bukkitのインジェクションに失敗しました。"); + terminal.writeLine(ChatColor.RED + "E: Bukkitのインジェクションに失敗しました。"); //削除する場合は削除 if (!withoutRemove) delete(terminal, new File("plugins/" + f.getFileName())); //プラグインをアンロード - PluginLoader.getInstance().unloadPlugin(plugin); + PluginUtil.unload(plugin); Runner.runLaterAsync(() -> { File file = PluginUtil.getFile(plugin); @@ -565,7 +550,7 @@ else if (resolveResult instanceof SuccessResult) } //依存関係をロード - PluginLoader.getInstance().loadPlugin(new File("plugins", f.getFileName()).toPath()); + PluginUtil.load(f.getFileName().substring(0, f.getFileName().length() - 4)); } catch (Exception e) //例外が発生した場合 { @@ -581,7 +566,7 @@ else if (resolveResult instanceof SuccessResult) //失敗フラグが立っていた場合は表示 if (!success.get()) - terminal.error("プラグインの読み込みに失敗しました。"); + terminal.writeLine(ChatColor.RED + "E: プラグインの読み込みに失敗しました。"); int finalAdd1 = add; int finalModify1 = modify; @@ -602,12 +587,10 @@ public void run() terminal.writeLine(autoRemovable); terminal.writeLine(Messages.getStatusMessage(finalAdd1, remove, finalModify1)); - terminal.success(description.getFullName() + " を正常にインストールしました。"); + terminal.writeLine(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); /*} }.runTaskLater(TeamKunPluginManager.plugin, 10L);*/ - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); + return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } private static String getDiffMessage(File f, boolean isNew) @@ -661,74 +644,55 @@ public static void delete(Terminal terminal, File f) } catch (Exception e) { - terminal.error("ファイルの削除に失敗しました: " + f.getName()); + terminal.writeLine(ChatColor.RED + "E: ファイルの削除に失敗しました: " + f.getName()); } } - private static HashMap buildChoicesRecursive(int count, MultiResult result) + private static void depend_askToCommandSender(Terminal terminal, List> jar, boolean ignoreInstall, boolean withoutResolveDepends, boolean withoutRemove) { - HashMap choices = new HashMap<>(); - - for (ResolveResult resolveResult : result.getResults()) - { - if (resolveResult instanceof SuccessResult) + UUID uuid = null; + if (terminal instanceof Player) + uuid = ((Player) terminal).getUniqueId(); + + terminal.writeLine(ChatColor.YELLOW + "W: リソースが複数見つかりました。インストールするリソースを選択するか、キャンセルを行ってください。"); + AtomicInteger integer = new AtomicInteger(0); + jar.forEach(pair -> { + int index = integer.incrementAndGet(); + terminal.write(Component.text(ChatColor.LIGHT_PURPLE + "- [" + index + "] " + ChatColor.GREEN + pair.getLeft()) + .clickEvent(ClickEvent.runCommand("/kpm i " + pair.getRight())) + .hoverEvent(HoverEvent.showText( + Component.text(ChatColor.GREEN + "クリックしてこのリリースをインストール")))); + + }); + terminal.write(Component.text(ChatColor.LIGHT_PURPLE + "- [C] " + ChatColor.GREEN + "キャンセル") + .clickEvent(ClickEvent.runCommand("/kpm i $CF$")) + .hoverEvent(HoverEvent.showText( + Component.text(ChatColor.GREEN + "クリックしてこのリリースをインストール")))); + + // TODO: Replace to Question + TeamKunPluginManager.getPlugin().getFunctional().add(uuid, new Say2Functional.FunctionalEntry(StringUtils::equalsIgnoreCase, s -> { + if (s.equalsIgnoreCase("c")) { - choices.put(String.valueOf(count++), (SuccessResult) resolveResult); - continue; + terminal.writeLine(ChatColor.RED + "E: キャンセルされました。"); + return; } - if (resolveResult instanceof MultiResult) - choices.putAll(buildChoicesRecursive(count + 1, (MultiResult) resolveResult)); - } - - return choices; - } - - private static SuccessResult dependAskToTerminal(Terminal terminal, MultiResult result) - { - terminal.warn("複数のリソースが見つかりました。"); - - Map hashResultMap = buildChoicesRecursive(1, result); - Map hashTextMap = new HashMap<>(); - - for (Map.Entry entry : hashResultMap.entrySet()) - { - String key = entry.getKey(); - SuccessResult value = entry.getValue(); - - String fileName = value.getFileName(); - - if (fileName == null) - fileName = ChatColor.RED + "不明なファイル名(バージョン " + value.getVersion() + ")"; - - hashTextMap.put(key, fileName); - } - - QuestionResult questionResult; - - try - { - questionResult = - terminal.getInput().showQuestion("インストールするリリースを選択してください。", - new AttributeChoice(hashTextMap), QuestionAttribute.CANCELLABLE - ) - .waitAndGetResult(); - } - catch (InterruptedException e) - { - terminal.error("処理が中断されました。"); - return null; - } - + int i = Integer.parseInt(s); + if (i < 1 || i > jar.size() + 1) + { + terminal.writeLine(ChatColor.RED + "リソースは 1 以上、" + (jar.size() + 1) + " 以下である必要があります。"); + terminal.writeLine(ChatColor.RED + "E: キャンセルされました。"); + return; + } - if (questionResult.test(QuestionAttribute.CANCELLABLE)) - { - terminal.warn("インストールがキャンセルされました。"); - return null; - } + Pair resource = jar.get(--i); + install(terminal, resource.getRight(), ignoreInstall, withoutResolveDepends, withoutRemove, false); - return hashResultMap.get(questionResult.getRawAnswer()); + }, (String[]) ArrayUtils.add(IntStream.range(1, jar.size() + 1).parallel() + .mapToObj(String::valueOf) + .toArray(String[]::new), "c")) + ); } private static String pickPluginJar(List> jar) From 49217c090be76bbce1436594147aab9a091daa7c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 19 Apr 2022 20:57:49 +0900 Subject: [PATCH 125/745] refactor: use error() and warn() and success() --- .../plugin/Installer.java | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index cc05b10c..1f90b4d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -67,7 +67,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b //プラグインが見つからない場合はreturn if (info == null) { - terminal.writeLine(ChatColor.RED + "E: プラグインが見つかりませんでした。"); + terminal.error("プラグインが見つかりませんでした。"); return; } @@ -77,7 +77,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b //アンインストール対象が存在するかチェック if (!PluginUtil.isPluginLoaded(info.name)) { - terminal.writeLine(ChatColor.RED + "E: プラグインが見つかりませんでした。"); + terminal.error("プラグインが見つかりませんでした。"); return; } @@ -85,9 +85,9 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b if (TeamKunPluginManager.getPlugin().getPluginConfig(). getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name))) { - terminal.writeLine(ChatColor.YELLOW + "W: このプラグインは保護されています。\n" + + terminal.warn("このプラグインは保護されています。\n" + ChatColor.YELLOW + " 保護されているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - terminal.writeLine(ChatColor.RED + "E: システムが保護されました。"); + terminal.error("システムが保護されました。"); return; } @@ -95,10 +95,10 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b // 強制アンインストールである場合は無視 if (!info.rdepends.isEmpty() && !force) { - terminal.writeLine(ChatColor.YELLOW + "W: このプラグインは以下のプラグインの依存関係です。"); + terminal.warn("このプラグインは以下のプラグインの依存関係です。"); terminal.writeLine(ChatColor.BLUE + info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.joining(" "))); terminal.writeLine(ChatColor.YELLOW + " 依存関係になっているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - terminal.writeLine(ChatColor.RED + "E: システムが保護されました。"); + terminal.error("システムが保護されました。"); return; } @@ -130,7 +130,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b if (!autoRemovable.isEmpty()) terminal.writeLine(autoRemovable); terminal.writeLine(Messages.getStatusMessage(0, 1, 0)); - terminal.writeLine(ChatColor.GREEN + "S: " + plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); + terminal.success(plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); }, 20L); } @@ -191,8 +191,7 @@ public static InstallResult install(@NotNull Terminal terminal, String url, bool { ErrorResult errorResult = (ErrorResult) resolveResult; - terminal.writeLine(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + - " リゾルバ:" + errorResult.getSource().getName()); + terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); @@ -203,14 +202,14 @@ else if (resolveResult instanceof MultiResult) try { - if (terminal.isQuiet()) // TODO: なんやねんこのクソコード + if (terminal.isQuiet()) { resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); if (resolveResult instanceof ErrorResult) { ErrorResult errorResult = (ErrorResult) resolveResult; - terminal.writeLine(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); @@ -256,8 +255,8 @@ else if (resolveResult instanceof SuccessResult) downloadResult = URLUtils.downloadFile(jarURL); if (downloadResult.getLeft() == null && downloadResult.getRight().startsWith("ERROR ")) { - terminal.writeLine(ChatColor.YELLOW + "W: " + downloadResult.getRight().substring(6)); - terminal.writeLine(ChatColor.RED + "E: ファイルのダウンロードに失敗しました。"); + terminal.warn(downloadResult.getRight().substring(6)); + terminal.error("ファイルのダウンロードに失敗しました。"); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } @@ -283,7 +282,7 @@ else if (resolveResult instanceof SuccessResult) } catch (FileNotFoundException e) //ファイルが見つからない場合はreturn { - terminal.writeLine(ChatColor.RED + "E: ファイルが見つかりませんでした。"); + terminal.error("ファイルが見つかりませんでした。"); if (!withoutRemove) delete(terminal, new File("plugins/" + downloadResult.getRight())); @@ -293,7 +292,7 @@ else if (resolveResult instanceof SuccessResult) } catch (IOException | InvalidDescriptionException e) //plugin.ymlがおかしい場合はreturn { - terminal.writeLine(ChatColor.RED + "E: 情報を読み込めませんでした。"); + terminal.error("情報を読み込めませんでした。"); if (!withoutRemove) delete(terminal, new File("plugins/" + downloadResult.getRight())); @@ -304,7 +303,7 @@ else if (resolveResult instanceof SuccessResult) //保護されているプラグインの場合はインスコ・変換せずreturn if (TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) { - terminal.writeLine(ChatColor.RED + "E: このプラグインは保護されています。"); + terminal.error("このプラグインは保護されています。"); add--; if (!withoutRemove) delete(terminal, new File("plugins/" + downloadResult.getRight())); @@ -364,7 +363,7 @@ else if (resolveResult instanceof SuccessResult) else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが変わらない(もしくは低い)。 { add--; - terminal.writeLine(ChatColor.YELLOW + "W: 既に同じプラグインが存在します。"); + terminal.warn("既に同じプラグインが存在します。"); //それでもインストールするかどうかを尋 if (terminal.isPlayer()) // TODO: Remove this if statement @@ -388,7 +387,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが delete(terminal, new File("plugins/" + fileName)); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.writeLine(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); + terminal.success(description.getFullName() + " を正常にインストールしました。"); } else { @@ -410,7 +409,7 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが delete(terminal, new File("plugins/" + downloadResult.getRight())); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.writeLine(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); + terminal.success(description.getFullName() + " を正常にインストールしました。"); return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } @@ -453,9 +452,9 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが { ErrorResult errorResult = (ErrorResult) resolveResult; - terminal.writeLine(ChatColor.RED + "E: " + errorResult.getCause().getMessage() + + terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); - terminal.writeLine(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); + terminal.warn(dependency + ": " + dependency.substring(5)); failedResolve.add(dependency); continue; } @@ -466,7 +465,7 @@ else if (resolveResult instanceof MultiResult) resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); if (resolveResult instanceof ErrorResult) { - terminal.writeLine(ChatColor.YELLOW + "W: " + dependency + ": " + dependency.substring(5)); + terminal.warn(dependency + ": " + dependency.substring(5)); failedResolve.add(dependency); continue; } @@ -513,7 +512,7 @@ else if (resolveResult instanceof SuccessResult) if (!failedResolve.isEmpty()) { terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.writeLine(ChatColor.YELLOW + "W: " + description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); + terminal.warn(description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); terminal.writeLine(ChatColor.RED + String.join(", ", failedResolve)); return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); } @@ -533,7 +532,7 @@ else if (resolveResult instanceof SuccessResult) //プラグインが既に読まれてい場合はreturn if (PluginUtil.isPluginLoaded(description.getName())) { - terminal.writeLine(ChatColor.RED + "E: Bukkitのインジェクションに失敗しました。"); + terminal.error("Bukkitのインジェクションに失敗しました。"); //削除する場合は削除 if (!withoutRemove) @@ -566,7 +565,7 @@ else if (resolveResult instanceof SuccessResult) //失敗フラグが立っていた場合は表示 if (!success.get()) - terminal.writeLine(ChatColor.RED + "E: プラグインの読み込みに失敗しました。"); + terminal.error("プラグインの読み込みに失敗しました。"); int finalAdd1 = add; int finalModify1 = modify; @@ -587,7 +586,7 @@ public void run() terminal.writeLine(autoRemovable); terminal.writeLine(Messages.getStatusMessage(finalAdd1, remove, finalModify1)); - terminal.writeLine(ChatColor.GREEN + "S: " + description.getFullName() + " を正常にインストールしました。"); + terminal.success(description.getFullName() + " を正常にインストールしました。"); /*} }.runTaskLater(TeamKunPluginManager.plugin, 10L);*/ return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); @@ -644,7 +643,7 @@ public static void delete(Terminal terminal, File f) } catch (Exception e) { - terminal.writeLine(ChatColor.RED + "E: ファイルの削除に失敗しました: " + f.getName()); + terminal.error("ファイルの削除に失敗しました: " + f.getName()); } } @@ -655,7 +654,7 @@ private static void depend_askToCommandSender(Terminal terminal, List { int index = integer.incrementAndGet(); @@ -666,7 +665,7 @@ private static void depend_askToCommandSender(Terminal terminal, List { if (s.equalsIgnoreCase("c")) { - terminal.writeLine(ChatColor.RED + "E: キャンセルされました。"); + terminal.error("キャンセルされました。"); return; } @@ -682,7 +681,7 @@ private static void depend_askToCommandSender(Terminal terminal, List jar.size() + 1) { terminal.writeLine(ChatColor.RED + "リソースは 1 以上、" + (jar.size() + 1) + " 以下である必要があります。"); - terminal.writeLine(ChatColor.RED + "E: キャンセルされました。"); + terminal.error("キャンセルされました。"); return; } From 986e881381c145607ed47e78867ee7133bf6a4bd Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 20 Apr 2022 16:17:55 +0900 Subject: [PATCH 126/745] refactor: depend_askToCommandSender --- .../plugin/Installer.java | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 1f90b4d8..5dd0d954 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -6,6 +6,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; @@ -16,17 +17,11 @@ import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.Say2Functional; import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; @@ -37,15 +32,15 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; -import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -import java.util.stream.IntStream; @SuppressWarnings("unused") public class Installer @@ -222,15 +217,15 @@ else if (resolveResult instanceof SuccessResult) } else { - List> multi = Arrays.stream(multiResult.getResults()) - .filter(result -> result instanceof SuccessResult) - .map(result -> { - SuccessResult successResult = (SuccessResult) result; - return new Pair<>(successResult.getVersion(), successResult.getDownloadUrl()); - }).collect(Collectors.toList()); - - depend_askToCommandSender(terminal, multi, ignoreInstall, withoutResolveDepends, withoutRemove); - return new InstallResult(add, remove, modify, false); + SuccessResult result = dependAskToTerminal(terminal, multiResult); + + if (result == null) + { + terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); + return new InstallResult(add, remove, modify, false); + } + + jarURL = result.getDownloadUrl(); } } catch (IllegalArgumentException ignored) @@ -648,50 +643,58 @@ public static void delete(Terminal terminal, File f) } - private static void depend_askToCommandSender(Terminal terminal, List> jar, boolean ignoreInstall, boolean withoutResolveDepends, boolean withoutRemove) + private static HashMap buildChoicesRecursive(int count, MultiResult result) { - UUID uuid = null; - if (terminal instanceof Player) - uuid = ((Player) terminal).getUniqueId(); - - terminal.warn("リソースが複数見つかりました。インストールするリソースを選択するか、キャンセルを行ってください。"); - AtomicInteger integer = new AtomicInteger(0); - jar.forEach(pair -> { - int index = integer.incrementAndGet(); - terminal.write(Component.text(ChatColor.LIGHT_PURPLE + "- [" + index + "] " + ChatColor.GREEN + pair.getLeft()) - .clickEvent(ClickEvent.runCommand("/kpm i " + pair.getRight())) - .hoverEvent(HoverEvent.showText( - Component.text(ChatColor.GREEN + "クリックしてこのリリースをインストール")))); - - }); - terminal.write(Component.text(ChatColor.LIGHT_PURPLE + "- [C] " + ChatColor.GREEN + "キャンセル") - .clickEvent(ClickEvent.runCommand("/kpm i $-CF$")) - .hoverEvent(HoverEvent.showText( - Component.text(ChatColor.GREEN + "クリックしてこのリリースをインストール")))); - - // TODO: Replace to Question - TeamKunPluginManager.getPlugin().getFunctional().add(uuid, new Say2Functional.FunctionalEntry(StringUtils::equalsIgnoreCase, s -> { - if (s.equalsIgnoreCase("c")) + HashMap choices = new HashMap<>(); + + for (ResolveResult resolveResult : result.getResults()) + { + if (resolveResult instanceof SuccessResult) { - terminal.error("キャンセルされました。"); - return; + choices.put(count + "." + resolveResult.hashCode(), (SuccessResult) resolveResult); + continue; } - int i = Integer.parseInt(s); - if (i < 1 || i > jar.size() + 1) - { - terminal.writeLine(ChatColor.RED + "リソースは 1 以上、" + (jar.size() + 1) + " 以下である必要があります。"); - terminal.error("キャンセルされました。"); - return; - } + if (resolveResult instanceof MultiResult) + choices.putAll(buildChoicesRecursive(count + 1, (MultiResult) resolveResult)); + } + + return choices; + } + + private static SuccessResult dependAskToTerminal(Terminal terminal, MultiResult result) + { + terminal.warn("複数のリソースが見つかりました。"); + + Map hashResultMap = buildChoicesRecursive(1, result); + Map hashTextMap = hashResultMap.entrySet().stream() + .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(), entry.getValue().getFileName())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + + QuestionResult questionResult; - Pair resource = jar.get(--i); - install(terminal, resource.getRight(), ignoreInstall, withoutResolveDepends, withoutRemove, false); + try + { + questionResult = + terminal.getInput().showQuestion("インストールするリリースを選択してください。", + new AttributeChoice(hashTextMap), QuestionAttribute.CANCELLABLE + ) + .waitAndGetResult(); + } + catch (InterruptedException e) + { + terminal.error("処理が中断されました。"); + return null; + } + + if (questionResult.test(QuestionAttribute.CANCELLABLE)) + { + terminal.warn("インストールがキャンセルされました。"); + return null; + } - }, (String[]) ArrayUtils.add(IntStream.range(1, jar.size() + 1).parallel() - .mapToObj(String::valueOf) - .toArray(String[]::new), "c")) - ); + return hashResultMap.get(questionResult.getRawAnswer()); } private static String pickPluginJar(List> jar) From 2e7bc1a03599fefd14ac94c8d9aa27a8616deee0 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 20 Apr 2022 19:46:27 +0900 Subject: [PATCH 127/745] refactor: URLUtils.download -> Requests --- .../plugin/Installer.java | 69 ++++++--- .../teamkunpluginmanager/utils/URLUtils.java | 135 ------------------ 2 files changed, 46 insertions(+), 158 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 5dd0d954..207a247b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -17,7 +17,8 @@ import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -32,6 +33,8 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; @@ -236,7 +239,8 @@ else if (resolveResult instanceof SuccessResult) jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); } - Pair downloadResult; + long downloadResult; + Path downloadPath; //ダウンロード if (!withoutDownload) @@ -247,16 +251,24 @@ else if (resolveResult instanceof SuccessResult) long startTime = System.currentTimeMillis(); //ファイルをダウンロード - downloadResult = URLUtils.downloadFile(jarURL); - if (downloadResult.getLeft() == null && downloadResult.getRight().startsWith("ERROR ")) + try + { + downloadPath = Paths.get("plugins", jarURL.substring(url.lastIndexOf("/") + 1)); + downloadResult = Requests.downloadFile( + RequestContext.RequestMethod.GET, + jarURL, + downloadPath + ); + } + catch (IOException e) { - terminal.warn(downloadResult.getRight().substring(6)); - terminal.error("ファイルのダウンロードに失敗しました。"); + terminal.error("ファイルのダウンロードに失敗しました:" + e.getMessage()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } - terminal.writeLine(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadResult.getRight())); + + terminal.writeLine(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadPath.getFileName().toString())); add++; terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())) @@ -264,7 +276,10 @@ else if (resolveResult instanceof SuccessResult) .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN) + "秒で取得しました。"); } else //ダウンロードしない - downloadResult = new Pair<>(true, url); + { + downloadResult = -1; + downloadPath = Paths.get(url); + } terminal.writeLine(ChatColor.LIGHT_PURPLE + "情報を読み込み中..."); @@ -273,13 +288,13 @@ else if (resolveResult instanceof SuccessResult) try { //plugin.ymlを読み取り - description = PluginUtil.loadDescription(new File("plugins/" + downloadResult.getRight())); + description = PluginUtil.loadDescription(downloadPath.toFile()); } catch (FileNotFoundException e) //ファイルが見つからない場合はreturn { terminal.error("ファイルが見つかりませんでした。"); if (!withoutRemove) - delete(terminal, new File("plugins/" + downloadResult.getRight())); + delete(terminal, downloadPath.toFile()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); @@ -289,7 +304,7 @@ else if (resolveResult instanceof SuccessResult) { terminal.error("情報を読み込めませんでした。"); if (!withoutRemove) - delete(terminal, new File("plugins/" + downloadResult.getRight())); + delete(terminal, downloadPath.toFile()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); @@ -301,7 +316,7 @@ else if (resolveResult instanceof SuccessResult) terminal.error("このプラグインは保護されています。"); add--; if (!withoutRemove) - delete(terminal, new File("plugins/" + downloadResult.getRight())); + delete(terminal, downloadPath.toFile()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); return new InstallResult(add, remove, modify, false); } @@ -319,10 +334,10 @@ else if (resolveResult instanceof SuccessResult) //ファイルを移動 //114514.jar => YJSNPIPlugin-1.0.jar FileUtils.moveFile( - new File("plugins/" + downloadResult.getRight()), + downloadPath.toFile(), new File("plugins/" + fileName) ); - downloadResult = new Pair<>(false, fileName); + downloadPath = Paths.get("plugins/" + fileName); } catch (IOException e) { @@ -365,10 +380,10 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが { //ファイルの比較を行う terminal.writeLine(getDiffMessage(PluginUtil.getFile(plugin), false)); - terminal.writeLine(getDiffMessage(new File("plugins/" + downloadResult.getRight()), true)); + terminal.writeLine(getDiffMessage(downloadPath.toFile(), true)); terminal.writeLine("\n"); //ファイナルにコピーする。 - String fileName = downloadResult.getRight(); + String fileName = downloadPath.getFileName().toString(); try { @@ -390,7 +405,9 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが InstallResult ir = install(terminal, fileName, false, false, false, true); terminal.writeLine(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); } - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } catch (InterruptedException e) @@ -400,16 +417,18 @@ else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが } //削除 - if (!withoutRemove && new File("plugins/" + downloadResult.getRight()).exists()) - delete(terminal, new File("plugins/" + downloadResult.getRight())); + if (!withoutRemove && downloadPath.toFile().exists()) + delete(terminal, downloadPath.toFile()); terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); terminal.success(description.getFullName() + " を正常にインストールしました。"); - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } - added.add(new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true)); + added.add(new InstallResult(downloadPath.getFileName().toString(), description.getName(), add, remove, modify, true)); //==================依存関係解決処理 ここから================== @@ -509,7 +528,9 @@ else if (resolveResult instanceof SuccessResult) terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); terminal.warn(description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); terminal.writeLine(ChatColor.RED + String.join(", ", failedResolve)); - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } AtomicBoolean success = new AtomicBoolean(true); @@ -584,7 +605,9 @@ public void run() terminal.success(description.getFullName() + " を正常にインストールしました。"); /*} }.runTaskLater(TeamKunPluginManager.plugin, 10L);*/ - return new InstallResult(downloadResult.getRight(), description.getName(), add, remove, modify, true); + return new InstallResult(downloadPath.getFileName().toString(), description.getName(), + add, remove, modify, true + ); } private static String getDiffMessage(File f, boolean isNew) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java deleted file mode 100644 index 2cb6f38e..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/URLUtils.java +++ /dev/null @@ -1,135 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.UnknownHostException; -import java.nio.file.NoSuchFileException; - -public class URLUtils -{ - /** - * ファイルをだうんろーど! - * - * @param url URL - * @return ローカルのパス - */ - public static Pair downloadFile(String url) - { - return downloadFile(url, url.substring(url.lastIndexOf("/") + 1)); - } - - /** - * ファイルをだうんろーど! - * - * @param url URL - * @param fileName ファイル名 - * @return ローカルのパス - */ - public static Pair downloadFile(String url, String fileName) - { - boolean duplicateFile = false; - - if (fileName.isEmpty()) - fileName = "tmp1.jar"; - - int tryna = 0; - String original = fileName; - while (new File("plugins/" + fileName).exists()) - { - fileName = original + "." + ++tryna + ".jar"; - duplicateFile = true; - } - - tryna = 0; - - final int redirectLimit = TeamKunPluginManager.getPlugin().getPluginConfig().getInt("redirectLimit", 15); - - try - { - URL urlObj = new URL(url); - HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection(); - boolean redir; - do - { - try - { - if (tryna++ > redirectLimit) - return new Pair<>(null, "ERROR リダイレクトリミットに到達しました。"); - - connection.setRequestMethod("GET"); - connection.setInstanceFollowRedirects(false); - if (urlObj.getHost().endsWith("github.com") || urlObj.getHost().equals("raw.githubusercontent.com")) - connection.setRequestProperty( - "Authorization", - "token " + TeamKunPluginManager.getPlugin().getVault().getToken() - ); - connection.setRequestProperty("User-Agent", "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop"); - connection.connect(); - - redir = false; - if (String.valueOf(connection.getResponseCode()).startsWith("3")) - { - URL base = connection.getURL(); - String locationStr = connection.getHeaderField("Location"); - if (locationStr != null) - base = new URL(base, locationStr); - - //connection.disconnect(); - if (base != null) - { - redir = true; - connection = (HttpURLConnection) base.openConnection(); - } - } - } - catch (UnknownHostException e) - { - return new Pair<>(null, "ERROR '" + urlObj.getHost() + "' を解決できませんでした。"); - } - catch (ClassCastException e) - { - return new Pair<>(null, "ERROR プロトコルが壊れています。"); - } - catch (Exception e) - { - return new Pair<>(null, "ERROR エラー '" + e.getClass().getName() + "' が発生しました。"); - } - } - while (redir); - - File file = new File("plugins/" + fileName); - - if (!file.createNewFile()) - throw new NoSuchFileException("ファイルの作成に失敗しました。"); - - try (InputStream is = connection.getInputStream(); - OutputStream os = new FileOutputStream(file)) - { - IOUtils.copy(is, os); - } - catch (Exception e) - { - e.printStackTrace(); - file.delete(); - return new Pair<>(null, "ERROR エラー '" + e.getClass().getName() + "' が発生しました。"); - } - - - //FileUtils.copyInputStreamToFile(connection.getInputStream(), file); - return new Pair<>(duplicateFile, fileName); - } - catch (Exception e) - { - e.printStackTrace(); - return new Pair<>(false, ""); - - } - } -} From 21c979883c74273248c5d6eb13134a8a419417a7 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 20 Apr 2022 19:48:19 +0900 Subject: [PATCH 128/745] fix: Nullpo of CommandAutoRemoved --- .../lab/teamkunpluginmanager/commands/CommandAutoRemove.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 2b86896a..50cc8542 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -2,6 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; @@ -29,7 +30,7 @@ private static List removeUnusedPlugins(ArrayList removables) Plugin plugin = Bukkit.getPluginManager().getPlugin(removable); if (plugin != null) { - Installer.unInstall(null, removable, true); + Installer.unInstall(Terminals.ofConsole().quiet(), removable, true); removed.add(removable); } DependencyTree.purge(removable); From f02cdf05a8eb12306711a7b8f4ddb89cdf9bb314 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 22 Apr 2022 19:56:10 +0900 Subject: [PATCH 129/745] feat: Meta --- .../plugin/meta/PluginInstaller.java | 9 +++++++ .../plugin/meta/PluginMeta.java | 26 +++++++++++++++++++ .../plugin/meta/PluginType.java | 7 +++++ 3 files changed, 42 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java new file mode 100644 index 00000000..522f1b1d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +public enum PluginInstaller +{ + SERVER_ADMIN, + KPM_DEPENDENCY_RESOLVER, + OTHER_PLUGIN, + UNKNOWN +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java new file mode 100644 index 00000000..81542071 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java @@ -0,0 +1,26 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +import lombok.Value; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Value +public class PluginMeta +{ + @NotNull + String name; + @NotNull + PluginDescriptionFile pluginYML; + + @NotNull + PluginInstaller pluginInstaller; + @NotNull + PluginType pluginType; + + long installedIn; + boolean enable; + + @Nullable + String resolver; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java new file mode 100644 index 00000000..2cba1b38 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java @@ -0,0 +1,7 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +public enum PluginType +{ + INDEPENDENCE, + DEPENDENCY +} From fc8d2bd6117969a7a73a03ff03393de56951ac71 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 22 Apr 2022 21:41:27 +0900 Subject: [PATCH 130/745] feat: wip: new Installer --- .../plugin/installer/InstallProgress.java | 60 +++++++++++++ .../plugin/installer/InstallResult.java | 90 +++++++++++++++++++ .../plugin/installer/Installer.java | 15 ++++ .../plugin/installer/PlumbingInstaller.java | 25 ++++++ .../installer/signal/InstallerSignal.java | 5 ++ .../signal/InstallerSignalHandler.java | 9 ++ .../plugin/installer/signal/SignalType.java | 14 +++ .../signal/signals/ResolvingPluginSignal.java | 14 +++ 8 files changed, 232 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/ResolvingPluginSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java new file mode 100644 index 00000000..0810a64f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -0,0 +1,60 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public class InstallProgress +{ + private final List upgraded; + private final List installed; + private final List removed; + private final List pending; + + public InstallProgress() + { + this.upgraded = new ArrayList<>(); + this.installed = new ArrayList<>(); + this.removed = new ArrayList<>(); + this.pending = new ArrayList<>(); + } + + private void removeFromAll(@NotNull String name) + { + this.upgraded.remove(name); + this.installed.remove(name); + this.removed.remove(name); + this.pending.remove(name); + } + + public void addUpgraded(@NotNull String pluginName) + { + this.removeFromAll(pluginName); + + this.upgraded.add(pluginName); + } + + public void addInstalled(@NotNull String pluginName) + { + this.removeFromAll(pluginName); + + this.installed.add(pluginName); + } + + public void addRemoved(@NotNull String pluginName) + { + this.removeFromAll(pluginName); + + this.removed.add(pluginName); + } + + public void addPending(@NotNull String pluginName) + { + this.removeFromAll(pluginName); + + this.pending.add(pluginName); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java new file mode 100644 index 00000000..9aef2f27 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -0,0 +1,90 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.HoverEvent; +import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; + +@AllArgsConstructor +public class InstallResult +{ + private static final int MAX_RESULT_HOVER_ONE_LINE = 5; + + private final InstallProgress progress; + + private static TextComponent getResultStatusComponent(@NotNull String[] components, @NotNull String hoverPrefix) + { + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < components.length; i++) + { + if (i % MAX_RESULT_HOVER_ONE_LINE == 0) + builder.append("\n"); + + builder.append(ChatColor.AQUA) + .append("- ") + .append(components[i]); + } + + return Component.text(" " + components.length + "個") + .hoverEvent(HoverEvent.showText(Component.text(hoverPrefix + "\n" + builder))); + } + + public int getUpgradedCount() + { + return progress.getUpgraded().size(); + } + + public int getInstalledCount() + { + return progress.getInstalled().size(); + } + + public int getRemovedCount() + { + return progress.getRemoved().size(); + } + + public int getPendingCount() + { + return progress.getPending().size(); + } + + public String[] getUpgraded() + { + return progress.getUpgraded().toArray(new String[0]); + } + + public String[] getInstalled() + { + return progress.getInstalled().toArray(new String[0]); + } + + public String[] getRemoved() + { + return progress.getRemoved().toArray(new String[0]); + } + + public String[] getPending() + { + return progress.getPending().toArray(new String[0]); + } + + public void printResultStatus(@NotNull Terminal terminal) + { + TextComponent component = Component.text("") + .append(Component.text("アップグレード:") + .append(getResultStatusComponent(getUpgraded(), "アップグレードされたプラグイン"))) + .append(Component.text("、インストール:") + .append(getResultStatusComponent(getInstalled(), "インストールされたプラグイン"))) + .append(Component.text("、削除:") + .append(getResultStatusComponent(getRemoved(), "削除されたプラグイン"))) + .append(Component.text("、保留:") + .append(getResultStatusComponent(getPending(), "保留されたプラグイン"))); + + terminal.write(component); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java new file mode 100644 index 00000000..360c31c7 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; + +public class Installer +{ + private final InstallerSignalHandler signalHandler; + private final PlumbingInstaller installer; + + public Installer(InstallerSignalHandler signalHandler) + { + this.signalHandler = signalHandler; + this.installer = new PlumbingInstaller(this, signalHandler); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java new file mode 100644 index 00000000..be1cf40e --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; + +@AllArgsConstructor +class PlumbingInstaller +{ + private static final PluginResolver PLUGIN_RESOLVER; + + static + { + PLUGIN_RESOLVER = TeamKunPluginManager.getPlugin().getResolver(); + } + + private final Installer installer; + private final InstallerSignalHandler signalHandler; + + public InstallProgress initInstall() + { + return new InstallProgress(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java new file mode 100644 index 00000000..a89f2a16 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal; + +public interface InstallerSignal +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java new file mode 100644 index 00000000..dedc63dd --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal; + +import org.jetbrains.annotations.NotNull; + +@FunctionalInterface +public interface InstallerSignalHandler +{ + void handleSignal(@NotNull T signal); +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java new file mode 100644 index 00000000..61dba993 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java @@ -0,0 +1,14 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.ResolvingPluginSignal; + +@AllArgsConstructor +@Getter +public enum SignalType +{ + RESOLVING_PLUGIN(ResolvingPluginSignal.class); + + private final Class signalClass; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/ResolvingPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/ResolvingPluginSignal.java new file mode 100644 index 00000000..73d543e4 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/ResolvingPluginSignal.java @@ -0,0 +1,14 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; + +@AllArgsConstructor +@Data +public class ResolvingPluginSignal implements InstallerSignal +{ + private final PluginResolver resolver; + private String query; +} From 7989481d18584831fdf39ed7e40d782422cf463f Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 24 Apr 2022 16:57:47 +0900 Subject: [PATCH 131/745] feat: Signals and FailedResult --- .../plugin/installer/FailedReason.java | 10 +++++++++ .../installer/InstallFailedInstallResult.java | 16 ++++++++++++++ .../plugin/installer/InstallResult.java | 14 ++++++++++++- .../plugin/installer/signal/SignalType.java | 4 ++-- .../signals/MultiplePluginResolvedSignal.java | 21 +++++++++++++++++++ .../signals/PluginResolveErrorSignal.java | 13 ++++++++++++ .../PluginResolvedSuccessfulSignal.java | 15 +++++++++++++ ...Signal.java => PluginResolvingSignal.java} | 4 ++-- 8 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/MultiplePluginResolvedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolveErrorSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvedSuccessfulSignal.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/{ResolvingPluginSignal.java => PluginResolvingSignal.java} (86%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java new file mode 100644 index 00000000..304a07b1 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +public enum FailedReason +{ + // Resolving errors + GOT_ERROR_RESULT, + + // General internal errors + ILLEGAL_INTERNAL_STATE, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java new file mode 100644 index 00000000..a76c6681 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +import lombok.Getter; + +@Getter +public class InstallFailedInstallResult extends InstallResult +{ + private final FailedReason reason; + + InstallFailedInstallResult(InstallProgress progress, FailedReason reason) + { + super(false, progress); + this.reason = reason; + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java index 9aef2f27..bcc2c263 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +import lombok.AccessLevel; import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kyori.adventure.text.Component; @@ -8,13 +9,24 @@ import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; -@AllArgsConstructor +@AllArgsConstructor(access = AccessLevel.PACKAGE) public class InstallResult { private static final int MAX_RESULT_HOVER_ONE_LINE = 5; + private final boolean success; private final InstallProgress progress; + public static InstallResult success(InstallProgress progress) + { + return new InstallResult(true, progress); + } + + public static InstallFailedInstallResult error(InstallProgress progress, FailedReason reason) + { + return new InstallFailedInstallResult(progress, reason); + } + private static TextComponent getResultStatusComponent(@NotNull String[] components, @NotNull String hoverPrefix) { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java index 61dba993..78cc43e2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java @@ -2,13 +2,13 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.ResolvingPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.PluginResolvingSignal; @AllArgsConstructor @Getter public enum SignalType { - RESOLVING_PLUGIN(ResolvingPluginSignal.class); + RESOLVING_PLUGIN(PluginResolvingSignal.class); private final Class signalClass; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/MultiplePluginResolvedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/MultiplePluginResolvedSignal.java new file mode 100644 index 00000000..f09509af --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/MultiplePluginResolvedSignal.java @@ -0,0 +1,21 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Data +public class MultiplePluginResolvedSignal implements InstallerSignal +{ + @NotNull + private final String query; + + @NotNull + private final MultiResult results; + + @Nullable + private ResolveResult specifiedResult; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolveErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolveErrorSignal.java new file mode 100644 index 00000000..e3abe943 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolveErrorSignal.java @@ -0,0 +1,13 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; + +import lombok.Data; +import lombok.NonNull; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; + +@Data +public class PluginResolveErrorSignal implements InstallerSignal +{ + @NonNull + private final ErrorResult error; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvedSuccessfulSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvedSuccessfulSignal.java new file mode 100644 index 00000000..b141df22 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvedSuccessfulSignal.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import org.jetbrains.annotations.NotNull; + +@AllArgsConstructor +@Data +public class PluginResolvedSuccessfulSignal implements InstallerSignal +{ + @NotNull + private SuccessResult resolvedPlugin; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/ResolvingPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvingSignal.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/ResolvingPluginSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvingSignal.java index 73d543e4..08bd0d32 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/ResolvingPluginSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvingSignal.java @@ -7,8 +7,8 @@ @AllArgsConstructor @Data -public class ResolvingPluginSignal implements InstallerSignal +public class PluginResolvingSignal implements InstallerSignal { - private final PluginResolver resolver; private String query; + private final PluginResolver resolver; } From 7a8a775ceff62aa66a98624a4c2405603bfa416e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 24 Apr 2022 17:06:01 +0900 Subject: [PATCH 132/745] feat: InstallPhase --- .../plugin/installer/InstallPhase.java | 9 +++++++++ .../plugin/installer/InstallProgress.java | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java new file mode 100644 index 00000000..c6fb794c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +public enum InstallPhase +{ + // General phases + STARTED, + INITIALIZING, + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 0810a64f..355f7e7c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -9,6 +10,9 @@ @Getter public class InstallProgress { + @Setter + private InstallPhase phase; + private final List upgraded; private final List installed; private final List removed; @@ -20,6 +24,8 @@ public InstallProgress() this.installed = new ArrayList<>(); this.removed = new ArrayList<>(); this.pending = new ArrayList<>(); + + this.phase = InstallPhase.STARTED; } private void removeFromAll(@NotNull String name) From a26f7bb5a8fe8f486115afc5533e7efceae9a928 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 24 Apr 2022 18:28:18 +0900 Subject: [PATCH 133/745] refactor: signals/ -> signals/install --- .../plugin/installer/signal/SignalType.java | 14 -------------- .../MultiplePluginResolvedSignal.java | 2 +- .../{ => resolve}/PluginResolveErrorSignal.java | 2 +- .../PluginResolvedSuccessfulSignal.java | 2 +- .../{ => resolve}/PluginResolvingSignal.java | 2 +- 5 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/{ => resolve}/MultiplePluginResolvedSignal.java (96%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/{ => resolve}/PluginResolveErrorSignal.java (95%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/{ => resolve}/PluginResolvedSuccessfulSignal.java (95%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/{ => resolve}/PluginResolvingSignal.java (95%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java deleted file mode 100644 index 78cc43e2..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/SignalType.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.PluginResolvingSignal; - -@AllArgsConstructor -@Getter -public enum SignalType -{ - RESOLVING_PLUGIN(PluginResolvingSignal.class); - - private final Class signalClass; -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/MultiplePluginResolvedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/MultiplePluginResolvedSignal.java similarity index 96% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/MultiplePluginResolvedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/MultiplePluginResolvedSignal.java index f09509af..502d1864 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/MultiplePluginResolvedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/MultiplePluginResolvedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolveErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolveErrorSignal.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolveErrorSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolveErrorSignal.java index e3abe943..4c55be1a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolveErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolveErrorSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; import lombok.Data; import lombok.NonNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvedSuccessfulSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvedSuccessfulSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java index b141df22..338d44e8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvedSuccessfulSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java index 08bd0d32..4465b6b0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/PluginResolvingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; import lombok.AllArgsConstructor; import lombok.Data; From 7f9af4bbb124ec0c773f2693b2e8b93eef10bfa2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 25 Apr 2022 22:19:19 +0900 Subject: [PATCH 134/745] refactor: Extract RequestMethod to outer. --- .../net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 207a247b..cc9b2e6d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -17,7 +17,7 @@ import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -255,7 +255,7 @@ else if (resolveResult instanceof SuccessResult) { downloadPath = Paths.get("plugins", jarURL.substring(url.lastIndexOf("/") + 1)); downloadResult = Requests.downloadFile( - RequestContext.RequestMethod.GET, + RequestMethod.GET, jarURL, downloadPath ); From b8dc901ee5d37044096affe79890adc47d131774 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 26 Apr 2022 19:04:18 +0900 Subject: [PATCH 135/745] feat: wip: installer: Download plugin --- .../plugin/installer/FailedReason.java | 5 + .../plugin/installer/InstallPhase.java | 6 + .../plugin/installer/InstallProgress.java | 47 ++++- .../plugin/installer/InstallResult.java | 4 +- .../plugin/installer/Installer.java | 54 ++++- .../plugin/installer/PlumbingInstaller.java | 197 +++++++++++++++++- .../signals/download/DownloadErrorCause.java | 27 +++ .../signals/download/DownloadErrorSignal.java | 23 ++ .../download/DownloadProgressSignal.java | 25 +++ .../signals/download/DownloadSignal.java | 18 ++ .../download/DownloadStartedSignal.java | 25 +++ .../download/DownloadSucceedSignal.java | 23 ++ 12 files changed, 442 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java index 304a07b1..9fb8347e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java @@ -5,6 +5,11 @@ public enum FailedReason // Resolving errors GOT_ERROR_RESULT, + // Net errors + ILLEGAL_RESPONSE_CODE, + NO_RESPONSE_BODY, + // General internal errors ILLEGAL_INTERNAL_STATE, + IO_EXCEPTION_OCCURRED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java index c6fb794c..deb406cd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java @@ -6,4 +6,10 @@ public enum InstallPhase STARTED, INITIALIZING, + // Install phases + QUERY_RESOLVING, + MULTIPLE_RESULT_RESOLVING, + START_DOWNLOADING, + DOWNLOADING + } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 355f7e7c..f8862c7a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -2,10 +2,15 @@ import lombok.Getter; import lombok.Setter; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import org.jetbrains.annotations.NotNull; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.UUID; @Getter public class InstallProgress @@ -18,7 +23,10 @@ public class InstallProgress private final List removed; private final List pending; - public InstallProgress() + private final UUID installActionID; + private final Path installTempDir; + + public InstallProgress(boolean createTempDir) throws IOException, SecurityException { this.upgraded = new ArrayList<>(); this.installed = new ArrayList<>(); @@ -26,6 +34,31 @@ public InstallProgress() this.pending = new ArrayList<>(); this.phase = InstallPhase.STARTED; + + this.installActionID = UUID.randomUUID(); + + if (!createTempDir) + { + this.installTempDir = null; + return; + } + + this.installTempDir = Files.createTempDirectory( + TeamKunPluginManager.getPlugin().getDataFolder().toPath(), + this.getInstallActionID().toString() + ); + } + + public static InstallProgress dummy() + { + try + { + return new InstallProgress(false); + } + catch (IOException e) + { // should not happen + throw new IllegalStateException(e); + } } private void removeFromAll(@NotNull String name) @@ -63,4 +96,16 @@ public void addPending(@NotNull String pluginName) this.pending.add(pluginName); } + + public void finish() + { + try + { + Files.deleteIfExists(this.installTempDir); + } + catch (IOException e) + { + e.printStackTrace(); + } + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java index bcc2c263..2147b81b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -19,11 +19,13 @@ public class InstallResult public static InstallResult success(InstallProgress progress) { + progress.finish(); return new InstallResult(true, progress); } public static InstallFailedInstallResult error(InstallProgress progress, FailedReason reason) - { + { // TODO: Implement debug mode + progress.finish(); return new InstallFailedInstallResult(progress, reason); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java index 360c31c7..8f4b2fbf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java @@ -1,15 +1,57 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolvedSuccessfulSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; + +import java.io.IOException; public class Installer { - private final InstallerSignalHandler signalHandler; - private final PlumbingInstaller installer; - - public Installer(InstallerSignalHandler signalHandler) + public static InstallResult installPlugin(String query, InstallerSignalHandler signalHandler) { - this.signalHandler = signalHandler; - this.installer = new PlumbingInstaller(this, signalHandler); + PlumbingInstaller internal; + InstallProgress progress; + + // region Initialize install. Phase: INITIALIZING + try + { + internal = PlumbingInstaller.initInstall(signalHandler); + progress = internal.getProgress(); + } + catch (IOException | SecurityException e) + { + return InstallResult.error(InstallProgress.dummy(), FailedReason.IO_EXCEPTION_OCCURRED); + } + + // endregion + + // region Query resolving. Phase: QUERY_RESOLVING, MULTIPLE_RESULT_RESOLVING => QUERY_RESOLVING + progress.setPhase(InstallPhase.QUERY_RESOLVING); + + ResolveResult queryResolveResult = internal.resolvePlugin(query); + queryResolveResult = internal.normalizeResolveResult(query, queryResolveResult); + + InstallResult mayQueryError = internal.checkResolveError(queryResolveResult); + if (mayQueryError != null) + return mayQueryError; + + assert queryResolveResult != null; // if queryResolveResult is null, mayQueryError must not be null. + + signalHandler.handleSignal(new PluginResolvedSuccessfulSignal((SuccessResult) queryResolveResult)); + // endregion + + SuccessResult resolvedPlugin = (SuccessResult) queryResolveResult; + + // region Downloading. Phase: START_DOWNLOADING=>DOWNLOADING + progress.setPhase(InstallPhase.START_DOWNLOADING); + + PlumbingInstaller.DownloadResult downloadResult = internal.downloadJar(progress, resolvedPlugin); + + if (!downloadResult.isSuccess()) + return InstallResult.error(progress, downloadResult.getDownloadFailedReason()); + + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java index be1cf40e..151794df 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java @@ -1,11 +1,36 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadStartedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadSucceedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.MultiplePluginResolvedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolveErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolvingSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -@AllArgsConstructor +import java.io.IOException; +import java.nio.file.Path; +import java.util.UUID; +import java.util.function.Consumer; + +@AllArgsConstructor(access = AccessLevel.PRIVATE) class PlumbingInstaller { private static final PluginResolver PLUGIN_RESOLVER; @@ -15,11 +40,175 @@ class PlumbingInstaller PLUGIN_RESOLVER = TeamKunPluginManager.getPlugin().getResolver(); } - private final Installer installer; private final InstallerSignalHandler signalHandler; - public InstallProgress initInstall() + @Getter + private final InstallProgress progress; + + public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler) + throws IOException, SecurityException + { + + InstallProgress progress = new InstallProgress(true); + + PlumbingInstaller instance = new PlumbingInstaller(signalHandler, progress); + + progress.setPhase(InstallPhase.INITIALIZING); + return instance; + } + + public @NotNull ResolveResult resolvePlugin(@NotNull String query) + { + this.signalHandler.handleSignal(new PluginResolvingSignal(query, PLUGIN_RESOLVER)); + + return PLUGIN_RESOLVER.resolve(query); + } + + public @Nullable ResolveResult resolveMultipleResults(@NotNull String query, @NotNull MultiResult results) + { + if (results.getResults().length < 1) + throw new IllegalStateException("MultiResult with no results."); + + MultiplePluginResolvedSignal signal = new MultiplePluginResolvedSignal(query, results); + this.signalHandler.handleSignal(signal); + + if (signal.getSpecifiedResult() != null) + return signal.getSpecifiedResult(); // Plugin actually resolved by SignalHandler. + + ResolveResult result = results.getResults()[0]; + + if (result instanceof MultiResult) + { + MultiResult multiResult = (MultiResult) result; + return this.resolveMultipleResults(query, multiResult); // Recursive call. + } + + return result; + } + + public @NotNull DownloadResult downloadJar(@NotNull InstallProgress progress, @NotNull SuccessResult resolveResult) + { + UUID downloadID = progress.getInstallActionID(); + + DownloadStartedSignal downloadingSignal = new DownloadStartedSignal( + downloadID, + progress.getInstallTempDir().resolve(progress.getInstallActionID().toString() + ".jar"), + resolveResult.getDownloadUrl() + ); + + this.signalHandler.handleSignal(downloadingSignal); // SignalHandler can change the download URL and download path. + + Path path = downloadingSignal.getDownloadPath(); + String url = downloadingSignal.getUrl(); + + try + { + long size = Requests.downloadFile(RequestMethod.GET, url, path, new DownloadProgressConsumer(downloadID)); + + this.signalHandler.handleSignal(new DownloadSucceedSignal(downloadID, path, size)); + + return new DownloadResult(path, true, size, null); // downloadFailedReason is null. + } + catch (IOException e) + { + DownloadErrorCause cause; + Object signalValue; + + if (e.getMessage().startsWith("HTTP error ")) + { + cause = DownloadErrorCause.ILLEGAL_HTTP_RESPONSE; + signalValue = e.getMessage().substring(11); + } + else if (e.getMessage().startsWith("No response body was returned")) + { + cause = DownloadErrorCause.NO_BODY_IN_RESPONSE; + signalValue = null; + } + else + { + cause = DownloadErrorCause.IO_EXCEPTION; + signalValue = e; + } + + DownloadErrorSignal error = new DownloadErrorSignal(downloadID, cause, signalValue); + this.signalHandler.handleSignal(error); + + return new DownloadResult(null, false, -1, cause.toFailedReason()); + } + catch (Exception e) + { + this.signalHandler.handleSignal(new DownloadErrorSignal(downloadID, DownloadErrorCause.UNKNOWN_ERROR, e)); + + return new DownloadResult(null, false, -1, DownloadErrorCause.UNKNOWN_ERROR.toFailedReason()); + } + } + + public @Nullable ResolveResult normalizeResolveResult(@NotNull String query, @NotNull ResolveResult queryResolveResult) { - return new InstallProgress(); + if (queryResolveResult instanceof ErrorResult) + { + this.signalHandler.handleSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); + return null; + } + else if (queryResolveResult instanceof MultiResult) + { + this.progress.setPhase(InstallPhase.MULTIPLE_RESULT_RESOLVING); + + MultiResult multiResult = (MultiResult) queryResolveResult; + ResolveResult actualResolveResult = this.resolveMultipleResults(query, multiResult); + + if (actualResolveResult instanceof ErrorResult) + { + // MultiResult has been resolved, but the actual result is an error + this.signalHandler.handleSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); + return null; + } + + // MultiResult has been resolved, and the actual result is a SuccessResult + // (resolveMultipleResults() should not return a MultiResult) + + this.progress.setPhase(InstallPhase.QUERY_RESOLVING); // Reset to QUERY_RESOLVING from MULTIPLE_RESULT_RESOLVING + + return actualResolveResult; + } + else + return queryResolveResult; + } + + public @Nullable InstallResult checkResolveError(@Nullable ResolveResult resolveResult) + { + if (resolveResult == null) // normalizeResolveResult() returns null if the ResolveResult is error. + return InstallResult.error(progress, FailedReason.GOT_ERROR_RESULT); + if (!(resolveResult instanceof SuccessResult)) // Should never happen + return InstallResult.error(progress, FailedReason.ILLEGAL_INTERNAL_STATE); + + return null; + } + + @Value + public static class DownloadResult + { + Path path; + boolean success; + long totalSize; + + FailedReason downloadFailedReason; + } + + @Value + private class DownloadProgressConsumer implements Consumer + { + UUID installID; + + @Override + public void accept(DownloadProgress downloadProgress) + { + PlumbingInstaller.this.signalHandler.handleSignal(new DownloadProgressSignal( + installID, + downloadProgress.getTotalSize(), + downloadProgress.getDownloaded(), + downloadProgress.getPercentage() + )); + } } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorCause.java new file mode 100644 index 00000000..c9cb6417 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorCause.java @@ -0,0 +1,27 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; + +public enum DownloadErrorCause +{ + ILLEGAL_HTTP_RESPONSE, + NO_BODY_IN_RESPONSE, + IO_EXCEPTION, + UNKNOWN_ERROR; + + public FailedReason toFailedReason() + { + switch (this) + { + case ILLEGAL_HTTP_RESPONSE: + return FailedReason.ILLEGAL_RESPONSE_CODE; + case NO_BODY_IN_RESPONSE: + return FailedReason.NO_RESPONSE_BODY; + case IO_EXCEPTION: + return FailedReason.IO_EXCEPTION_OCCURRED; + case UNKNOWN_ERROR: + default: + return FailedReason.ILLEGAL_INTERNAL_STATE; + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java new file mode 100644 index 00000000..4614bd7e --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; + +import java.util.UUID; + +@EqualsAndHashCode(callSuper = true) +@Value +public class DownloadErrorSignal extends DownloadSignal implements InstallerSignal +{ + DownloadErrorCause cause; + Object value; + + public DownloadErrorSignal(UUID downloadId, DownloadErrorCause cause, Object value) + { + super(downloadId); + this.cause = cause; + this.value = value; + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java new file mode 100644 index 00000000..350bb3b1 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; + +import java.util.UUID; + +@EqualsAndHashCode(callSuper = true) +@Value +public class DownloadProgressSignal extends DownloadSignal implements InstallerSignal +{ + long totalSize; + long downloaded; + + double percentage; + + public DownloadProgressSignal(UUID downloadId, long totalSize, long downloaded, double percentage) + { + super(downloadId); + this.totalSize = totalSize; + this.downloaded = downloaded; + this.percentage = percentage; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java new file mode 100644 index 00000000..2c51df28 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java @@ -0,0 +1,18 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +import java.util.UUID; + +@EqualsAndHashCode +public abstract class DownloadSignal +{ + @Getter + private final UUID downloadId; + + public DownloadSignal(UUID downloadId) + { + this.downloadId = downloadId; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java new file mode 100644 index 00000000..71f46b94 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; + +import java.nio.file.Path; +import java.util.UUID; + +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +public class DownloadStartedSignal extends DownloadSignal implements InstallerSignal +{ + private Path downloadPath; + private String url; + + public DownloadStartedSignal(UUID downloadId, Path downloadPath, String url) + { + super(downloadId); + this.downloadPath = downloadPath; + this.url = url; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java new file mode 100644 index 00000000..d473d510 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; + +import java.nio.file.Path; +import java.util.UUID; + +@EqualsAndHashCode(callSuper = true) +@Value +public class DownloadSucceedSignal extends DownloadSignal implements InstallerSignal +{ + Path downloadPath; + long totalSize; + + public DownloadSucceedSignal(UUID downloadId, Path downloadPath, long totalSize) + { + super(downloadId); + this.downloadPath = downloadPath; + this.totalSize = totalSize; + } +} From 6bfa8ef870854572548273f2323ef28197bcbc55 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 26 Apr 2022 19:21:46 +0900 Subject: [PATCH 136/745] refactor: wip: installer: Remove DownloadSignal and remove downloadID --- .../plugin/installer/PlumbingInstaller.java | 43 +++++++------------ .../signals/download/DownloadErrorSignal.java | 18 +++----- .../download/DownloadProgressSignal.java | 14 +----- .../signals/download/DownloadSignal.java | 18 -------- .../download/DownloadStartedSignal.java | 25 ----------- .../download/DownloadStartingSignal.java | 16 +++++++ .../download/DownloadSucceedSignal.java | 10 ++--- .../PluginResolvedSuccessfulSignal.java | 2 - .../resolve/PluginResolvingSignal.java | 2 - 9 files changed, 41 insertions(+), 107 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartingSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java index 151794df..9421ad4e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java @@ -9,7 +9,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadStartedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadStartingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadSucceedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.MultiplePluginResolvedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolveErrorSignal; @@ -27,8 +27,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.UUID; -import java.util.function.Consumer; @AllArgsConstructor(access = AccessLevel.PRIVATE) class PlumbingInstaller @@ -86,12 +84,18 @@ public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler return result; } - public @NotNull DownloadResult downloadJar(@NotNull InstallProgress progress, @NotNull SuccessResult resolveResult) + private void onDownload(DownloadProgress downloadProgress) { - UUID downloadID = progress.getInstallActionID(); + PlumbingInstaller.this.signalHandler.handleSignal(new DownloadProgressSignal( + downloadProgress.getTotalSize(), + downloadProgress.getDownloaded(), + downloadProgress.getPercentage() + )); + } - DownloadStartedSignal downloadingSignal = new DownloadStartedSignal( - downloadID, + public @NotNull DownloadResult downloadJar(@NotNull InstallProgress progress, @NotNull SuccessResult resolveResult) + { + DownloadStartingSignal downloadingSignal = new DownloadStartingSignal( progress.getInstallTempDir().resolve(progress.getInstallActionID().toString() + ".jar"), resolveResult.getDownloadUrl() ); @@ -103,9 +107,9 @@ public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler try { - long size = Requests.downloadFile(RequestMethod.GET, url, path, new DownloadProgressConsumer(downloadID)); + long size = Requests.downloadFile(RequestMethod.GET, url, path, this::onDownload); - this.signalHandler.handleSignal(new DownloadSucceedSignal(downloadID, path, size)); + this.signalHandler.handleSignal(new DownloadSucceedSignal(path, size)); return new DownloadResult(path, true, size, null); // downloadFailedReason is null. } @@ -130,14 +134,14 @@ else if (e.getMessage().startsWith("No response body was returned")) signalValue = e; } - DownloadErrorSignal error = new DownloadErrorSignal(downloadID, cause, signalValue); + DownloadErrorSignal error = new DownloadErrorSignal(cause, signalValue); this.signalHandler.handleSignal(error); return new DownloadResult(null, false, -1, cause.toFailedReason()); } catch (Exception e) { - this.signalHandler.handleSignal(new DownloadErrorSignal(downloadID, DownloadErrorCause.UNKNOWN_ERROR, e)); + this.signalHandler.handleSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, e)); return new DownloadResult(null, false, -1, DownloadErrorCause.UNKNOWN_ERROR.toFailedReason()); } @@ -194,21 +198,4 @@ public static class DownloadResult FailedReason downloadFailedReason; } - - @Value - private class DownloadProgressConsumer implements Consumer - { - UUID installID; - - @Override - public void accept(DownloadProgress downloadProgress) - { - PlumbingInstaller.this.signalHandler.handleSignal(new DownloadProgressSignal( - installID, - downloadProgress.getTotalSize(), - downloadProgress.getDownloaded(), - downloadProgress.getPercentage() - )); - } - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java index 4614bd7e..22385917 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java @@ -1,23 +1,15 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; -import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.UUID; - -@EqualsAndHashCode(callSuper = true) @Value -public class DownloadErrorSignal extends DownloadSignal implements InstallerSignal +public class DownloadErrorSignal implements InstallerSignal { + @NotNull DownloadErrorCause cause; + @Nullable Object value; - - public DownloadErrorSignal(UUID downloadId, DownloadErrorCause cause, Object value) - { - super(downloadId); - this.cause = cause; - this.value = value; - } - } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java index 350bb3b1..f033ef8c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java @@ -1,25 +1,13 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; -import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; -import java.util.UUID; - -@EqualsAndHashCode(callSuper = true) @Value -public class DownloadProgressSignal extends DownloadSignal implements InstallerSignal +public class DownloadProgressSignal implements InstallerSignal { long totalSize; long downloaded; double percentage; - - public DownloadProgressSignal(UUID downloadId, long totalSize, long downloaded, double percentage) - { - super(downloadId); - this.totalSize = totalSize; - this.downloaded = downloaded; - this.percentage = percentage; - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java deleted file mode 100644 index 2c51df28..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSignal.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; - -import lombok.EqualsAndHashCode; -import lombok.Getter; - -import java.util.UUID; - -@EqualsAndHashCode -public abstract class DownloadSignal -{ - @Getter - private final UUID downloadId; - - public DownloadSignal(UUID downloadId) - { - this.downloadId = downloadId; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java deleted file mode 100644 index 71f46b94..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartedSignal.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; - -import java.nio.file.Path; -import java.util.UUID; - -@EqualsAndHashCode(callSuper = true) -@Getter -@Setter -public class DownloadStartedSignal extends DownloadSignal implements InstallerSignal -{ - private Path downloadPath; - private String url; - - public DownloadStartedSignal(UUID downloadId, Path downloadPath, String url) - { - super(downloadId); - this.downloadPath = downloadPath; - this.url = url; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartingSignal.java new file mode 100644 index 00000000..e396371e --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartingSignal.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +@Data +public class DownloadStartingSignal implements InstallerSignal +{ + @NotNull + private Path downloadPath; + @NotNull + private String url; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java index d473d510..bc448ea9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java @@ -1,22 +1,20 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; -import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import org.jetbrains.annotations.NotNull; import java.nio.file.Path; -import java.util.UUID; -@EqualsAndHashCode(callSuper = true) @Value -public class DownloadSucceedSignal extends DownloadSignal implements InstallerSignal +public class DownloadSucceedSignal implements InstallerSignal { + @NotNull Path downloadPath; long totalSize; - public DownloadSucceedSignal(UUID downloadId, Path downloadPath, long totalSize) + public DownloadSucceedSignal(@NotNull Path downloadPath, long totalSize) { - super(downloadId); this.downloadPath = downloadPath; this.totalSize = totalSize; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java index 338d44e8..3e354483 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java @@ -1,12 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; -import lombok.AllArgsConstructor; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; -@AllArgsConstructor @Data public class PluginResolvedSuccessfulSignal implements InstallerSignal { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java index 4465b6b0..b2bba450 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java @@ -1,11 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; -import lombok.AllArgsConstructor; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -@AllArgsConstructor @Data public class PluginResolvingSignal implements InstallerSignal { From daa5dc68cb322eda2a6195b4ae8c31640e54a5ea Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 26 Apr 2022 19:30:58 +0900 Subject: [PATCH 137/745] feat: wip: installer: InstallProgress on Signal --- .../plugin/installer/Installer.java | 2 +- .../plugin/installer/PlumbingInstaller.java | 24 ++++++++++++------- .../signal/InstallerSignalHandler.java | 3 ++- .../resolve/PluginResolvingSignal.java | 2 ++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java index 8f4b2fbf..46d37c6d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java @@ -39,7 +39,7 @@ public static InstallResult installPlugin(String query, InstallerSignalHandler s assert queryResolveResult != null; // if queryResolveResult is null, mayQueryError must not be null. - signalHandler.handleSignal(new PluginResolvedSuccessfulSignal((SuccessResult) queryResolveResult)); + internal.postSignal(new PluginResolvedSuccessfulSignal((SuccessResult) queryResolveResult)); // endregion SuccessResult resolvedPlugin = (SuccessResult) queryResolveResult; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java index 9421ad4e..0af9bfb1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorSignal; @@ -43,6 +44,11 @@ class PlumbingInstaller @Getter private final InstallProgress progress; + public void postSignal(@NotNull InstallerSignal signal) + { + this.signalHandler.handleSignal(this.progress, signal); + } + public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler) throws IOException, SecurityException { @@ -57,7 +63,7 @@ public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler public @NotNull ResolveResult resolvePlugin(@NotNull String query) { - this.signalHandler.handleSignal(new PluginResolvingSignal(query, PLUGIN_RESOLVER)); + this.postSignal(new PluginResolvingSignal(query, PLUGIN_RESOLVER)); return PLUGIN_RESOLVER.resolve(query); } @@ -68,7 +74,7 @@ public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler throw new IllegalStateException("MultiResult with no results."); MultiplePluginResolvedSignal signal = new MultiplePluginResolvedSignal(query, results); - this.signalHandler.handleSignal(signal); + this.postSignal(signal); if (signal.getSpecifiedResult() != null) return signal.getSpecifiedResult(); // Plugin actually resolved by SignalHandler. @@ -86,7 +92,7 @@ public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler private void onDownload(DownloadProgress downloadProgress) { - PlumbingInstaller.this.signalHandler.handleSignal(new DownloadProgressSignal( + PlumbingInstaller.this.postSignal(new DownloadProgressSignal( downloadProgress.getTotalSize(), downloadProgress.getDownloaded(), downloadProgress.getPercentage() @@ -100,7 +106,7 @@ private void onDownload(DownloadProgress downloadProgress) resolveResult.getDownloadUrl() ); - this.signalHandler.handleSignal(downloadingSignal); // SignalHandler can change the download URL and download path. + this.postSignal(downloadingSignal); // SignalHandler can change the download URL and download path. Path path = downloadingSignal.getDownloadPath(); String url = downloadingSignal.getUrl(); @@ -109,7 +115,7 @@ private void onDownload(DownloadProgress downloadProgress) { long size = Requests.downloadFile(RequestMethod.GET, url, path, this::onDownload); - this.signalHandler.handleSignal(new DownloadSucceedSignal(path, size)); + this.postSignal(new DownloadSucceedSignal(path, size)); return new DownloadResult(path, true, size, null); // downloadFailedReason is null. } @@ -135,13 +141,13 @@ else if (e.getMessage().startsWith("No response body was returned")) } DownloadErrorSignal error = new DownloadErrorSignal(cause, signalValue); - this.signalHandler.handleSignal(error); + this.postSignal(error); return new DownloadResult(null, false, -1, cause.toFailedReason()); } catch (Exception e) { - this.signalHandler.handleSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, e)); + this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, e)); return new DownloadResult(null, false, -1, DownloadErrorCause.UNKNOWN_ERROR.toFailedReason()); } @@ -151,7 +157,7 @@ else if (e.getMessage().startsWith("No response body was returned")) { if (queryResolveResult instanceof ErrorResult) { - this.signalHandler.handleSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); + this.postSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); return null; } else if (queryResolveResult instanceof MultiResult) @@ -164,7 +170,7 @@ else if (queryResolveResult instanceof MultiResult) if (actualResolveResult instanceof ErrorResult) { // MultiResult has been resolved, but the actual result is an error - this.signalHandler.handleSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); + this.postSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); return null; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java index dedc63dd..e07466d7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java @@ -1,9 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import org.jetbrains.annotations.NotNull; @FunctionalInterface public interface InstallerSignalHandler { - void handleSignal(@NotNull T signal); + void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java index b2bba450..004eb4d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java @@ -1,10 +1,12 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; +import lombok.AllArgsConstructor; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; @Data +@AllArgsConstructor public class PluginResolvingSignal implements InstallerSignal { private String query; From 3a06c9c70959c3926c731884967ee3676c9f056e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 28 Apr 2022 15:46:08 +0900 Subject: [PATCH 138/745] feat: wip: installer: Plugin yaml loading --- .../plugin/installer/FailedReason.java | 4 +++ .../plugin/installer/InstallPhase.java | 3 +- .../plugin/installer/Installer.java | 31 +++++++++++++++++++ .../plugin/LoadPluginDescriptionSignal.java | 16 ++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/plugin/LoadPluginDescriptionSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java index 9fb8347e..856a4844 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java @@ -9,6 +9,10 @@ public enum FailedReason ILLEGAL_RESPONSE_CODE, NO_RESPONSE_BODY, + // Installing errors + INVALID_PLUGIN_DESCRIPTION, + NOT_A_PLUGIN, + // General internal errors ILLEGAL_INTERNAL_STATE, IO_EXCEPTION_OCCURRED, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java index deb406cd..85e90d96 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java @@ -10,6 +10,7 @@ public enum InstallPhase QUERY_RESOLVING, MULTIPLE_RESULT_RESOLVING, START_DOWNLOADING, - DOWNLOADING + DOWNLOADING, + LOADING_PLUGIN_DESCRIPTION } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java index 46d37c6d..705df19f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java @@ -1,9 +1,13 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.plugin.LoadPluginDescriptionSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolvedSuccessfulSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.PluginDescriptionFile; import java.io.IOException; @@ -52,6 +56,33 @@ public static InstallResult installPlugin(String query, InstallerSignalHandler s if (!downloadResult.isSuccess()) return InstallResult.error(progress, downloadResult.getDownloadFailedReason()); + // endregion + + // region Load plugin.yml. Phase: LOADING_PLUGIN_DESCRIPTION + progress.setPhase(InstallPhase.LOADING_PLUGIN_DESCRIPTION); + internal.postSignal(new LoadPluginDescriptionSignal(downloadResult.getPath())); + + PluginDescriptionFile pluginYml; + + try + { + pluginYml = PluginUtil.loadDescription(downloadResult.getPath().toFile()); + } + catch (InvalidDescriptionException e) + { + if (e.getMessage().equals("This file isn't plugin.")) + return InstallResult.error(progress, FailedReason.NOT_A_PLUGIN); + else + return InstallResult.error(progress, FailedReason.INVALID_PLUGIN_DESCRIPTION); + } + catch (IOException e) + { + e.printStackTrace(); + return InstallResult.error(progress, FailedReason.IO_EXCEPTION_OCCURRED); + } + + // endregion + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/plugin/LoadPluginDescriptionSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/plugin/LoadPluginDescriptionSignal.java new file mode 100644 index 00000000..87b3adde --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/plugin/LoadPluginDescriptionSignal.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.plugin; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +@Data +@AllArgsConstructor +public class LoadPluginDescriptionSignal implements InstallerSignal +{ + @NotNull + private Path pluginFile; +} From 599c1f06b3da6b0bb54fd73c5aab0b2abce7b63d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 29 Apr 2022 19:50:40 +0900 Subject: [PATCH 139/745] feat: wip: installer: Phases --- .../installer/InstallFailedInstallResult.java | 15 +- .../{InstallPhase.java => InstallPhases.java} | 4 +- .../plugin/installer/InstallProgress.java | 4 +- .../plugin/installer/InstallResult.java | 12 +- .../plugin/installer/Installer.java | 82 +++---- .../plugin/installer/PlumbingInstaller.java | 207 ------------------ .../plugin/installer/phase/InstallPhase.java | 23 ++ .../plugin/installer/phase/PhaseArgument.java | 5 + .../plugin/installer/phase/PhaseEnum.java | 5 + .../plugin/installer/phase/PhaseResult.java | 20 ++ .../description/DescriptionLoadArgument.java | 23 ++ .../description/DescriptionLoadPhase.java | 55 +++++ .../description/DescriptionLoadResult.java | 22 ++ .../description/DescriptionLoadState.java | 10 + .../phases/download/DownloadArgument.java | 21 ++ .../phase/phases/download/DownloadPhase.java | 98 +++++++++ .../phase/phases/download/DownloadResult.java | 30 +++ .../phase/phases/download/DownloadState.java | 11 + .../phases/resolve/PluginResolveArgument.java | 12 + .../phases/resolve/PluginResolvePhase.java | 103 +++++++++ .../phases/resolve/PluginResolveResult.java | 28 +++ .../phases/resolve/PluginResolveState.java | 15 ++ 22 files changed, 544 insertions(+), 261 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{InstallPhase.java => InstallPhases.java} (72%) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index a76c6681..245e4b52 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -1,16 +1,29 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @Getter public class InstallFailedInstallResult extends InstallResult { + @NotNull private final FailedReason reason; + @Nullable + private final PhaseEnum phaseStatus; - InstallFailedInstallResult(InstallProgress progress, FailedReason reason) + InstallFailedInstallResult(@NotNull InstallProgress progress, @NotNull FailedReason reason, @NotNull PhaseEnum phaseStatus) { super(false, progress); this.reason = reason; + this.phaseStatus = phaseStatus; } + public InstallFailedInstallResult(InstallProgress progress, @NotNull FailedReason reason) + { + super(false, progress); + this.reason = reason; + this.phaseStatus = null; + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhases.java similarity index 72% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhases.java index 85e90d96..4fca778a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhases.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; -public enum InstallPhase +public enum InstallPhases { // General phases STARTED, @@ -8,8 +8,6 @@ public enum InstallPhase // Install phases QUERY_RESOLVING, - MULTIPLE_RESULT_RESOLVING, - START_DOWNLOADING, DOWNLOADING, LOADING_PLUGIN_DESCRIPTION diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index f8862c7a..7d6b4e64 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -16,7 +16,7 @@ public class InstallProgress { @Setter - private InstallPhase phase; + private InstallPhases phase; private final List upgraded; private final List installed; @@ -33,7 +33,7 @@ public InstallProgress(boolean createTempDir) throws IOException, SecurityExcept this.removed = new ArrayList<>(); this.pending = new ArrayList<>(); - this.phase = InstallPhase.STARTED; + this.phase = InstallPhases.STARTED; this.installActionID = UUID.randomUUID(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java index 2147b81b..a004deb5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -3,6 +3,7 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.HoverEvent; @@ -17,18 +18,25 @@ public class InstallResult private final boolean success; private final InstallProgress progress; - public static InstallResult success(InstallProgress progress) + public static InstallResult success(@NotNull InstallProgress progress) { progress.finish(); return new InstallResult(true, progress); } - public static InstallFailedInstallResult error(InstallProgress progress, FailedReason reason) + public static InstallFailedInstallResult error(@NotNull InstallProgress progress, @NotNull FailedReason reason) { // TODO: Implement debug mode progress.finish(); return new InstallFailedInstallResult(progress, reason); } + public static InstallFailedInstallResult error(@NotNull InstallProgress progress, @NotNull FailedReason reason, + @NotNull PhaseEnum phaseStatus) + { // TODO: Implement debug mode + progress.finish(); + return new InstallFailedInstallResult(progress, reason, phaseStatus); + } + private static TextComponent getResultStatusComponent(@NotNull String[] components, @NotNull String hoverPrefix) { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java index 705df19f..ecad3c8e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java @@ -1,28 +1,38 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.plugin.LoadPluginDescriptionSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolvedSuccessfulSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import org.bukkit.plugin.InvalidDescriptionException; -import org.bukkit.plugin.PluginDescriptionFile; import java.io.IOException; public class Installer { + private static InstallResult handlePhaseError(InstallProgress progress, PhaseResult result) + { + if (result.getErrorCause() != null) + return InstallResult.error(progress, result.getErrorCause(), result.getPhase()); + else + return InstallResult.error(progress, FailedReason.ILLEGAL_INTERNAL_STATE, result.getPhase()); + } + public static InstallResult installPlugin(String query, InstallerSignalHandler signalHandler) { - PlumbingInstaller internal; InstallProgress progress; // region Initialize install. Phase: INITIALIZING try { - internal = PlumbingInstaller.initInstall(signalHandler); - progress = internal.getProgress(); + progress = new InstallProgress(true); + progress.setPhase(InstallPhases.INITIALIZING); } catch (IOException | SecurityException e) { @@ -31,56 +41,36 @@ public static InstallResult installPlugin(String query, InstallerSignalHandler s // endregion - // region Query resolving. Phase: QUERY_RESOLVING, MULTIPLE_RESULT_RESOLVING => QUERY_RESOLVING - progress.setPhase(InstallPhase.QUERY_RESOLVING); - - ResolveResult queryResolveResult = internal.resolvePlugin(query); - queryResolveResult = internal.normalizeResolveResult(query, queryResolveResult); + // region Query resolving. Phase: QUERY_RESOLVE + progress.setPhase(InstallPhases.QUERY_RESOLVING); - InstallResult mayQueryError = internal.checkResolveError(queryResolveResult); - if (mayQueryError != null) - return mayQueryError; + PluginResolvePhase resolvePhase = new PluginResolvePhase(progress, signalHandler); + PluginResolveResult resolveResult = resolvePhase.runPhase(new PluginResolveArgument(query)); - assert queryResolveResult != null; // if queryResolveResult is null, mayQueryError must not be null. - - internal.postSignal(new PluginResolvedSuccessfulSignal((SuccessResult) queryResolveResult)); + if (!resolveResult.isSuccess() || resolveResult.getResolveResult() == null) // getResolveResult() == null is never true. + return handlePhaseError(progress, resolveResult); // endregion - SuccessResult resolvedPlugin = (SuccessResult) queryResolveResult; - // region Downloading. Phase: START_DOWNLOADING=>DOWNLOADING - progress.setPhase(InstallPhase.START_DOWNLOADING); + progress.setPhase(InstallPhases.DOWNLOADING); - PlumbingInstaller.DownloadResult downloadResult = internal.downloadJar(progress, resolvedPlugin); + DownloadPhase downloadPhase = new DownloadPhase(progress, signalHandler); + DownloadResult downloadResult = downloadPhase.runPhase(DownloadArgument.of(resolveResult)); if (!downloadResult.isSuccess()) - return InstallResult.error(progress, downloadResult.getDownloadFailedReason()); + return handlePhaseError(progress, downloadResult); // endregion // region Load plugin.yml. Phase: LOADING_PLUGIN_DESCRIPTION - progress.setPhase(InstallPhase.LOADING_PLUGIN_DESCRIPTION); - internal.postSignal(new LoadPluginDescriptionSignal(downloadResult.getPath())); + progress.setPhase(InstallPhases.LOADING_PLUGIN_DESCRIPTION); - PluginDescriptionFile pluginYml; - - try - { - pluginYml = PluginUtil.loadDescription(downloadResult.getPath().toFile()); - } - catch (InvalidDescriptionException e) - { - if (e.getMessage().equals("This file isn't plugin.")) - return InstallResult.error(progress, FailedReason.NOT_A_PLUGIN); - else - return InstallResult.error(progress, FailedReason.INVALID_PLUGIN_DESCRIPTION); - } - catch (IOException e) - { - e.printStackTrace(); - return InstallResult.error(progress, FailedReason.IO_EXCEPTION_OCCURRED); - } + DescriptionLoadPhase descriptionLoadPhase = new DescriptionLoadPhase(progress, signalHandler); + DescriptionLoadResult descriptionLoadResult = + descriptionLoadPhase.runPhase(DescriptionLoadArgument.of(downloadResult)); + if (!downloadResult.isSuccess()) + return handlePhaseError(progress, downloadResult); // endregion diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java deleted file mode 100644 index 0af9bfb1..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/PlumbingInstaller.java +++ /dev/null @@ -1,207 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadStartingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadSucceedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.MultiplePluginResolvedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolveErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolvingSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.IOException; -import java.nio.file.Path; - -@AllArgsConstructor(access = AccessLevel.PRIVATE) -class PlumbingInstaller -{ - private static final PluginResolver PLUGIN_RESOLVER; - - static - { - PLUGIN_RESOLVER = TeamKunPluginManager.getPlugin().getResolver(); - } - - private final InstallerSignalHandler signalHandler; - - @Getter - private final InstallProgress progress; - - public void postSignal(@NotNull InstallerSignal signal) - { - this.signalHandler.handleSignal(this.progress, signal); - } - - public static PlumbingInstaller initInstall(InstallerSignalHandler signalHandler) - throws IOException, SecurityException - { - - InstallProgress progress = new InstallProgress(true); - - PlumbingInstaller instance = new PlumbingInstaller(signalHandler, progress); - - progress.setPhase(InstallPhase.INITIALIZING); - return instance; - } - - public @NotNull ResolveResult resolvePlugin(@NotNull String query) - { - this.postSignal(new PluginResolvingSignal(query, PLUGIN_RESOLVER)); - - return PLUGIN_RESOLVER.resolve(query); - } - - public @Nullable ResolveResult resolveMultipleResults(@NotNull String query, @NotNull MultiResult results) - { - if (results.getResults().length < 1) - throw new IllegalStateException("MultiResult with no results."); - - MultiplePluginResolvedSignal signal = new MultiplePluginResolvedSignal(query, results); - this.postSignal(signal); - - if (signal.getSpecifiedResult() != null) - return signal.getSpecifiedResult(); // Plugin actually resolved by SignalHandler. - - ResolveResult result = results.getResults()[0]; - - if (result instanceof MultiResult) - { - MultiResult multiResult = (MultiResult) result; - return this.resolveMultipleResults(query, multiResult); // Recursive call. - } - - return result; - } - - private void onDownload(DownloadProgress downloadProgress) - { - PlumbingInstaller.this.postSignal(new DownloadProgressSignal( - downloadProgress.getTotalSize(), - downloadProgress.getDownloaded(), - downloadProgress.getPercentage() - )); - } - - public @NotNull DownloadResult downloadJar(@NotNull InstallProgress progress, @NotNull SuccessResult resolveResult) - { - DownloadStartingSignal downloadingSignal = new DownloadStartingSignal( - progress.getInstallTempDir().resolve(progress.getInstallActionID().toString() + ".jar"), - resolveResult.getDownloadUrl() - ); - - this.postSignal(downloadingSignal); // SignalHandler can change the download URL and download path. - - Path path = downloadingSignal.getDownloadPath(); - String url = downloadingSignal.getUrl(); - - try - { - long size = Requests.downloadFile(RequestMethod.GET, url, path, this::onDownload); - - this.postSignal(new DownloadSucceedSignal(path, size)); - - return new DownloadResult(path, true, size, null); // downloadFailedReason is null. - } - catch (IOException e) - { - DownloadErrorCause cause; - Object signalValue; - - if (e.getMessage().startsWith("HTTP error ")) - { - cause = DownloadErrorCause.ILLEGAL_HTTP_RESPONSE; - signalValue = e.getMessage().substring(11); - } - else if (e.getMessage().startsWith("No response body was returned")) - { - cause = DownloadErrorCause.NO_BODY_IN_RESPONSE; - signalValue = null; - } - else - { - cause = DownloadErrorCause.IO_EXCEPTION; - signalValue = e; - } - - DownloadErrorSignal error = new DownloadErrorSignal(cause, signalValue); - this.postSignal(error); - - return new DownloadResult(null, false, -1, cause.toFailedReason()); - } - catch (Exception e) - { - this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, e)); - - return new DownloadResult(null, false, -1, DownloadErrorCause.UNKNOWN_ERROR.toFailedReason()); - } - } - - public @Nullable ResolveResult normalizeResolveResult(@NotNull String query, @NotNull ResolveResult queryResolveResult) - { - if (queryResolveResult instanceof ErrorResult) - { - this.postSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); - return null; - } - else if (queryResolveResult instanceof MultiResult) - { - this.progress.setPhase(InstallPhase.MULTIPLE_RESULT_RESOLVING); - - MultiResult multiResult = (MultiResult) queryResolveResult; - ResolveResult actualResolveResult = this.resolveMultipleResults(query, multiResult); - - if (actualResolveResult instanceof ErrorResult) - { - // MultiResult has been resolved, but the actual result is an error - this.postSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); - return null; - } - - // MultiResult has been resolved, and the actual result is a SuccessResult - // (resolveMultipleResults() should not return a MultiResult) - - this.progress.setPhase(InstallPhase.QUERY_RESOLVING); // Reset to QUERY_RESOLVING from MULTIPLE_RESULT_RESOLVING - - return actualResolveResult; - } - else - return queryResolveResult; - } - - public @Nullable InstallResult checkResolveError(@Nullable ResolveResult resolveResult) - { - if (resolveResult == null) // normalizeResolveResult() returns null if the ResolveResult is error. - return InstallResult.error(progress, FailedReason.GOT_ERROR_RESULT); - if (!(resolveResult instanceof SuccessResult)) // Should never happen - return InstallResult.error(progress, FailedReason.ILLEGAL_INTERNAL_STATE); - - return null; - } - - @Value - public static class DownloadResult - { - Path path; - boolean success; - long totalSize; - - FailedReason downloadFailedReason; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java new file mode 100644 index 00000000..d3bdd1fc --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import org.jetbrains.annotations.NotNull; + +@AllArgsConstructor +public abstract class InstallPhase>> +{ + @NotNull + protected final InstallProgress progress; + @NotNull + private final InstallerSignalHandler signalHandler; + + public abstract @NotNull R runPhase(@NotNull A arguments); + + public void postSignal(@NotNull InstallerSignal signal) + { + this.signalHandler.handleSignal(this.progress, signal); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java new file mode 100644 index 00000000..6d5f3856 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; + +public interface PhaseArgument +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java new file mode 100644 index 00000000..9191b2bd --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; + +public interface PhaseEnum +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java new file mode 100644 index 00000000..65754dc9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java @@ -0,0 +1,20 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@AllArgsConstructor +@Getter +public abstract class PhaseResult & PhaseEnum> +{ + private final boolean success; + @NotNull + private final R phase; + + @Nullable + private final FailedReason errorCause; + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java new file mode 100644 index 00000000..b0cdb7c7 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +@Value +public class DescriptionLoadArgument implements PhaseArgument +{ + @NotNull + Path pluginFile; + + public static DescriptionLoadArgument of(@NotNull DownloadResult of) + { + if (!of.isSuccess() || of.getPath() == null) + throw new IllegalArgumentException("Download must be successful"); + + return new DescriptionLoadArgument(of.getPath()); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java new file mode 100644 index 00000000..0c3e848a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java @@ -0,0 +1,55 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.plugin.LoadPluginDescriptionSignal; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; + +public class DescriptionLoadPhase extends InstallPhase +{ + private DescriptionLoadState phaseState; + + public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + { + super(progress, signalHandler); + this.phaseState = DescriptionLoadState.INITIALIZED; + } + + @Override + public @NotNull DescriptionLoadResult runPhase(@NotNull DescriptionLoadArgument arguments) + { + this.postSignal(new LoadPluginDescriptionSignal(arguments.getPluginFile())); + + PluginDescriptionFile pluginYml; + + try + { + this.phaseState = DescriptionLoadState.LOADING_PLUGIN_DESCRIPTION; + pluginYml = PluginUtil.loadDescription(arguments.getPluginFile().toFile()); + } + catch (InvalidDescriptionException e) + { + if (e.getMessage().equals("This file isn't plugin.")) + return new DescriptionLoadResult(false, this.phaseState, FailedReason.NOT_A_PLUGIN, null); + else + { + e.printStackTrace(); + return new DescriptionLoadResult(false, this.phaseState, FailedReason.INVALID_PLUGIN_DESCRIPTION, null); + } + } + catch (IOException e) + { + e.printStackTrace(); + return new DescriptionLoadResult(false, this.phaseState, FailedReason.IO_EXCEPTION_OCCURRED, null); + } + + return new DescriptionLoadResult(true, this.phaseState, null, pluginYml); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java new file mode 100644 index 00000000..9ec9cfcd --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Getter +public class DescriptionLoadResult extends PhaseResult +{ + @Nullable + private final PluginDescriptionFile description; + + public DescriptionLoadResult(boolean success, @NotNull DescriptionLoadState phase, @Nullable FailedReason errorCause, + @Nullable PluginDescriptionFile description) + { + super(success, phase, errorCause); + this.description = description; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java new file mode 100644 index 00000000..d18693de --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum DescriptionLoadState implements PhaseEnum +{ + INITIALIZED, + + LOADING_PLUGIN_DESCRIPTION +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java new file mode 100644 index 00000000..99716c9c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java @@ -0,0 +1,21 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; +import org.jetbrains.annotations.NotNull; + +@Value +public class DownloadArgument implements PhaseArgument +{ + @NotNull + String url; + + public static DownloadArgument of(@NotNull PluginResolveResult pluginResolveResult) + { + if (!pluginResolveResult.isSuccess() || pluginResolveResult.getResolveResult() == null) + throw new IllegalArgumentException("Plugin Resolving must be successful"); + + return new DownloadArgument(pluginResolveResult.getResolveResult().getDownloadUrl()); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java new file mode 100644 index 00000000..c3005199 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java @@ -0,0 +1,98 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadStartingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadSucceedSignal; +import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.nio.file.Path; + +public class DownloadPhase extends InstallPhase +{ + private DownloadState phaseState; + + public DownloadPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + { + super(progress, signalHandler); + + this.phaseState = DownloadState.INITIALIZED; + } + + private void onDownload(DownloadProgress downloadProgress) + { + this.phaseState = DownloadState.DOWNLOADING; + + this.postSignal(new DownloadProgressSignal( + downloadProgress.getTotalSize(), + downloadProgress.getDownloaded(), + downloadProgress.getPercentage() + )); + } + + @Override + public @NotNull DownloadResult runPhase(@NotNull DownloadArgument arguments) + { + DownloadStartingSignal downloadingSignal = new DownloadStartingSignal( + progress.getInstallTempDir().resolve(progress.getInstallActionID().toString() + ".jar"), + arguments.getUrl() + ); + + this.phaseState = DownloadState.START_DOWNLOADING; + this.postSignal(downloadingSignal); // SignalHandler can change the download URL and download path. + + Path path = downloadingSignal.getDownloadPath(); + String url = downloadingSignal.getUrl(); + + try + { + long size = Requests.downloadFile(RequestMethod.GET, url, path, this::onDownload); + + this.postSignal(new DownloadSucceedSignal(path, size)); + + return new DownloadResult(true, this.phaseState, path, size); + } + catch (IOException e) + { + DownloadErrorCause cause; + Object signalValue; + + if (e.getMessage().startsWith("HTTP error ")) + { + cause = DownloadErrorCause.ILLEGAL_HTTP_RESPONSE; + signalValue = e.getMessage().substring(11); + } + else if (e.getMessage().startsWith("No response body was returned")) + { + cause = DownloadErrorCause.NO_BODY_IN_RESPONSE; + signalValue = null; + } + else + { + cause = DownloadErrorCause.IO_EXCEPTION; + signalValue = e; + } + + DownloadErrorSignal error = new DownloadErrorSignal(cause, signalValue); + this.postSignal(error); + + return new DownloadResult(true, this.phaseState, path, -1, cause.toFailedReason()); + } + catch (Exception e) + { + this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, e)); + + return new DownloadResult(true, this.phaseState, path, -1, + DownloadErrorCause.UNKNOWN_ERROR.toFailedReason() + ); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java new file mode 100644 index 00000000..bb837379 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java @@ -0,0 +1,30 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; + +@Getter +public class DownloadResult extends PhaseResult +{ + @Nullable + private final Path path; + private final long totalSize; + + public DownloadResult(boolean success, @NotNull DownloadState phase, @Nullable Path path, + long totalSize, @Nullable FailedReason errorCause) + { + super(success, phase, errorCause); + this.path = path; + this.totalSize = totalSize; + } + + public DownloadResult(boolean success, @NotNull DownloadState phase, @Nullable Path path, long totalSize) + { + this(success, phase, path, totalSize, null); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java new file mode 100644 index 00000000..0dd4f7c4 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java @@ -0,0 +1,11 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum DownloadState implements PhaseEnum +{ + INITIALIZED, + + START_DOWNLOADING, + DOWNLOADING, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java new file mode 100644 index 00000000..b6fb8e63 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import org.jetbrains.annotations.NotNull; + +@Data +public class PluginResolveArgument implements PhaseArgument +{ + @NotNull + String query; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java new file mode 100644 index 00000000..48d0a364 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java @@ -0,0 +1,103 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; + +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.MultiplePluginResolvedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolveErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolvingSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PluginResolvePhase extends InstallPhase +{ + private static final PluginResolver PLUGIN_RESOLVER; + + static + { + PLUGIN_RESOLVER = TeamKunPluginManager.getPlugin().getResolver(); + } + + private PluginResolveState phaseState; + + public PluginResolvePhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + { + super(progress, signalHandler); + + this.phaseState = PluginResolveState.INITIALIZED; + } + + private @Nullable ResolveResult resolveMultipleResults(@NotNull String query, @NotNull MultiResult results) + { + if (results.getResults().length < 1) + throw new IllegalStateException("MultiResult with no results."); + + MultiplePluginResolvedSignal signal = new MultiplePluginResolvedSignal(query, results); + this.postSignal(signal); + + if (signal.getSpecifiedResult() != null) + return signal.getSpecifiedResult(); // Plugin actually resolved by SignalHandler. + + ResolveResult result = results.getResults()[0]; + + if (result instanceof MultiResult) + { + MultiResult multiResult = (MultiResult) result; + return this.resolveMultipleResults(query, multiResult); // Recursive call. + } + + return result; + } + + @Override + public @NotNull PluginResolveResult runPhase(@NotNull PluginResolveArgument arguments) + { + String query = arguments.getQuery(); + + this.phaseState = PluginResolveState.PRE_RESOLVING; + this.postSignal(new PluginResolvingSignal(query, PLUGIN_RESOLVER)); + + ResolveResult queryResolveResult = PLUGIN_RESOLVER.resolve(query); + + this.phaseState = PluginResolveState.PRE_RESOLVE_FINISHED; + + if (queryResolveResult instanceof ErrorResult) + { + this.postSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); + return new PluginResolveResult(false, this.phaseState, FailedReason.GOT_ERROR_RESULT, null); + } + else if (queryResolveResult instanceof MultiResult) + { + this.phaseState = PluginResolveState.MULTI_RESOLVING; + + MultiResult multiResult = (MultiResult) queryResolveResult; + ResolveResult actualResolveResult = resolveMultipleResults(arguments.getQuery(), multiResult); + + if (actualResolveResult instanceof ErrorResult) + { + // MultiResult has been resolved, but the actual result is an error + this.postSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); + return new PluginResolveResult(false, this.phaseState, FailedReason.GOT_ERROR_RESULT, null); + } + + // MultiResult has been resolved, and the actual result is a SuccessResult + // (resolveMultipleResults() should not return a MultiResult) + + queryResolveResult = actualResolveResult; + } + + this.phaseState = PluginResolveState.RESOLVE_FINISHED; + + if (!(queryResolveResult instanceof SuccessResult)) + return new PluginResolveResult(false, this.phaseState, FailedReason.ILLEGAL_INTERNAL_STATE, null); + + return new PluginResolveResult(true, this.phaseState, (SuccessResult) queryResolveResult); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java new file mode 100644 index 00000000..c07d7c32 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java @@ -0,0 +1,28 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PluginResolveResult extends PhaseResult +{ + @Getter + @Nullable + private final SuccessResult resolveResult; + + public PluginResolveResult(boolean success, @NotNull PluginResolveState phase, @NotNull FailedReason errorCause, @Nullable SuccessResult resolveResult) + { + super(success, phase, errorCause); + this.resolveResult = resolveResult; + } + + public PluginResolveResult(boolean success, @NotNull PluginResolveState phase, @NotNull SuccessResult resolveResult) + { + super(success, phase, null); + this.resolveResult = resolveResult; + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java new file mode 100644 index 00000000..a0ac0f31 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum PluginResolveState implements PhaseEnum +{ + INITIALIZED, + + PRE_RESOLVING, + PRE_RESOLVE_FINISHED, + + MULTI_RESOLVING, + + RESOLVE_FINISHED +} From 39f2bc0e403bb99314af0c606e2965388b0fd42a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 29 Apr 2022 20:04:01 +0900 Subject: [PATCH 140/745] refactor: wip: installer: remove signals --- .../plugin/installer/Installer.java | 1 - .../plugin/installer/InstallerSignal.java | 5 +++++ .../{signal => }/InstallerSignalHandler.java | 3 +-- .../plugin/installer/phase/InstallPhase.java | 4 ++-- .../phases/description/DescriptionLoadPhase.java | 4 ++-- .../signals}/LoadPluginDescriptionSignal.java | 4 ++-- .../phase/phases/download/DownloadPhase.java | 12 ++++++------ .../download/signals}/DownloadErrorCause.java | 2 +- .../download/signals}/DownloadErrorSignal.java | 4 ++-- .../download/signals/DownloadProgressSignal.java | 13 +++++++++++++ .../download/signals}/DownloadStartingSignal.java | 4 ++-- .../download/signals}/DownloadSucceedSignal.java | 4 ++-- .../phase/phases/resolve/PluginResolvePhase.java | 8 ++++---- .../signals}/MultiplePluginResolvedSignal.java | 4 ++-- .../resolve/signals}/PluginResolveErrorSignal.java | 4 ++-- .../signals}/PluginResolvedSuccessfulSignal.java | 4 ++-- .../resolve/signals}/PluginResolvingSignal.java | 4 ++-- .../plugin/installer/signal/InstallerSignal.java | 5 ----- .../signals/download/DownloadProgressSignal.java | 13 ------------- 19 files changed, 50 insertions(+), 52 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal => }/InstallerSignalHandler.java (60%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/plugin => phase/phases/description/signals}/LoadPluginDescriptionSignal.java (61%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/download => phase/phases/download/signals}/DownloadErrorCause.java (88%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/download => phase/phases/download/signals}/DownloadErrorSignal.java (60%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadProgressSignal.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/download => phase/phases/download/signals}/DownloadStartingSignal.java (59%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/download => phase/phases/download/signals}/DownloadSucceedSignal.java (69%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/resolve => phase/phases/resolve/signals}/MultiplePluginResolvedSignal.java (74%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/resolve => phase/phases/resolve/signals}/PluginResolveErrorSignal.java (59%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/resolve => phase/phases/resolve/signals}/PluginResolvedSuccessfulSignal.java (62%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signal/signals/resolve => phase/phases/resolve/signals}/PluginResolvingSignal.java (62%) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java index ecad3c8e..48ac1bd9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java @@ -10,7 +10,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; import java.io.IOException; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java new file mode 100644 index 00000000..e83263d8 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +public interface InstallerSignal +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java index e07466d7..defbb82e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java @@ -1,6 +1,5 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import org.jetbrains.annotations.NotNull; @FunctionalInterface diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java index d3bdd1fc..25873a31 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java @@ -2,8 +2,8 @@ import lombok.AllArgsConstructor; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import org.jetbrains.annotations.NotNull; @AllArgsConstructor diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java index 0c3e848a..a06101d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java @@ -2,9 +2,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.plugin.LoadPluginDescriptionSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.signals.LoadPluginDescriptionSignal; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/plugin/LoadPluginDescriptionSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/signals/LoadPluginDescriptionSignal.java similarity index 61% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/plugin/LoadPluginDescriptionSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/signals/LoadPluginDescriptionSignal.java index 87b3adde..008b017b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/plugin/LoadPluginDescriptionSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/signals/LoadPluginDescriptionSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.plugin; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.signals; import lombok.AllArgsConstructor; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java index c3005199..bd453b58 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java @@ -1,13 +1,13 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadStartingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download.DownloadSucceedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadStartingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadSucceedSignal; import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorCause.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorCause.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorCause.java index c9cb6417..3c5e26fe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java index 22385917..ee92ef01 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadProgressSignal.java new file mode 100644 index 00000000..28ad98e8 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadProgressSignal.java @@ -0,0 +1,13 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; + +@Value +public class DownloadProgressSignal implements InstallerSignal +{ + long totalSize; + long downloaded; + + double percentage; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadStartingSignal.java similarity index 59% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadStartingSignal.java index e396371e..f0db7453 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadStartingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadStartingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadSucceedSignal.java similarity index 69% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadSucceedSignal.java index bc448ea9..4476186d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadSucceedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadSucceedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java index 48d0a364..55673cb3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java @@ -3,11 +3,11 @@ import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.MultiplePluginResolvedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolveErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve.PluginResolvingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals.MultiplePluginResolvedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals.PluginResolveErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals.PluginResolvingSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/MultiplePluginResolvedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/MultiplePluginResolvedSignal.java similarity index 74% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/MultiplePluginResolvedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/MultiplePluginResolvedSignal.java index 502d1864..4621ab50 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/MultiplePluginResolvedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/MultiplePluginResolvedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolveErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolveErrorSignal.java similarity index 59% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolveErrorSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolveErrorSignal.java index 4c55be1a..6abff8b5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolveErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolveErrorSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; import lombok.Data; import lombok.NonNull; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; @Data diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvedSuccessfulSignal.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvedSuccessfulSignal.java index 3e354483..c2d2d11e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvedSuccessfulSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvedSuccessfulSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvingSignal.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvingSignal.java index 004eb4d8..81cb1727 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/resolve/PluginResolvingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvingSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; import lombok.AllArgsConstructor; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; @Data diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java deleted file mode 100644 index a89f2a16..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/InstallerSignal.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal; - -public interface InstallerSignal -{ -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java deleted file mode 100644 index f033ef8c..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signal/signals/download/DownloadProgressSignal.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.signals.download; - -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signal.InstallerSignal; - -@Value -public class DownloadProgressSignal implements InstallerSignal -{ - long totalSize; - long downloaded; - - double percentage; -} From b0c800a2bd1e057844e09a8e3260a3da5d0e5866 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 30 Apr 2022 16:39:09 +0900 Subject: [PATCH 141/745] refactor: wip: installer: Split FailedReason --- .../plugin/installer/FailedReason.java | 19 ------------- .../installer/InstallFailedInstallResult.java | 8 +++--- .../plugin/installer/InstallResult.java | 12 +++++---- .../plugin/installer/Installer.java | 10 ++++--- .../phase/GeneralPhaseErrorCause.java | 8 ++++++ .../plugin/installer/phase/InstallPhase.java | 2 +- .../plugin/installer/phase/PhaseResult.java | 6 ++--- .../DescriptionLoadErrorCause.java | 10 +++++++ .../description/DescriptionLoadPhase.java | 13 ++++++--- .../description/DescriptionLoadResult.java | 6 ++--- .../phases/download/DownloadErrorCause.java | 11 ++++++++ .../phase/phases/download/DownloadPhase.java | 7 ++--- .../phase/phases/download/DownloadResult.java | 5 ++-- .../download/signals/DownloadErrorCause.java | 27 ------------------- .../download/signals/DownloadErrorSignal.java | 1 + .../resolve/PluginResolveErrorCause.java | 9 +++++++ .../phases/resolve/PluginResolvePhase.java | 9 ++++--- .../phases/resolve/PluginResolveResult.java | 6 ++--- .../signals/IgnoredPluginSignal.java | 12 +++++++++ 19 files changed, 95 insertions(+), 86 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java deleted file mode 100644 index 856a4844..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/FailedReason.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; - -public enum FailedReason -{ - // Resolving errors - GOT_ERROR_RESULT, - - // Net errors - ILLEGAL_RESPONSE_CODE, - NO_RESPONSE_BODY, - - // Installing errors - INVALID_PLUGIN_DESCRIPTION, - NOT_A_PLUGIN, - - // General internal errors - ILLEGAL_INTERNAL_STATE, - IO_EXCEPTION_OCCURRED, -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index 245e4b52..abb096af 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -6,21 +6,21 @@ import org.jetbrains.annotations.Nullable; @Getter -public class InstallFailedInstallResult extends InstallResult +public class InstallFailedInstallResult & PhaseEnum> extends InstallResult { @NotNull - private final FailedReason reason; + private final T reason; @Nullable private final PhaseEnum phaseStatus; - InstallFailedInstallResult(@NotNull InstallProgress progress, @NotNull FailedReason reason, @NotNull PhaseEnum phaseStatus) + InstallFailedInstallResult(@NotNull InstallProgress progress, @NotNull T reason, @NotNull PhaseEnum phaseStatus) { super(false, progress); this.reason = reason; this.phaseStatus = phaseStatus; } - public InstallFailedInstallResult(InstallProgress progress, @NotNull FailedReason reason) + public InstallFailedInstallResult(InstallProgress progress, @NotNull T reason) { super(false, progress); this.reason = reason; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java index a004deb5..f4542875 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -24,17 +24,19 @@ public static InstallResult success(@NotNull InstallProgress progress) return new InstallResult(true, progress); } - public static InstallFailedInstallResult error(@NotNull InstallProgress progress, @NotNull FailedReason reason) + public static & PhaseEnum> InstallFailedInstallResult error(@NotNull InstallProgress progress, + @NotNull T reason) { // TODO: Implement debug mode progress.finish(); - return new InstallFailedInstallResult(progress, reason); + return new InstallFailedInstallResult<>(progress, reason); } - public static InstallFailedInstallResult error(@NotNull InstallProgress progress, @NotNull FailedReason reason, - @NotNull PhaseEnum phaseStatus) + public static & PhaseEnum> InstallFailedInstallResult error(@NotNull InstallProgress progress, + @NotNull T reason, + @NotNull PhaseEnum phaseStatus) { // TODO: Implement debug mode progress.finish(); - return new InstallFailedInstallResult(progress, reason, phaseStatus); + return new InstallFailedInstallResult<>(progress, reason, phaseStatus); } private static TextComponent getResultStatusComponent(@NotNull String[] components, @NotNull String hoverPrefix) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java index 48ac1bd9..70aa89aa 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java @@ -1,5 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.GeneralPhaseErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; @@ -15,12 +17,12 @@ public class Installer { - private static InstallResult handlePhaseError(InstallProgress progress, PhaseResult result) + private static & PhaseEnum> InstallResult handlePhaseError(InstallProgress progress, PhaseResult result) { if (result.getErrorCause() != null) return InstallResult.error(progress, result.getErrorCause(), result.getPhase()); else - return InstallResult.error(progress, FailedReason.ILLEGAL_INTERNAL_STATE, result.getPhase()); + return InstallResult.error(progress, GeneralPhaseErrorCause.ILLEGAL_INTERNAL_STATE, result.getPhase()); } public static InstallResult installPlugin(String query, InstallerSignalHandler signalHandler) @@ -35,7 +37,7 @@ public static InstallResult installPlugin(String query, InstallerSignalHandler s } catch (IOException | SecurityException e) { - return InstallResult.error(InstallProgress.dummy(), FailedReason.IO_EXCEPTION_OCCURRED); + return InstallResult.error(InstallProgress.dummy(), GeneralPhaseErrorCause.IO_EXCEPTION_OCCURRED); } // endregion @@ -72,6 +74,6 @@ public static InstallResult installPlugin(String query, InstallerSignalHandler s return handlePhaseError(progress, downloadResult); // endregion - + // region Check the plugin is already installed. Phase: CHECK_INSTALLED } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java new file mode 100644 index 00000000..ff3eb194 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java @@ -0,0 +1,8 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; + +public enum GeneralPhaseErrorCause implements PhaseEnum +{ + // General internal errors + ILLEGAL_INTERNAL_STATE, + IO_EXCEPTION_OCCURRED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java index 25873a31..db6c08c5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; @AllArgsConstructor -public abstract class InstallPhase>> +public abstract class InstallPhase, ? extends Enum>> { @NotNull protected final InstallProgress progress; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java index 65754dc9..0d550152 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java @@ -2,19 +2,17 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @AllArgsConstructor @Getter -public abstract class PhaseResult & PhaseEnum> +public abstract class PhaseResult & PhaseEnum, C extends Enum & PhaseEnum> { private final boolean success; @NotNull private final R phase; @Nullable - private final FailedReason errorCause; - + private final C errorCause; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java new file mode 100644 index 00000000..a40978f2 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum DescriptionLoadErrorCause implements PhaseEnum +{ + NOT_A_PLUGIN, + INVALID_DESCRIPTION, + IO_EXCEPTION +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java index a06101d8..3b26a92e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; @@ -37,17 +36,23 @@ public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull Installe catch (InvalidDescriptionException e) { if (e.getMessage().equals("This file isn't plugin.")) - return new DescriptionLoadResult(false, this.phaseState, FailedReason.NOT_A_PLUGIN, null); + return new DescriptionLoadResult(false, this.phaseState, + DescriptionLoadErrorCause.NOT_A_PLUGIN, null + ); else { e.printStackTrace(); - return new DescriptionLoadResult(false, this.phaseState, FailedReason.INVALID_PLUGIN_DESCRIPTION, null); + return new DescriptionLoadResult(false, this.phaseState, + DescriptionLoadErrorCause.INVALID_DESCRIPTION, null + ); } } catch (IOException e) { e.printStackTrace(); - return new DescriptionLoadResult(false, this.phaseState, FailedReason.IO_EXCEPTION_OCCURRED, null); + return new DescriptionLoadResult(false, this.phaseState, + DescriptionLoadErrorCause.IO_EXCEPTION, null + ); } return new DescriptionLoadResult(true, this.phaseState, null, pluginYml); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java index 9ec9cfcd..7796355c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java @@ -1,19 +1,19 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @Getter -public class DescriptionLoadResult extends PhaseResult +public class DescriptionLoadResult extends PhaseResult { @Nullable private final PluginDescriptionFile description; - public DescriptionLoadResult(boolean success, @NotNull DescriptionLoadState phase, @Nullable FailedReason errorCause, + public DescriptionLoadResult(boolean success, @NotNull DescriptionLoadState phase, + @Nullable DescriptionLoadErrorCause errorCause, @Nullable PluginDescriptionFile description) { super(success, phase, errorCause); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java new file mode 100644 index 00000000..fbbfc746 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java @@ -0,0 +1,11 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum DownloadErrorCause implements PhaseEnum +{ + ILLEGAL_HTTP_RESPONSE, + NO_BODY_IN_RESPONSE, + IO_EXCEPTION, + UNKNOWN_ERROR +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java index bd453b58..c787b33b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java @@ -3,7 +3,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadErrorSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadProgressSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadStartingSignal; @@ -84,15 +83,13 @@ else if (e.getMessage().startsWith("No response body was returned")) DownloadErrorSignal error = new DownloadErrorSignal(cause, signalValue); this.postSignal(error); - return new DownloadResult(true, this.phaseState, path, -1, cause.toFailedReason()); + return new DownloadResult(true, this.phaseState, path, -1, cause); } catch (Exception e) { this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, e)); - return new DownloadResult(true, this.phaseState, path, -1, - DownloadErrorCause.UNKNOWN_ERROR.toFailedReason() - ); + return new DownloadResult(true, this.phaseState, path, -1, DownloadErrorCause.UNKNOWN_ERROR); } } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java index bb837379..2a172a51 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,14 +8,14 @@ import java.nio.file.Path; @Getter -public class DownloadResult extends PhaseResult +public class DownloadResult extends PhaseResult { @Nullable private final Path path; private final long totalSize; public DownloadResult(boolean success, @NotNull DownloadState phase, @Nullable Path path, - long totalSize, @Nullable FailedReason errorCause) + long totalSize, @Nullable DownloadErrorCause errorCause) { super(success, phase, errorCause); this.path = path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorCause.java deleted file mode 100644 index 3c5e26fe..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorCause.java +++ /dev/null @@ -1,27 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; - -public enum DownloadErrorCause -{ - ILLEGAL_HTTP_RESPONSE, - NO_BODY_IN_RESPONSE, - IO_EXCEPTION, - UNKNOWN_ERROR; - - public FailedReason toFailedReason() - { - switch (this) - { - case ILLEGAL_HTTP_RESPONSE: - return FailedReason.ILLEGAL_RESPONSE_CODE; - case NO_BODY_IN_RESPONSE: - return FailedReason.NO_RESPONSE_BODY; - case IO_EXCEPTION: - return FailedReason.IO_EXCEPTION_OCCURRED; - case UNKNOWN_ERROR: - default: - return FailedReason.ILLEGAL_INTERNAL_STATE; - } - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java index ee92ef01..84a2d9e6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java @@ -2,6 +2,7 @@ import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadErrorCause; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java new file mode 100644 index 00000000..badb4ddd --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum PluginResolveErrorCause implements PhaseEnum +{ + ILLEGAL_INTERNAL_STATE, + GOT_ERROR_RESULT +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java index 55673cb3..a3e8554e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; @@ -71,7 +70,9 @@ public PluginResolvePhase(@NotNull InstallProgress progress, @NotNull InstallerS if (queryResolveResult instanceof ErrorResult) { this.postSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); - return new PluginResolveResult(false, this.phaseState, FailedReason.GOT_ERROR_RESULT, null); + return new PluginResolveResult(false, this.phaseState, + PluginResolveErrorCause.GOT_ERROR_RESULT, null + ); } else if (queryResolveResult instanceof MultiResult) { @@ -84,7 +85,7 @@ else if (queryResolveResult instanceof MultiResult) { // MultiResult has been resolved, but the actual result is an error this.postSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); - return new PluginResolveResult(false, this.phaseState, FailedReason.GOT_ERROR_RESULT, null); + return new PluginResolveResult(false, this.phaseState, PluginResolveErrorCause.GOT_ERROR_RESULT, null); } // MultiResult has been resolved, and the actual result is a SuccessResult @@ -96,7 +97,7 @@ else if (queryResolveResult instanceof MultiResult) this.phaseState = PluginResolveState.RESOLVE_FINISHED; if (!(queryResolveResult instanceof SuccessResult)) - return new PluginResolveResult(false, this.phaseState, FailedReason.ILLEGAL_INTERNAL_STATE, null); + return new PluginResolveResult(false, this.phaseState, PluginResolveErrorCause.ILLEGAL_INTERNAL_STATE, null); return new PluginResolveResult(true, this.phaseState, (SuccessResult) queryResolveResult); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java index c07d7c32..266ca275 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java @@ -1,19 +1,19 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.FailedReason; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class PluginResolveResult extends PhaseResult +public class PluginResolveResult extends PhaseResult { @Getter @Nullable private final SuccessResult resolveResult; - public PluginResolveResult(boolean success, @NotNull PluginResolveState phase, @NotNull FailedReason errorCause, @Nullable SuccessResult resolveResult) + public PluginResolveResult(boolean success, @NotNull PluginResolveState phase, + @NotNull PluginResolveErrorCause errorCause, @Nullable SuccessResult resolveResult) { super(success, phase, errorCause); this.resolveResult = resolveResult; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java new file mode 100644 index 00000000..5aa73b72 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +@Value +public class IgnoredPluginSignal implements InstallerSignal +{ + @NotNull + String pluginName; +} From fa8bfe4b8329d51c5aa2b2acab241e851352c409 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 1 May 2022 22:40:43 +0900 Subject: [PATCH 142/745] feat: wip: installer: PhaseHogeHoge --- .../phases/predicate/PredicateArgument.java | 83 +++++++++++++++++++ .../phases/predicate/PredicateErrorCause.java | 9 ++ .../phases/predicate/PredicatePhase.java | 45 ++++++++++ .../phases/predicate/PredicateResult.java | 17 ++++ .../phases/predicate/PredicateState.java | 9 ++ 5 files changed, 163 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java new file mode 100644 index 00000000..92287534 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java @@ -0,0 +1,83 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import org.jetbrains.annotations.NotNull; + +@AllArgsConstructor +@Getter +public class PredicateArgument implements PhaseArgument +{ + private final Object arg1; + private final Object arg2; + private final Object arg3; + private final Object arg4; + private final Object arg5; + private final Object arg6; + private final Object arg7; + private final Object arg8; + private final Object arg9; + private final Object arg10; + + public static PredicateArgument of(@NotNull Object arg1) + { + return new PredicateArgument(arg1, null, null, null, null, null, null, null, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2) + { + return new PredicateArgument(arg1, arg2, null, null, null, null, null, null, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3) + { + return new PredicateArgument(arg1, arg2, arg3, null, null, null, null, null, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, + @NotNull Object arg4) + { + return new PredicateArgument(arg1, arg2, arg3, arg4, null, null, null, null, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, + @NotNull Object arg4, @NotNull Object arg5) + { + return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, null, null, null, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, + @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6) + { + return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, null, null, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, + @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, @NotNull Object arg7) + { + return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, null, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, + @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, + @NotNull Object arg7, @NotNull Object arg8) + { + return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, null, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, + @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, + @NotNull Object arg7, @NotNull Object arg8, @NotNull Object arg9) + { + return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, null); + } + + public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, + @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, + @NotNull Object arg7, @NotNull Object arg8, @NotNull Object arg9, + @NotNull Object arg10) + { + return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java new file mode 100644 index 00000000..be00d2fa --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum PredicateErrorCause implements PhaseEnum +{ + CHECK_FAILED, + EXCEPTION_OCCURRED +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java new file mode 100644 index 00000000..9f1feaee --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java @@ -0,0 +1,45 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Predicate; + +public class PredicatePhase extends InstallPhase +{ + @NotNull + private final Predicate body; + @Getter + @NotNull + private PredicateState phase; + + public PredicatePhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler, + @NotNull Predicate predicate) + { + super(progress, signalHandler); + this.phase = PredicateState.INITIALIZED; + this.body = predicate; + } + + @Override + public @NotNull PredicateResult runPhase(@NotNull PredicateArgument argument) + { + this.phase = PredicateState.CHECK_RUN; + + try + { + if (this.body.test(argument)) + return new PredicateResult(true, this.phase); + else + return new PredicateResult(false, this.phase, PredicateErrorCause.CHECK_FAILED); + } + catch (Exception e) + { + e.printStackTrace(); + return new PredicateResult(false, this.phase, PredicateErrorCause.EXCEPTION_OCCURRED); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java new file mode 100644 index 00000000..5be92cb5 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java @@ -0,0 +1,17 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import org.jetbrains.annotations.NotNull; + +public class PredicateResult extends PhaseResult +{ + public PredicateResult(boolean success, @NotNull PredicateState state, @NotNull PredicateErrorCause errorCause) + { + super(success, state, errorCause); + } + + public PredicateResult(boolean success, PredicateState state) + { + super(success, state, null); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java new file mode 100644 index 00000000..d2b276c5 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; + +public enum PredicateState implements PhaseEnum +{ + INITIALIZED, + CHECK_RUN +} From b31d0acfcd8f580ad872349d39c04d03e3df00f0 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 2 May 2022 14:57:43 +0900 Subject: [PATCH 143/745] revert: wip: installer: Remove predicate --- .../phases/predicate/PredicateArgument.java | 83 ------------------- .../phases/predicate/PredicateErrorCause.java | 9 -- .../phases/predicate/PredicatePhase.java | 45 ---------- .../phases/predicate/PredicateResult.java | 17 ---- .../phases/predicate/PredicateState.java | 9 -- 5 files changed, 163 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java deleted file mode 100644 index 92287534..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateArgument.java +++ /dev/null @@ -1,83 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import org.jetbrains.annotations.NotNull; - -@AllArgsConstructor -@Getter -public class PredicateArgument implements PhaseArgument -{ - private final Object arg1; - private final Object arg2; - private final Object arg3; - private final Object arg4; - private final Object arg5; - private final Object arg6; - private final Object arg7; - private final Object arg8; - private final Object arg9; - private final Object arg10; - - public static PredicateArgument of(@NotNull Object arg1) - { - return new PredicateArgument(arg1, null, null, null, null, null, null, null, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2) - { - return new PredicateArgument(arg1, arg2, null, null, null, null, null, null, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3) - { - return new PredicateArgument(arg1, arg2, arg3, null, null, null, null, null, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, - @NotNull Object arg4) - { - return new PredicateArgument(arg1, arg2, arg3, arg4, null, null, null, null, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, - @NotNull Object arg4, @NotNull Object arg5) - { - return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, null, null, null, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, - @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6) - { - return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, null, null, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, - @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, @NotNull Object arg7) - { - return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, null, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, - @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, - @NotNull Object arg7, @NotNull Object arg8) - { - return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, null, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, - @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, - @NotNull Object arg7, @NotNull Object arg8, @NotNull Object arg9) - { - return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, null); - } - - public static PredicateArgument of(@NotNull Object arg1, @NotNull Object arg2, @NotNull Object arg3, - @NotNull Object arg4, @NotNull Object arg5, @NotNull Object arg6, - @NotNull Object arg7, @NotNull Object arg8, @NotNull Object arg9, - @NotNull Object arg10) - { - return new PredicateArgument(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java deleted file mode 100644 index be00d2fa..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateErrorCause.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; - -public enum PredicateErrorCause implements PhaseEnum -{ - CHECK_FAILED, - EXCEPTION_OCCURRED -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java deleted file mode 100644 index 9f1feaee..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicatePhase.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; - -import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import org.jetbrains.annotations.NotNull; - -import java.util.function.Predicate; - -public class PredicatePhase extends InstallPhase -{ - @NotNull - private final Predicate body; - @Getter - @NotNull - private PredicateState phase; - - public PredicatePhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler, - @NotNull Predicate predicate) - { - super(progress, signalHandler); - this.phase = PredicateState.INITIALIZED; - this.body = predicate; - } - - @Override - public @NotNull PredicateResult runPhase(@NotNull PredicateArgument argument) - { - this.phase = PredicateState.CHECK_RUN; - - try - { - if (this.body.test(argument)) - return new PredicateResult(true, this.phase); - else - return new PredicateResult(false, this.phase, PredicateErrorCause.CHECK_FAILED); - } - catch (Exception e) - { - e.printStackTrace(); - return new PredicateResult(false, this.phase, PredicateErrorCause.EXCEPTION_OCCURRED); - } - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java deleted file mode 100644 index 5be92cb5..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateResult.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; -import org.jetbrains.annotations.NotNull; - -public class PredicateResult extends PhaseResult -{ - public PredicateResult(boolean success, @NotNull PredicateState state, @NotNull PredicateErrorCause errorCause) - { - super(success, state, errorCause); - } - - public PredicateResult(boolean success, PredicateState state) - { - super(success, state, null); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java deleted file mode 100644 index d2b276c5..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/predicate/PredicateState.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.predicate; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; - -public enum PredicateState implements PhaseEnum -{ - INITIALIZED, - CHECK_RUN -} From cc00ea2c6f55e7ea4098ab46bec34e7b70990ea3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 3 May 2022 18:50:10 +0900 Subject: [PATCH 144/745] revert: wip: installer: As abstract --- .../PluginInstaller.java} | 23 ++++++++----------- .../plugin/installer/phase/PhaseArgument.java | 19 ++++++++++++++- .../description/DescriptionLoadArgument.java | 19 +++++++++++---- .../phases/download/DownloadArgument.java | 18 +++++++++++---- .../phases/resolve/PluginResolveArgument.java | 9 +++++++- 5 files changed, 63 insertions(+), 25 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{Installer.java => install/PluginInstaller.java} (77%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 70aa89aa..e26d7970 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -1,8 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; +import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallPhases; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.GeneralPhaseErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; @@ -15,17 +18,9 @@ import java.io.IOException; -public class Installer +public class PluginInstaller extends AbstractInstaller { - private static & PhaseEnum> InstallResult handlePhaseError(InstallProgress progress, PhaseResult result) - { - if (result.getErrorCause() != null) - return InstallResult.error(progress, result.getErrorCause(), result.getPhase()); - else - return InstallResult.error(progress, GeneralPhaseErrorCause.ILLEGAL_INTERNAL_STATE, result.getPhase()); - } - - public static InstallResult installPlugin(String query, InstallerSignalHandler signalHandler) + public InstallResult installPlugin(String query, InstallerSignalHandler signalHandler) { InstallProgress progress; @@ -68,7 +63,7 @@ public static InstallResult installPlugin(String query, InstallerSignalHandler s DescriptionLoadPhase descriptionLoadPhase = new DescriptionLoadPhase(progress, signalHandler); DescriptionLoadResult descriptionLoadResult = - descriptionLoadPhase.runPhase(DescriptionLoadArgument.of(downloadResult)); + descriptionLoadPhase.runPhase(new DescriptionLoadArgument(downloadResult)); if (!downloadResult.isSuccess()) return handlePhaseError(progress, downloadResult); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java index 6d5f3856..483e577f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java @@ -1,5 +1,22 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; -public interface PhaseArgument +import lombok.Getter; + +public abstract class PhaseArgument { + @Getter + private final boolean chain; + + public PhaseArgument(PhaseResult previousPhaseResult) + { + this.chain = true; + if (!previousPhaseResult.isSuccess()) + throw new IllegalStateException("Previous must be successful"); + + } + + public PhaseArgument() + { + this.chain = false; + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java index b0cdb7c7..8bb85720 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; @@ -8,16 +9,24 @@ import java.nio.file.Path; @Value -public class DescriptionLoadArgument implements PhaseArgument +@EqualsAndHashCode(callSuper = false) +public class DescriptionLoadArgument extends PhaseArgument { @NotNull Path pluginFile; - public static DescriptionLoadArgument of(@NotNull DownloadResult of) + public DescriptionLoadArgument(@NotNull Path pluginFile) { - if (!of.isSuccess() || of.getPath() == null) - throw new IllegalArgumentException("Download must be successful"); + this.pluginFile = pluginFile; + } + + public DescriptionLoadArgument(DownloadResult previousPhaseResult) + { + super(previousPhaseResult); + + if (previousPhaseResult.getPath() == null) + throw new IllegalArgumentException("DownloadResult.path is null"); - return new DescriptionLoadArgument(of.getPath()); + this.pluginFile = previousPhaseResult.getPath(); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java index 99716c9c..144b819d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java @@ -1,21 +1,31 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; import org.jetbrains.annotations.NotNull; @Value -public class DownloadArgument implements PhaseArgument +@EqualsAndHashCode(callSuper = false) +public class DownloadArgument extends PhaseArgument { @NotNull String url; - public static DownloadArgument of(@NotNull PluginResolveResult pluginResolveResult) + public DownloadArgument(@NotNull String url) { - if (!pluginResolveResult.isSuccess() || pluginResolveResult.getResolveResult() == null) + this.url = url; + } + + public DownloadArgument(@NotNull PluginResolveResult pluginResolveResult) + { + super(pluginResolveResult); + + if (pluginResolveResult.getResolveResult() == null) throw new IllegalArgumentException("Plugin Resolving must be successful"); - return new DownloadArgument(pluginResolveResult.getResolveResult().getDownloadUrl()); + this.url = pluginResolveResult.getResolveResult().getDownloadUrl(); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java index b6fb8e63..392979fd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java @@ -1,12 +1,19 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; import org.jetbrains.annotations.NotNull; @Data -public class PluginResolveArgument implements PhaseArgument +@EqualsAndHashCode(callSuper = false) +public class PluginResolveArgument extends PhaseArgument { @NotNull String query; + + public PluginResolveArgument(@NotNull String query) + { + this.query = query; + } } From 5b21351315f5266d91cef5ca03a3b32ddce027de Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 4 May 2022 00:28:07 +0900 Subject: [PATCH 145/745] revert: wip: installer: AbstractInstaller --- .../plugin/AbstractInstaller.java | 144 ++++++++++++++++++ .../installer/InstallFailedInstallResult.java | 9 +- .../plugin/installer/InstallProgress.java | 10 +- .../plugin/installer/InstallResult.java | 31 +--- .../installer/InstallerSignalHandler.java | 2 +- .../installer/install/InstallErrorCause.java | 10 ++ .../InstallPhase.java} | 4 +- .../installer/install/PluginInstaller.java | 45 +++--- .../plugin/installer/phase/InstallPhase.java | 2 +- .../phases/resolve/PluginResolvePhase.java | 2 +- 10 files changed, 194 insertions(+), 65 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{InstallPhases.java => install/InstallPhase.java} (61%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java new file mode 100644 index 00000000..7781c1fb --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -0,0 +1,144 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.GeneralPhaseErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public abstract class AbstractInstaller, P extends Enum

> +{ + protected final InstallProgress

progress; + protected final InstallerSignalHandler signalHandler; + + public AbstractInstaller(InstallerSignalHandler signalHandler) throws IOException + { + this.progress = new InstallProgress<>(true); + this.signalHandler = signalHandler; + } + + public abstract InstallResult

execute(@NotNull String query) throws IOException; + + @NotNull + protected InstallResult

success() + { + return new InstallResult<>(true, this.progress); + } + + public & PhaseEnum> InstallFailedInstallResult error(@NotNull T reason) + { // TODO: Implement debug mode + return new InstallFailedInstallResult<>(this.progress, reason); + } + + @SuppressWarnings("unchecked") + public & PhaseEnum, S extends Enum & PhaseEnum> InstallFailedInstallResult error( + @NotNull T reason, + @NotNull PhaseEnum phaseStatus) + { // TODO: Implement debug mode + return new InstallFailedInstallResult<>(this.progress, reason, (S) phaseStatus); + } + + @NotNull + protected & PhaseEnum> InstallResult

handlePhaseError(@NotNull PhaseResult result) + { + if (result.getErrorCause() != null) + return this.error(result.getErrorCause(), result.getPhase()); + else + return this.error(GeneralPhaseErrorCause.ILLEGAL_INTERNAL_STATE, result.getPhase()); + } + + @NotNull + @SuppressWarnings({"unchecked", "rawtypes"}) + private Constructor findConstructor(@NotNull Class argumentClass, + @NotNull Class phaseClass) + { + for (Constructor constructor : phaseClass.getConstructors()) + { + if (constructor.getParameterCount() == 1 + && constructor.getParameterTypes()[0].isAssignableFrom(argumentClass)) + { + constructor.setAccessible(true); + return (Constructor) constructor; + } + } + + throw new IllegalArgumentException("No constructor found for chain element: " + phaseClass.getName()); + } + + @NotNull + private Class getTypeParameterClass(Class clazz, int index) + { + return clazz.getTypeParameters()[index].getClass(); + } + + private PhaseArgument toArgument(@NotNull PhaseResult previousResult, + @NotNull Class argumentClass) + throws InvocationTargetException, InstantiationException, IllegalAccessException + { + Constructor constructor = + findConstructor(previousResult.getClass(), argumentClass); + + return constructor.newInstance(previousResult); + } + + @NotNull + private PhaseResult submitPhase(@NotNull PhaseArgument phaseArgument, + @NotNull InstallPhase phase) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException + { + Method executeMethod = phase.getClass().getMethod("runPhase", PhaseArgument.class); + executeMethod.setAccessible(true); + + return (PhaseResult) executeMethod.invoke(phase, phaseArgument); + } + + private PhaseResult submitPhase(PhaseResult phaseArgument, InstallPhase phase) + throws InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException + { + PhaseArgument argument = toArgument(phaseArgument, getTypeParameterClass(phase.getClass(), 0)); + + return submitPhase(argument, phase); + } + + @Nullable + protected InstallPhase submitPhase(@NotNull PhaseArgument firstArgument, @NotNull InstallPhase... phases) + { + InstallPhase tryingPhase = null; // Return null if no error occurs in all phases. + PhaseResult phaseResult = null; + + try + { + for (InstallPhase phase : phases) + { + if (phaseResult != null && !phaseResult.isSuccess()) + break; + + tryingPhase = phase; + if (phaseResult == null) + phaseResult = submitPhase(firstArgument, phase); + else + phaseResult = submitPhase(phaseResult, phase); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + if (phaseResult != null && !phaseResult.isSuccess()) + return tryingPhase; + else + return null; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index abb096af..ad3b4225 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -6,21 +6,22 @@ import org.jetbrains.annotations.Nullable; @Getter -public class InstallFailedInstallResult & PhaseEnum> extends InstallResult +public class InstallFailedInstallResult

, T extends Enum & PhaseEnum, S extends Enum & PhaseEnum> + extends InstallResult

{ @NotNull private final T reason; @Nullable - private final PhaseEnum phaseStatus; + private final S phaseStatus; - InstallFailedInstallResult(@NotNull InstallProgress progress, @NotNull T reason, @NotNull PhaseEnum phaseStatus) + public InstallFailedInstallResult(@NotNull InstallProgress

progress, @NotNull T reason, @NotNull S phaseStatus) { super(false, progress); this.reason = reason; this.phaseStatus = phaseStatus; } - public InstallFailedInstallResult(InstallProgress progress, @NotNull T reason) + public InstallFailedInstallResult(InstallProgress

progress, @NotNull T reason) { super(false, progress); this.reason = reason; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 7d6b4e64..2a6dbd4c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -13,10 +13,10 @@ import java.util.UUID; @Getter -public class InstallProgress +public class InstallProgress

> { @Setter - private InstallPhases phase; + private P phase; private final List upgraded; private final List installed; @@ -33,7 +33,7 @@ public InstallProgress(boolean createTempDir) throws IOException, SecurityExcept this.removed = new ArrayList<>(); this.pending = new ArrayList<>(); - this.phase = InstallPhases.STARTED; + this.phase = null; this.installActionID = UUID.randomUUID(); @@ -49,11 +49,11 @@ public InstallProgress(boolean createTempDir) throws IOException, SecurityExcept ); } - public static InstallProgress dummy() + public static InstallProgress dummy() { try { - return new InstallProgress(false); + return new InstallProgress<>(false); } catch (IOException e) { // should not happen diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java index f4542875..871601ed 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -1,42 +1,27 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; +import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.HoverEvent; import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; -@AllArgsConstructor(access = AccessLevel.PACKAGE) -public class InstallResult +public class InstallResult

> { private static final int MAX_RESULT_HOVER_ONE_LINE = 5; + @Getter private final boolean success; - private final InstallProgress progress; + @Getter + private final InstallProgress

progress; - public static InstallResult success(@NotNull InstallProgress progress) + public InstallResult(boolean success, InstallProgress

progress) { progress.finish(); - return new InstallResult(true, progress); - } - - public static & PhaseEnum> InstallFailedInstallResult error(@NotNull InstallProgress progress, - @NotNull T reason) - { // TODO: Implement debug mode - progress.finish(); - return new InstallFailedInstallResult<>(progress, reason); - } - - public static & PhaseEnum> InstallFailedInstallResult error(@NotNull InstallProgress progress, - @NotNull T reason, - @NotNull PhaseEnum phaseStatus) - { // TODO: Implement debug mode - progress.finish(); - return new InstallFailedInstallResult<>(progress, reason, phaseStatus); + this.success = success; + this.progress = progress; } private static TextComponent getResultStatusComponent(@NotNull String[] components, @NotNull String hoverPrefix) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java index defbb82e..4b00e8e2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java @@ -5,5 +5,5 @@ @FunctionalInterface public interface InstallerSignalHandler { - void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal); + void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java new file mode 100644 index 00000000..fc1f14f8 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; + +public enum InstallErrorCause +{ + PHASE_EXCEPTION_OCCURRED, + PHASE_FAILED, + + EXCEPTION_OCCURRED, + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhases.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhase.java similarity index 61% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhases.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhase.java index 4fca778a..547d8dc3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallPhases.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhase.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; -public enum InstallPhases +public enum InstallPhase { // General phases STARTED, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index e26d7970..3413c46b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -1,11 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallPhases; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.GeneralPhaseErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; @@ -15,58 +12,50 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; +import org.jetbrains.annotations.NotNull; import java.io.IOException; -public class PluginInstaller extends AbstractInstaller +public class PluginInstaller extends AbstractInstaller { - public InstallResult installPlugin(String query, InstallerSignalHandler signalHandler) + public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOException { - InstallProgress progress; - - // region Initialize install. Phase: INITIALIZING - try - { - progress = new InstallProgress(true); - progress.setPhase(InstallPhases.INITIALIZING); - } - catch (IOException | SecurityException e) - { - return InstallResult.error(InstallProgress.dummy(), GeneralPhaseErrorCause.IO_EXCEPTION_OCCURRED); - } - - // endregion + super(signalHandler); + } + public InstallResult execute(@NotNull String query) + { // region Query resolving. Phase: QUERY_RESOLVE - progress.setPhase(InstallPhases.QUERY_RESOLVING); + this.progress.setPhase(InstallPhase.QUERY_RESOLVING); PluginResolvePhase resolvePhase = new PluginResolvePhase(progress, signalHandler); PluginResolveResult resolveResult = resolvePhase.runPhase(new PluginResolveArgument(query)); - if (!resolveResult.isSuccess() || resolveResult.getResolveResult() == null) // getResolveResult() == null is never true. - return handlePhaseError(progress, resolveResult); + if (!resolveResult.isSuccess() || resolveResult.getResolveResult() == null) + // getResolveResult() == null is never true. + return handlePhaseError(resolveResult); // endregion - // region Downloading. Phase: START_DOWNLOADING=>DOWNLOADING - progress.setPhase(InstallPhases.DOWNLOADING); + // region Downloading. Phase: DOWNLOADING + this.progress.setPhase(InstallPhase.DOWNLOADING); DownloadPhase downloadPhase = new DownloadPhase(progress, signalHandler); - DownloadResult downloadResult = downloadPhase.runPhase(DownloadArgument.of(resolveResult)); + DownloadResult downloadResult = downloadPhase.runPhase(new DownloadArgument(resolveResult)); if (!downloadResult.isSuccess()) - return handlePhaseError(progress, downloadResult); + return handlePhaseError(downloadResult); // endregion // region Load plugin.yml. Phase: LOADING_PLUGIN_DESCRIPTION - progress.setPhase(InstallPhases.LOADING_PLUGIN_DESCRIPTION); + progress.setPhase(InstallPhase.LOADING_PLUGIN_DESCRIPTION); DescriptionLoadPhase descriptionLoadPhase = new DescriptionLoadPhase(progress, signalHandler); DescriptionLoadResult descriptionLoadResult = descriptionLoadPhase.runPhase(new DescriptionLoadArgument(downloadResult)); if (!downloadResult.isSuccess()) - return handlePhaseError(progress, downloadResult); + return handlePhaseError(downloadResult); // endregion // region Check the plugin is already installed. Phase: CHECK_INSTALLED diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java index db6c08c5..ee796734 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java @@ -10,7 +10,7 @@ public abstract class InstallPhase, ? extends Enum>> { @NotNull - protected final InstallProgress progress; + protected final InstallProgress progress; @NotNull private final InstallerSignalHandler signalHandler; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java index a3e8554e..3d2de359 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java @@ -26,7 +26,7 @@ public class PluginResolvePhase extends InstallPhase progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); From a076ca2a28777d78797ced0787b5813372bff147 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 4 May 2022 03:13:01 +0900 Subject: [PATCH 146/745] revert: wip: installer: Remove PhaseEnum --- .../plugin/AbstractInstaller.java | 12 +++++------- .../plugin/installer/InstallFailedInstallResult.java | 3 +-- .../installer/phase/GeneralPhaseErrorCause.java | 2 +- .../plugin/installer/phase/PhaseEnum.java | 5 ----- .../plugin/installer/phase/PhaseResult.java | 2 +- .../description/DescriptionLoadErrorCause.java | 3 +-- .../phases/description/DescriptionLoadState.java | 3 +-- .../phase/phases/download/DownloadErrorCause.java | 3 +-- .../phase/phases/download/DownloadState.java | 3 +-- .../phases/resolve/PluginResolveErrorCause.java | 3 +-- .../phase/phases/resolve/PluginResolveState.java | 4 +--- 11 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index 7781c1fb..a9f02f86 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -7,7 +7,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.GeneralPhaseErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,21 +35,20 @@ protected InstallResult

success() return new InstallResult<>(true, this.progress); } - public & PhaseEnum> InstallFailedInstallResult error(@NotNull T reason) + public > InstallFailedInstallResult error(@NotNull T reason) { // TODO: Implement debug mode return new InstallFailedInstallResult<>(this.progress, reason); } - @SuppressWarnings("unchecked") - public & PhaseEnum, S extends Enum & PhaseEnum> InstallFailedInstallResult error( + public , S extends Enum> InstallFailedInstallResult error( @NotNull T reason, - @NotNull PhaseEnum phaseStatus) + @NotNull S phaseStatus) { // TODO: Implement debug mode - return new InstallFailedInstallResult<>(this.progress, reason, (S) phaseStatus); + return new InstallFailedInstallResult<>(this.progress, reason, phaseStatus); } @NotNull - protected & PhaseEnum> InstallResult

handlePhaseError(@NotNull PhaseResult result) + protected , T extends Enum> InstallResult

handlePhaseError(@NotNull PhaseResult result) { if (result.getErrorCause() != null) return this.error(result.getErrorCause(), result.getPhase()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index ad3b4225..4279fadc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -1,12 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @Getter -public class InstallFailedInstallResult

, T extends Enum & PhaseEnum, S extends Enum & PhaseEnum> +public class InstallFailedInstallResult

, T extends Enum, S extends Enum> extends InstallResult

{ @NotNull diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java index ff3eb194..af3f1821 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; -public enum GeneralPhaseErrorCause implements PhaseEnum +public enum GeneralPhaseErrorCause { // General internal errors ILLEGAL_INTERNAL_STATE, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java deleted file mode 100644 index 9191b2bd..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseEnum.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; - -public interface PhaseEnum -{ -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java index 0d550152..2d4df0a5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java @@ -7,7 +7,7 @@ @AllArgsConstructor @Getter -public abstract class PhaseResult & PhaseEnum, C extends Enum & PhaseEnum> +public abstract class PhaseResult, C extends Enum> { private final boolean success; @NotNull diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java index a40978f2..02b5c165 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; -public enum DescriptionLoadErrorCause implements PhaseEnum +public enum DescriptionLoadErrorCause { NOT_A_PLUGIN, INVALID_DESCRIPTION, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java index d18693de..7f25f7f6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; -public enum DescriptionLoadState implements PhaseEnum +public enum DescriptionLoadState { INITIALIZED, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java index fbbfc746..780d035e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; -public enum DownloadErrorCause implements PhaseEnum +public enum DownloadErrorCause { ILLEGAL_HTTP_RESPONSE, NO_BODY_IN_RESPONSE, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java index 0dd4f7c4..dfd03323 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadState.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; -public enum DownloadState implements PhaseEnum +public enum DownloadState { INITIALIZED, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java index badb4ddd..1c661cdf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; -public enum PluginResolveErrorCause implements PhaseEnum +public enum PluginResolveErrorCause { ILLEGAL_INTERNAL_STATE, GOT_ERROR_RESULT diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java index a0ac0f31..15f43f90 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java @@ -1,8 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseEnum; - -public enum PluginResolveState implements PhaseEnum +public enum PluginResolveState { INITIALIZED, From ff4fd27d40dce39193f0d2a163a835ed9a92351f Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 5 May 2022 00:14:22 +0900 Subject: [PATCH 147/745] fix: wip: installer: generic --- .../phase/phases/description/DescriptionLoadPhase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java index 3b26a92e..6b028306 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java @@ -15,7 +15,7 @@ public class DescriptionLoadPhase extends InstallPhase progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); this.phaseState = DescriptionLoadState.INITIALIZED; From 4c99bd55a44ee8629c46230a90e2a47828dc5115 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 5 May 2022 20:06:05 +0900 Subject: [PATCH 148/745] feat: wip: installer: Submitter --- .../plugin/AbstractInstaller.java | 91 +------------ .../installer/install/InstallErrorCause.java | 5 +- .../{InstallPhase.java => InstallPhases.java} | 5 +- .../installer/install/PluginInstaller.java | 47 ++----- .../installer/phase/PhaseSubmitter.java | 125 ++++++++++++++++++ 5 files changed, 148 insertions(+), 125 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/{InstallPhase.java => InstallPhases.java} (70%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index a9f02f86..411e7f78 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin; +import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; @@ -8,16 +9,14 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseSubmitter; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; public abstract class AbstractInstaller, P extends Enum

> { + @Getter protected final InstallProgress

progress; protected final InstallerSignalHandler signalHandler; @@ -56,87 +55,11 @@ protected , T extends Enum> InstallResult

handlePhaseErr return this.error(GeneralPhaseErrorCause.ILLEGAL_INTERNAL_STATE, result.getPhase()); } - @NotNull - @SuppressWarnings({"unchecked", "rawtypes"}) - private Constructor findConstructor(@NotNull Class argumentClass, - @NotNull Class phaseClass) + protected , PP extends InstallPhase> + PhaseSubmitter, A, R, PP> + submitter(@NotNull P phaseState, @NotNull PP phase) { - for (Constructor constructor : phaseClass.getConstructors()) - { - if (constructor.getParameterCount() == 1 - && constructor.getParameterTypes()[0].isAssignableFrom(argumentClass)) - { - constructor.setAccessible(true); - return (Constructor) constructor; - } - } - - throw new IllegalArgumentException("No constructor found for chain element: " + phaseClass.getName()); + return new PhaseSubmitter<>(phaseState, this, phase); } - @NotNull - private Class getTypeParameterClass(Class clazz, int index) - { - return clazz.getTypeParameters()[index].getClass(); - } - - private PhaseArgument toArgument(@NotNull PhaseResult previousResult, - @NotNull Class argumentClass) - throws InvocationTargetException, InstantiationException, IllegalAccessException - { - Constructor constructor = - findConstructor(previousResult.getClass(), argumentClass); - - return constructor.newInstance(previousResult); - } - - @NotNull - private PhaseResult submitPhase(@NotNull PhaseArgument phaseArgument, - @NotNull InstallPhase phase) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException - { - Method executeMethod = phase.getClass().getMethod("runPhase", PhaseArgument.class); - executeMethod.setAccessible(true); - - return (PhaseResult) executeMethod.invoke(phase, phaseArgument); - } - - private PhaseResult submitPhase(PhaseResult phaseArgument, InstallPhase phase) - throws InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException - { - PhaseArgument argument = toArgument(phaseArgument, getTypeParameterClass(phase.getClass(), 0)); - - return submitPhase(argument, phase); - } - - @Nullable - protected InstallPhase submitPhase(@NotNull PhaseArgument firstArgument, @NotNull InstallPhase... phases) - { - InstallPhase tryingPhase = null; // Return null if no error occurs in all phases. - PhaseResult phaseResult = null; - - try - { - for (InstallPhase phase : phases) - { - if (phaseResult != null && !phaseResult.isSuccess()) - break; - - tryingPhase = phase; - if (phaseResult == null) - phaseResult = submitPhase(firstArgument, phase); - else - phaseResult = submitPhase(phaseResult, phase); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - - if (phaseResult != null && !phaseResult.isSuccess()) - return tryingPhase; - else - return null; - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java index fc1f14f8..c71eea81 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java @@ -5,6 +5,9 @@ public enum InstallErrorCause PHASE_EXCEPTION_OCCURRED, PHASE_FAILED, - EXCEPTION_OCCURRED, + // Environment errors + IGNORED_PLUGIN, + ALREADY_INSTALLED, + EXCEPTION_OCCURRED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java similarity index 70% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java index 547d8dc3..f5d32140 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; -public enum InstallPhase +public enum InstallPhases { // General phases STARTED, @@ -9,6 +9,7 @@ public enum InstallPhase // Install phases QUERY_RESOLVING, DOWNLOADING, - LOADING_PLUGIN_DESCRIPTION + PLUGIN_DESCRIPTION_LOADING, + CHECK_ENVIRONMENT, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 3413c46b..a6eb8ecf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -3,61 +3,32 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; import org.jetbrains.annotations.NotNull; import java.io.IOException; -public class PluginInstaller extends AbstractInstaller +public class PluginInstaller extends AbstractInstaller { public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOException { super(signalHandler); } - public InstallResult execute(@NotNull String query) + public InstallResult execute(@NotNull String query) { - // region Query resolving. Phase: QUERY_RESOLVE - this.progress.setPhase(InstallPhase.QUERY_RESOLVING); + DescriptionLoadResult pluginDescriptionResult = (DescriptionLoadResult) + this.submitter(InstallPhases.QUERY_RESOLVING, new PluginResolvePhase(progress, signalHandler)) + .then(InstallPhases.DOWNLOADING, new DownloadPhase(progress, signalHandler)) + .then(InstallPhases.PLUGIN_DESCRIPTION_LOADING, new DescriptionLoadPhase(progress, signalHandler)) + .submit(new PluginResolveArgument(query)); - PluginResolvePhase resolvePhase = new PluginResolvePhase(progress, signalHandler); - PluginResolveResult resolveResult = resolvePhase.runPhase(new PluginResolveArgument(query)); + if (!pluginDescriptionResult.isSuccess()) + return handlePhaseError(pluginDescriptionResult); - if (!resolveResult.isSuccess() || resolveResult.getResolveResult() == null) - // getResolveResult() == null is never true. - return handlePhaseError(resolveResult); - // endregion - - // region Downloading. Phase: DOWNLOADING - this.progress.setPhase(InstallPhase.DOWNLOADING); - - DownloadPhase downloadPhase = new DownloadPhase(progress, signalHandler); - DownloadResult downloadResult = downloadPhase.runPhase(new DownloadArgument(resolveResult)); - - if (!downloadResult.isSuccess()) - return handlePhaseError(downloadResult); - - // endregion - - // region Load plugin.yml. Phase: LOADING_PLUGIN_DESCRIPTION - progress.setPhase(InstallPhase.LOADING_PLUGIN_DESCRIPTION); - - DescriptionLoadPhase descriptionLoadPhase = new DescriptionLoadPhase(progress, signalHandler); - DescriptionLoadResult descriptionLoadResult = - descriptionLoadPhase.runPhase(new DescriptionLoadArgument(downloadResult)); - - if (!downloadResult.isSuccess()) - return handlePhaseError(downloadResult); - // endregion - - // region Check the plugin is already installed. Phase: CHECK_INSTALLED } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java new file mode 100644 index 00000000..fc8d4ea3 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java @@ -0,0 +1,125 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; + +import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +public class PhaseSubmitter< + T extends PhaseArgument, + P extends Enum

, + I extends AbstractInstaller, + A extends PhaseArgument, + R extends PhaseResult, + E extends InstallPhase> +{ + @NotNull + private final I installer; + @NotNull + private final E phase; + @NotNull + private final P phaseState; + + @NotNull + private final PhaseSubmitter first; + @Nullable + private PhaseSubmitter next; + + public PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E phase) + { + this(phaseState, installer, phase, null, null); + } + + private PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E phase, + @Nullable PhaseSubmitter first, @Nullable PhaseSubmitter next) + { + this.installer = installer; + this.phase = phase; + this.phaseState = phaseState; + + this.next = next; + + if (first == null) + this.first = this; + else + this.first = first; + } + + public , PE extends InstallPhase> + @NotNull PhaseSubmitter then(@NotNull P phaseState, @NotNull PE phase) + { + PhaseSubmitter submitter = new PhaseSubmitter<>(phaseState, installer, phase, this.first, null); + this.next = submitter; + + return submitter; + } + + public @NotNull R submitOnce(@NotNull A argument) + { + return this.phase.runPhase(argument); + } + + @SuppressWarnings("unchecked") + protected @NotNull R submitOnceUnsafe(@NotNull PA argument) + { + return this.phase.runPhase((A) argument); + } + + public @NotNull PhaseResult submit(@NotNull T firstArgument) + { + PhaseSubmitter submitter = this.first; + + installer.getProgress().setPhase(phaseState); + PhaseResult result = submitter.submitOnceUnsafe(firstArgument); + + try + { + while (submitter.next != null) + { + submitter = submitter.next; + + installer.getProgress().setPhase(submitter.phaseState); + PhaseArgument nextArgument = getConstructor(result).newInstance(result); + + result = submitter.submitOnceUnsafe(nextArgument); + + if (!result.isSuccess()) + return result; + } + } + catch (InstantiationException | IllegalAccessException | InvocationTargetException e) + { + e.printStackTrace(); + } + + return result; + } + + @SuppressWarnings("unchecked") + private Constructor getConstructor(@NotNull PhaseResult parentResult) + { + Class argumentClass = PhaseArgument.class; + + try + { + for (Constructor constructor : argumentClass.getConstructors()) + { + Class[] parameterTypes = constructor.getParameterTypes(); + if (parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(parentResult.getClass())) + { + constructor.setAccessible(true); + return (Constructor) constructor; + } + } + } + catch (Exception e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + + throw new IllegalArgumentException("No constructor found for " + argumentClass.getName()); + } +} From b77c0ffc694af19116b0889074d31c3b3abaf9e2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 6 May 2022 03:17:28 +0900 Subject: [PATCH 149/745] feat: wip: installer: Plugin assertion --- .../plugin/AbstractInstaller.java | 14 +++++ .../installer/install/InstallErrorCause.java | 4 +- .../installer/install/PluginInstaller.java | 51 +++++++++++++++++++ .../signals/IgnoredPluginSignal.java | 12 ----- .../AlreadyInstalledPluginSignal.java | 25 +++++++++ .../assertion/IgnoredPluginSignal.java | 25 +++++++++ 6 files changed, 117 insertions(+), 14 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/AlreadyInstalledPluginSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index 411e7f78..df01954c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -1,9 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.plugin; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.GeneralPhaseErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; @@ -26,6 +28,11 @@ public AbstractInstaller(InstallerSignalHandler signalHandler) throws IOExceptio this.signalHandler = signalHandler; } + protected void postSignal(@NotNull InstallerSignal signal) + { + this.signalHandler.handleSignal(this.progress, signal); + } + public abstract InstallResult

execute(@NotNull String query) throws IOException; @NotNull @@ -55,6 +62,7 @@ protected , T extends Enum> InstallResult

handlePhaseErr return this.error(GeneralPhaseErrorCause.ILLEGAL_INTERNAL_STATE, result.getPhase()); } + @NotNull protected , PP extends InstallPhase> PhaseSubmitter, A, R, PP> submitter(@NotNull P phaseState, @NotNull PP phase) @@ -62,4 +70,10 @@ protected , T extends Enum> InstallResult

handlePhaseErr return new PhaseSubmitter<>(phaseState, this, phase); } + protected boolean isPluginIgnored(@NotNull String pluginName) + { + return TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream() + .parallel() + .anyMatch(s -> s.equalsIgnoreCase(pluginName)); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java index c71eea81..4731cc0a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java @@ -6,8 +6,8 @@ public enum InstallErrorCause PHASE_FAILED, // Environment errors - IGNORED_PLUGIN, - ALREADY_INSTALLED, + PLUGIN_IGNORED, + PLUGIN_ALREADY_INSTALLED, EXCEPTION_OCCURRED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index a6eb8ecf..9f776e36 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -8,6 +8,11 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -19,8 +24,13 @@ public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOE super(signalHandler); } + @Override public InstallResult execute(@NotNull String query) { + PluginDescriptionFile pluginDescription; + String pluginName; + // region Do plugin resolve, download and description load. + DescriptionLoadResult pluginDescriptionResult = (DescriptionLoadResult) this.submitter(InstallPhases.QUERY_RESOLVING, new PluginResolvePhase(progress, signalHandler)) .then(InstallPhases.DOWNLOADING, new DownloadPhase(progress, signalHandler)) @@ -30,5 +40,46 @@ public InstallResult execute(@NotNull String query) if (!pluginDescriptionResult.isSuccess()) return handlePhaseError(pluginDescriptionResult); + pluginDescription = pluginDescriptionResult.getDescription(); + assert pluginDescription != null; // Not null because isSuccess() is true. + + pluginName = pluginDescription.getName(); + // endregion + + boolean replacePlugin = false; + // region Do assertions. + + // region Check if plugin is ignored. + if (this.isPluginIgnored(pluginName)) + { + IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(pluginDescription); + this.postSignal(ignoredPluginSignal); + + if (ignoredPluginSignal.isCancelInstall()) + return this.error(InstallErrorCause.PLUGIN_IGNORED); + } + // endregion + + // region Check if plugin is already installed. + + Plugin sameServerPlugin = Bukkit.getPluginManager().getPlugin(pluginName); + + if (sameServerPlugin != null) + { + AlreadyInstalledPluginSignal alreadyInstalledPluginSignal = + new AlreadyInstalledPluginSignal(sameServerPlugin.getDescription(), pluginDescription); + + this.postSignal(alreadyInstalledPluginSignal); + replacePlugin = alreadyInstalledPluginSignal.isReplacePlugin(); + + if (!replacePlugin) + return this.error(InstallErrorCause.PLUGIN_ALREADY_INSTALLED); + } + + // endregion + + // endregion + + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java deleted file mode 100644 index 5aa73b72..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/IgnoredPluginSignal.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals; - -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import org.jetbrains.annotations.NotNull; - -@Value -public class IgnoredPluginSignal implements InstallerSignal -{ - @NotNull - String pluginName; -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/AlreadyInstalledPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/AlreadyInstalledPluginSignal.java new file mode 100644 index 00000000..d60be946 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/AlreadyInstalledPluginSignal.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +@Data +public class AlreadyInstalledPluginSignal implements InstallerSignal +{ + @NotNull + private final PluginDescriptionFile installedPlugin; + + @NotNull + private final PluginDescriptionFile installingPlugin; + + private boolean replacePlugin; + + public AlreadyInstalledPluginSignal(@NotNull PluginDescriptionFile installedPlugin, @NotNull PluginDescriptionFile installingPlugin) + { + this.installedPlugin = installedPlugin; + this.installingPlugin = installingPlugin; + this.replacePlugin = false; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java new file mode 100644 index 00000000..5d65faeb --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +@Data +public class IgnoredPluginSignal implements InstallerSignal +{ + @NotNull + private final String pluginName; + @NotNull + private final PluginDescriptionFile pluginDescription; + + private boolean cancelInstall; + + public IgnoredPluginSignal(@NotNull PluginDescriptionFile pluginDescription) + { + this.pluginDescription = pluginDescription; + this.pluginName = pluginDescription.getName(); + + this.cancelInstall = true; + } +} From 8ca55c9d59f7e2c0f4d212481016c04d87659008 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 6 May 2022 03:39:08 +0900 Subject: [PATCH 150/745] fix: wip: installer: delete error --- .../teamkunpluginmanager/plugin/installer/InstallProgress.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 2a6dbd4c..347332ef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -3,6 +3,7 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -101,7 +102,7 @@ public void finish() { try { - Files.deleteIfExists(this.installTempDir); + FileUtils.forceDelete(this.installTempDir.toFile()); } catch (IOException e) { From 4449c0459fd44115082cfd76508efe29ec018fb6 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 6 May 2022 03:43:29 +0900 Subject: [PATCH 151/745] refactor: wip: installer: unity names --- .../plugin/installer/install/InstallPhases.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java index f5d32140..a2a4d260 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java @@ -7,9 +7,9 @@ public enum InstallPhases INITIALIZING, // Install phases - QUERY_RESOLVING, + RESOLVING_QUERY, DOWNLOADING, - PLUGIN_DESCRIPTION_LOADING, - CHECK_ENVIRONMENT, + LOADING_PLUGIN_DESCRIPTION, + CHECKING_ENVIRONMENT, } From 18d6148129f5c294e7e640f4477cfb51ecffdc8c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 6 May 2022 03:43:55 +0900 Subject: [PATCH 152/745] fix: wip: installer: Status change: CHECK_ENVIRONMENT --- .../plugin/installer/install/PluginInstaller.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 9f776e36..cfda75e9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -32,9 +32,9 @@ public InstallResult execute(@NotNull String query) // region Do plugin resolve, download and description load. DescriptionLoadResult pluginDescriptionResult = (DescriptionLoadResult) - this.submitter(InstallPhases.QUERY_RESOLVING, new PluginResolvePhase(progress, signalHandler)) + this.submitter(InstallPhases.RESOLVING_QUERY, new PluginResolvePhase(progress, signalHandler)) .then(InstallPhases.DOWNLOADING, new DownloadPhase(progress, signalHandler)) - .then(InstallPhases.PLUGIN_DESCRIPTION_LOADING, new DescriptionLoadPhase(progress, signalHandler)) + .then(InstallPhases.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadPhase(progress, signalHandler)) .submit(new PluginResolveArgument(query)); if (!pluginDescriptionResult.isSuccess()) @@ -49,6 +49,8 @@ public InstallResult execute(@NotNull String query) boolean replacePlugin = false; // region Do assertions. + this.progress.setPhase(InstallPhases.CHECKING_ENVIRONMENT); + // region Check if plugin is ignored. if (this.isPluginIgnored(pluginName)) { From 7cfce73e2d7c5dcbbab3b71e724a317d215032b3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 8 May 2022 00:25:01 +0900 Subject: [PATCH 153/745] feat: wip: installer: Modify signal --- .../signals/PluginModifiedSignal.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java new file mode 100644 index 00000000..27578b23 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java @@ -0,0 +1,24 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +@Value +public class PluginModifiedSignal implements InstallerSignal +{ + @NotNull + String pluginName; + @NotNull + PluginDescriptionFile pluginDescription; + @NotNull + ModifyType modifyType; + + public enum ModifyType + { + ADD, + REMOVE, + UPGRADE + } +} From c358cd2a20dcef7b6e126225fe36403129fbc78e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 8 May 2022 03:26:02 +0900 Subject: [PATCH 154/745] feat: wip: installer: Replace plugin --- .../plugin/AbstractInstaller.java | 14 ++++++++++ .../installer/install/InstallPhases.java | 2 +- .../installer/install/PluginInstaller.java | 26 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index df01954c..de129477 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -14,6 +14,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseSubmitter; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.io.IOException; public abstract class AbstractInstaller, P extends Enum

> @@ -76,4 +77,17 @@ protected boolean isPluginIgnored(@NotNull String pluginName) .parallel() .anyMatch(s -> s.equalsIgnoreCase(pluginName)); } + + protected boolean safeDelete(@NotNull File f) + { + try + { + return f.delete(); + } + catch (SecurityException e) + { + e.printStackTrace(); + return false; + } + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java index a2a4d260..e64c0bed 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java @@ -11,5 +11,5 @@ public enum InstallPhases DOWNLOADING, LOADING_PLUGIN_DESCRIPTION, CHECKING_ENVIRONMENT, - + REMOVING_OLD_PLUGIN, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index cfda75e9..01265e32 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; @@ -10,11 +11,13 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.io.IOException; public class PluginInstaller extends AbstractInstaller @@ -82,6 +85,29 @@ public InstallResult execute(@NotNull String query) // endregion + // region Remove plugin if it is already installed. (only replacePlugin is true) + if (replacePlugin) + { + this.progress.setPhase(InstallPhases.REMOVING_OLD_PLUGIN); + + File oldPluginFile = PluginUtil.getFile(sameServerPlugin); + + PluginUtil.unload(sameServerPlugin); // TODO: Replace with uninstall. + + if (!safeDelete(oldPluginFile)) + Runner.runLater(() -> { + safeDelete(oldPluginFile); + }, 10L); + } + // endregion + + // TODO: write process + + if (replacePlugin) + this.progress.addUpgraded(pluginName); + else + this.progress.addInstalled(pluginName); + return this.success(); } } From ae826334a6c7a3f8eb7abb65cabdf9ad647fd6b9 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 10 May 2022 18:55:49 +0900 Subject: [PATCH 155/745] fix: wip: installer: Generics --- .../plugin/installer/phase/phases/download/DownloadPhase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java index c787b33b..c3387da3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java @@ -19,7 +19,7 @@ public class DownloadPhase extends InstallPhase progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); From f654634c52f2e2c11f2ac17dc98e6505df78ab7d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 10 May 2022 19:05:00 +0900 Subject: [PATCH 156/745] refactor: wip: installer: Generate random download id --- .../phase/phases/download/DownloadPhase.java | 23 +++++++++++++------ .../phase/phases/download/DownloadResult.java | 11 ++++++--- .../download/signals/DownloadErrorSignal.java | 2 ++ .../signals/DownloadProgressSignal.java | 4 ++++ .../signals/DownloadStartingSignal.java | 3 +++ .../signals/DownloadSucceedSignal.java | 9 +++----- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java index c3387da3..00bc776b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java @@ -14,15 +14,20 @@ import java.io.IOException; import java.nio.file.Path; +import java.util.UUID; public class DownloadPhase extends InstallPhase { + private final String randomDownloadID; + private DownloadState phaseState; public DownloadPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); + this.randomDownloadID = UUID.randomUUID().toString(); + this.phaseState = DownloadState.INITIALIZED; } @@ -31,6 +36,7 @@ private void onDownload(DownloadProgress downloadProgress) this.phaseState = DownloadState.DOWNLOADING; this.postSignal(new DownloadProgressSignal( + this.randomDownloadID, downloadProgress.getTotalSize(), downloadProgress.getDownloaded(), downloadProgress.getPercentage() @@ -41,7 +47,8 @@ private void onDownload(DownloadProgress downloadProgress) public @NotNull DownloadResult runPhase(@NotNull DownloadArgument arguments) { DownloadStartingSignal downloadingSignal = new DownloadStartingSignal( - progress.getInstallTempDir().resolve(progress.getInstallActionID().toString() + ".jar"), + this.randomDownloadID, + progress.getInstallTempDir().resolve(this.randomDownloadID + ".jar"), arguments.getUrl() ); @@ -55,9 +62,9 @@ private void onDownload(DownloadProgress downloadProgress) { long size = Requests.downloadFile(RequestMethod.GET, url, path, this::onDownload); - this.postSignal(new DownloadSucceedSignal(path, size)); + this.postSignal(new DownloadSucceedSignal(this.randomDownloadID, path, size)); - return new DownloadResult(true, this.phaseState, path, size); + return new DownloadResult(true, this.phaseState, path, size, this.randomDownloadID); } catch (IOException e) { @@ -80,16 +87,18 @@ else if (e.getMessage().startsWith("No response body was returned")) signalValue = e; } - DownloadErrorSignal error = new DownloadErrorSignal(cause, signalValue); + DownloadErrorSignal error = new DownloadErrorSignal(cause, this.randomDownloadID, signalValue); this.postSignal(error); - return new DownloadResult(true, this.phaseState, path, -1, cause); + return new DownloadResult(true, this.phaseState, path, -1, this.randomDownloadID, cause); } catch (Exception e) { - this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, e)); + this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, this.randomDownloadID, e)); - return new DownloadResult(true, this.phaseState, path, -1, DownloadErrorCause.UNKNOWN_ERROR); + return new DownloadResult(true, this.phaseState, path, -1, this.randomDownloadID, + DownloadErrorCause.UNKNOWN_ERROR + ); } } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java index 2a172a51..8bd02268 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java @@ -14,16 +14,21 @@ public class DownloadResult extends PhaseResult Date: Wed, 11 May 2022 00:39:13 +0900 Subject: [PATCH 157/745] feat: wip: installer: Dependencies collector --- .../installer/install/PluginInstaller.java | 2 +- .../depends/DependsCollectArgument.java | 43 +++ .../depends/DependsCollectErrorCause.java | 6 + .../phases/depends/DependsCollectPhase.java | 286 ++++++++++++++++++ .../phases/depends/DependsCollectResult.java | 35 +++ .../phases/depends/DependsCollectState.java | 11 + ...endsCollectDependsDependsFailedSignal.java | 16 + .../DependsDescriptionLoadFailedSignal.java | 12 + .../signals/DependsDownloadFailedSignal.java | 14 + .../signals/DependsEnumeratedSignal.java | 15 + .../signals/DependsResolveFailedSignal.java | 12 + 11 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCollectDependsDependsFailedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDescriptionLoadFailedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsEnumeratedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 01265e32..ce0e9b79 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -101,7 +101,7 @@ public InstallResult execute(@NotNull String query) } // endregion - // TODO: write process + // TODO: write collect depends process if (replacePlugin) this.progress.addUpgraded(pluginName); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java new file mode 100644 index 00000000..cd3d745f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java @@ -0,0 +1,43 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@Value +@EqualsAndHashCode(callSuper = false) +public class DependsCollectArgument extends PhaseArgument +{ + @NotNull + PluginDescriptionFile pluginDescription; + @NotNull + List alreadyInstalledPlugins; + + public DependsCollectArgument(@NotNull DescriptionLoadResult descriptionLoadResult) + { + super(descriptionLoadResult); + + if (descriptionLoadResult.getDescription() == null) + throw new IllegalStateException("descriptionLoadResult.description is null"); + this.pluginDescription = descriptionLoadResult.getDescription(); + + this.alreadyInstalledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(plugin -> plugin.getDescription().getName()) + .collect(Collectors.toList()); + } + + public DependsCollectArgument(@NotNull PluginDescriptionFile pluginDescription, + @NotNull List alreadyInstalledPlugins) + { + this.pluginDescription = pluginDescription; + this.alreadyInstalledPlugins = alreadyInstalledPlugins; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectErrorCause.java new file mode 100644 index 00000000..1f9a4545 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectErrorCause.java @@ -0,0 +1,6 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; + +public enum DependsCollectErrorCause +{ + SOME_DEPENDENCIES_COLLECT_FAILED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java new file mode 100644 index 00000000..6ce81679 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java @@ -0,0 +1,286 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsDescriptionLoadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsDownloadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsResolveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class DependsCollectPhase extends InstallPhase +{ // TODO: きれいに + private final InstallerSignalHandler signalHandler; + + private DependsCollectState phaseState; + + public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + { + super(progress, signalHandler); + + this.signalHandler = signalHandler; + this.phaseState = DependsCollectState.INITIALIZED; + } + + private static HashMap> convertStringHashSetToStringListHashMap(HashMap> hashSetHashMap) + { + HashMap> listHashMap = new HashMap<>(); + for (String key : hashSetHashMap.keySet()) + listHashMap.put(key, new ArrayList<>(hashSetHashMap.get(key))); + + return listHashMap; + } + + @Override + public @NotNull DependsCollectResult runPhase(@NotNull DependsCollectArgument arguments) + { + PluginDescriptionFile pluginDescription = arguments.getPluginDescription(); + String pluginName = pluginDescription.getName(); + HashSet collectingFailedDepends; + + // Enumerate dependencies + DependsEnumeratedSignal dependsSignal = new DependsEnumeratedSignal( + pluginDescription.getDepend(), + arguments.getAlreadyInstalledPlugins() + ); + + this.postSignal(dependsSignal); + + HashMap resolvedResults; + // region Resolve dependencies + this.phaseState = DependsCollectState.RESOLVING_DEPENDS; + + resolvedResults = this.resolveDepends(dependsSignal.getDependencies(), arguments.getAlreadyInstalledPlugins()); + collectingFailedDepends = new HashSet<>(this.indicateResolveErrors(resolvedResults)); // Post signal on failed + + // Remove failed dependencies from resolve results + collectingFailedDepends.stream().parallel().forEach(resolvedResults::remove); + // endregion + + HashMap downloadResults; + // region Download dependencies + this.phaseState = DependsCollectState.DOWNLOADING_DEPENDS; + + downloadResults = this.downloadDepends(resolvedResults); + + List downloadFailures = this.indicateDownloadErrors(downloadResults); // Post signal on failed + collectingFailedDepends.addAll(downloadFailures); + + // Remove failed dependencies from download results + downloadFailures.stream().parallel().forEach(downloadResults::remove); + // endregion + + HashMap> collectFailures; + // region Collect dependency's dependencies (Recursive via collectDependsDepends) + this.phaseState = DependsCollectState.COLLECTING_DEPENDS_DEPENDS; + + HashMap dependsDescriptions = downloadResultsToPluginDescriptionFiles(downloadResults); + + List loadDescriptionsFailures = this.indicateLoadDescriptionErrors(dependsDescriptions); // Post signal on failed + collectingFailedDepends.addAll(loadDescriptionsFailures); + + // Remove failed dependencies from load description results + loadDescriptionsFailures.stream().parallel().forEach(dependsDescriptions::remove); + + //------------------------ + // Collect dependency's dependencies + + List alreadyInstalled = new ArrayList<>(arguments.getAlreadyInstalledPlugins()); + alreadyInstalled.add(pluginName); + alreadyInstalled.addAll(dependsDescriptions.keySet()); + + + HashMap dependsCollectResults = + this.collectDependsDepends(dependsDescriptions, alreadyInstalled); + + // Post signal on failed + collectFailures = this.indicateCollectDependsDependsErrors(dependsCollectResults); + + + // endregion + + if (!collectFailures.containsKey(pluginName)) + collectFailures.put(pluginName, new HashSet<>()); + collectFailures.get(pluginName).addAll(collectingFailedDepends); + + boolean success = collectingFailedDepends.isEmpty(); + DependsCollectErrorCause errorCause = success ? null: DependsCollectErrorCause.SOME_DEPENDENCIES_COLLECT_FAILED; + + return new DependsCollectResult( + success, this.phaseState, errorCause, + pluginName, convertStringHashSetToStringListHashMap(collectFailures) + ); + } + + private HashMap> indicateCollectDependsDependsErrors(@NotNull HashMap dependsCollectResults) + { // Not same as other indicate methods + HashMap> collectingFailedDepends = new HashMap<>(); + + for (Map.Entry entry : dependsCollectResults.entrySet()) + { + DependsCollectResult dependsCollectResult = entry.getValue(); + + if (!dependsCollectResult.isSuccess()) + for (Map.Entry> entry2 : dependsCollectResult.getCollectingFailedPlugins().entrySet()) + { + String pluginName = entry2.getKey(); + List collectingFailedDependsList = entry2.getValue(); + if (!collectingFailedDepends.containsKey(pluginName)) + collectingFailedDepends.put(pluginName, new HashSet<>()); + + collectingFailedDepends.get(pluginName).addAll(collectingFailedDependsList); + } + } + + return collectingFailedDepends; + } + + private DependsCollectResult passCollector(@NotNull PluginDescriptionFile pluginDescription, + @NotNull List alreadyCollectedPlugins) + { + DependsCollectArgument arguments = new DependsCollectArgument(pluginDescription, alreadyCollectedPlugins); + + return new DependsCollectPhase(this.progress, this.signalHandler) // do new() because DependsCollectPhase is stateful. + .runPhase(arguments); + } + + private HashMap collectDependsDepends(@NotNull HashMap dependsDescriptions, + @NotNull List alreadyCollectedPlugins) + { + return new HashMap<>(dependsDescriptions.entrySet().stream() + .parallel() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> + this.passCollector(entry.getValue(), alreadyCollectedPlugins)) + )); + } + + private List indicateLoadDescriptionErrors(@NotNull HashMap dependsDescriptions) + { + List errors = (dependsDescriptions.entrySet().stream()) + .filter(entry -> entry.getValue() == null) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + if (!errors.isEmpty()) + this.postSignal(new DependsDescriptionLoadFailedSignal(errors)); + + return errors; + } + + private PluginDescriptionFile downloadResultToPluginDescriptionFile(@NotNull DownloadResult downloadResult) + { + try + { + Path pluginPath = downloadResult.getPath(); + + if (pluginPath == null) + return null; + + return PluginUtil.loadDescription(pluginPath.toFile()); + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + private HashMap downloadResultsToPluginDescriptionFiles( + @NotNull Map downloadResults) + { + HashMap pluginDescriptionFiles = new HashMap<>(); + + for (Map.Entry entry : downloadResults.entrySet()) + { + PluginDescriptionFile pluginDescriptionFile = this.downloadResultToPluginDescriptionFile(entry.getValue()); + + pluginDescriptionFiles.put(entry.getKey(), pluginDescriptionFile); + } + + return pluginDescriptionFiles; + } + + private DownloadResult passDownloader(@NotNull String url) + { + DownloadArgument argument = new DownloadArgument(url); + + return new DownloadPhase(this.progress, this.signalHandler) + .runPhase(argument); + } + + private HashMap downloadDepends(@NotNull HashMap resolvedPlugins) + { + return new HashMap<>(resolvedPlugins.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> { + SuccessResult successResult = (SuccessResult) entry.getValue(); + return passDownloader(successResult.getDownloadUrl()); // Actual downloading + }))); + } + + private List indicateDownloadErrors(@NotNull HashMap downloadResults) + { + List errors = (downloadResults.entrySet().stream()) + .filter(entry -> !entry.getValue().isSuccess()) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + if (!errors.isEmpty()) + this.postSignal(new DependsDownloadFailedSignal(errors)); + + return errors; + } + + private List indicateResolveErrors(@NotNull HashMap resolveResults) + { + List errors = resolveResults.entrySet().stream().parallel() + .filter(entry -> !(entry.getValue() instanceof SuccessResult)) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + if (!errors.isEmpty()) + this.postSignal(new DependsResolveFailedSignal(errors)); + + return errors; + } + + private PluginResolveResult passResolver(@NotNull String dependency) + { + PluginResolveArgument resolveArgument = new PluginResolveArgument(dependency); + + return new PluginResolvePhase(this.progress, this.signalHandler) + .runPhase(resolveArgument); + } + + private HashMap resolveDepends(@NotNull List dependencies, + @NotNull List alreadyInstalledPlugins) + { + return new HashMap<>(dependencies.stream() + .filter(dependency -> !alreadyInstalledPlugins.contains(dependency)) + .map(dependency -> new Pair<>( + dependency, + this.passResolver(dependency).getResolveResult() // Actual resolving + )) + .collect(Collectors.toMap(Pair::getLeft, Pair::getRight))); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java new file mode 100644 index 00000000..c437aa8d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java @@ -0,0 +1,35 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.List; + +@Value +@EqualsAndHashCode(callSuper = true) +public class DependsCollectResult extends PhaseResult +{ + @NotNull + String targetPlugin; + + @NotNull + HashMap> collectingFailedPlugins; + + public DependsCollectResult(boolean success, @NotNull DependsCollectState phase, + @Nullable DependsCollectErrorCause errorCause, @NotNull String targetPlugin, + @NotNull HashMap> collectingFailedPlugins) + { + super(success, phase, errorCause); + this.targetPlugin = targetPlugin; + this.collectingFailedPlugins = collectingFailedPlugins; + } + + public boolean hasErrors() + { + return !collectingFailedPlugins.isEmpty(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectState.java new file mode 100644 index 00000000..281a3cf0 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectState.java @@ -0,0 +1,11 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; + +public enum DependsCollectState +{ + INITIALIZED, + + RESOLVING_DEPENDS, + DOWNLOADING_DEPENDS, + + COLLECTING_DEPENDS_DEPENDS // Dependency's depends. +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCollectDependsDependsFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCollectDependsDependsFailedSignal.java new file mode 100644 index 00000000..263b9d3b --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCollectDependsDependsFailedSignal.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@Value +public class DependsCollectDependsDependsFailedSignal implements InstallerSignal +{ + @NotNull + String pluginName; + @NotNull + List collectFailedDependencies; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDescriptionLoadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDescriptionLoadFailedSignal.java new file mode 100644 index 00000000..9d591f82 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDescriptionLoadFailedSignal.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; + +import java.util.List; + +@Value +public class DependsDescriptionLoadFailedSignal implements InstallerSignal +{ + List descriptionLoadFailedDependencies; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java new file mode 100644 index 00000000..15f0bf69 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java @@ -0,0 +1,14 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@Value +public class DependsDownloadFailedSignal implements InstallerSignal +{ + @NotNull + List downloadFailedDependencies; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsEnumeratedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsEnumeratedSignal.java new file mode 100644 index 00000000..4fd5f58a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsEnumeratedSignal.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +import lombok.AllArgsConstructor; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; + +import java.util.List; + +@AllArgsConstructor +@Value +public class DependsEnumeratedSignal implements InstallerSignal +{ + List dependencies; + List ignoredDependencies; // it means already installed or already collected +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java new file mode 100644 index 00000000..70030be5 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; + +import java.util.List; + +@Value +public class DependsResolveFailedSignal implements InstallerSignal +{ + List resolveFailedDependencies; +} From 9ca28b954790be6c17210cfaa773b88567bcf4ca Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 12 May 2022 19:44:59 +0900 Subject: [PATCH 158/745] feat: wip: installer: Specify download path --- .../phase/phases/download/DownloadArgument.java | 15 ++++++++++++++- .../phase/phases/download/DownloadPhase.java | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java index 144b819d..1d65c097 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java @@ -5,6 +5,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; @Value @EqualsAndHashCode(callSuper = false) @@ -13,9 +16,19 @@ public class DownloadArgument extends PhaseArgument @NotNull String url; + @Nullable + Path path; + + public DownloadArgument(@NotNull String url, @Nullable Path path) + { + this.url = url; + this.path = path; + } + public DownloadArgument(@NotNull String url) { this.url = url; + this.path = null; } public DownloadArgument(@NotNull PluginResolveResult pluginResolveResult) @@ -26,6 +39,6 @@ public DownloadArgument(@NotNull PluginResolveResult pluginResolveResult) throw new IllegalArgumentException("Plugin Resolving must be successful"); this.url = pluginResolveResult.getResolveResult().getDownloadUrl(); - + this.path = null; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java index 00bc776b..5eac5eae 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java @@ -46,9 +46,13 @@ private void onDownload(DownloadProgress downloadProgress) @Override public @NotNull DownloadResult runPhase(@NotNull DownloadArgument arguments) { + Path downloadPath = arguments.getPath(); + if (downloadPath == null) + downloadPath = progress.getInstallTempDir().resolve(this.randomDownloadID + ".kpmcache"); + DownloadStartingSignal downloadingSignal = new DownloadStartingSignal( this.randomDownloadID, - progress.getInstallTempDir().resolve(this.randomDownloadID + ".jar"), + downloadPath, arguments.getUrl() ); From 872aad36e1f0f7915c037849cb30aadd8a5f6bee Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 14 May 2022 08:14:29 +0900 Subject: [PATCH 159/745] fix: wip: installer: Fix depends collector --- .../installer/install/PluginInstaller.java | 4 +- .../phases/depends/DependsCollectCache.java | 122 +++++++++++++ .../phases/depends/DependsCollectPhase.java | 168 +++++++----------- .../phases/depends/DependsCollectResult.java | 10 +- .../signals/DependsCacheSaveFailedSignal.java | 7 + .../signals/DependsDownloadFailedSignal.java | 4 +- ...> DependsLoadDescriptionFailedSignal.java} | 8 +- .../signals/DependsResolveFailedSignal.java | 4 +- 8 files changed, 205 insertions(+), 122 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCacheSaveFailedSignal.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/{DependsDescriptionLoadFailedSignal.java => DependsLoadDescriptionFailedSignal.java} (56%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index ce0e9b79..9928aadf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -101,13 +101,13 @@ public InstallResult execute(@NotNull String query) } // endregion - // TODO: write collect depends process - if (replacePlugin) this.progress.addUpgraded(pluginName); else this.progress.addInstalled(pluginName); + // region Collecting dependencies section. + return this.success(); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java new file mode 100644 index 00000000..00b8f1ad --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java @@ -0,0 +1,122 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; + +import com.google.gson.Gson; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Data +@AllArgsConstructor +public class DependsCollectCache +{ + private static final Gson gson = new Gson(); + + @NotNull + private final File cacheFile; + @NotNull + private final String installId; + @NotNull + @Getter(AccessLevel.PRIVATE) + private final HashMap enumeratedDependencies; + + @NotNull + private String pluginName; + + private DependsCollectCache(@NotNull String installId) + { + this.installId = installId; + this.enumeratedDependencies = new HashMap<>(); + this.pluginName = "undefined-" + installId; + + this.cacheFile = Paths.get(".cache", installId, installId + ".kpmcache").toFile(); + } + + public static DependsCollectCache of(@NotNull String installId) + { + File cacheFile = Paths.get(".cache", installId, installId + ".kpmcache").toFile(); + + if (!cacheFile.exists()) + return new DependsCollectCache(installId); + + try (FileReader fis = new FileReader(cacheFile)) + { + return gson.fromJson(fis, DependsCollectCache.class); + } + catch (IOException e) + { + e.printStackTrace(); + return new DependsCollectCache(installId); + } + } + + public void addDependency(@NotNull String dependencyName) + { + if (!enumeratedDependencies.containsKey(dependencyName)) + enumeratedDependencies.put(dependencyName, null); + } + + public boolean isCollected(@NotNull String dependencyName) + { + return enumeratedDependencies.containsKey(dependencyName); + } + + public boolean isErrors() + { + return enumeratedDependencies.containsValue(null); + } + + public void onCollect(@NotNull String dependencyName, @Nullable Path dependencyPath) + { + if (enumeratedDependencies.containsKey(dependencyName)) + enumeratedDependencies.put(dependencyName, dependencyPath); + } + + public List getCollectedDependencies() + { + return this.enumeratedDependencies.entrySet().stream().parallel() + .filter(entry -> entry.getValue() != null) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + } + + public List getCollectFailedDependencies() + { + return this.enumeratedDependencies.entrySet().stream().parallel() + .filter(entry -> entry.getValue() == null) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + } + + public boolean save() + { + try (FileWriter fos = new FileWriter(this.cacheFile)) + { + fos.write(gson.toJson(this)); + return true; + } + catch (IOException e) + { + e.printStackTrace(); + return false; + } + } + + public DependsCollectCache update() + { + return of(this.installId); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java index 6ce81679..49102698 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java @@ -3,9 +3,11 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsDescriptionLoadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsCacheSaveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsCollectDependsDependsFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsDownloadFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsLoadDescriptionFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsResolveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; @@ -24,14 +26,15 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; public class DependsCollectPhase extends InstallPhase { // TODO: きれいに private final InstallerSignalHandler signalHandler; + private final DependsCollectCache cache; private DependsCollectState phaseState; @@ -40,24 +43,17 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal super(progress, signalHandler); this.signalHandler = signalHandler; - this.phaseState = DependsCollectState.INITIALIZED; - } - - private static HashMap> convertStringHashSetToStringListHashMap(HashMap> hashSetHashMap) - { - HashMap> listHashMap = new HashMap<>(); - for (String key : hashSetHashMap.keySet()) - listHashMap.put(key, new ArrayList<>(hashSetHashMap.get(key))); + this.cache = DependsCollectCache.of(progress.getInstallActionID().toString()); - return listHashMap; + this.phaseState = DependsCollectState.INITIALIZED; } @Override public @NotNull DependsCollectResult runPhase(@NotNull DependsCollectArgument arguments) { PluginDescriptionFile pluginDescription = arguments.getPluginDescription(); + this.cache.setPluginName(pluginDescription.getName()); String pluginName = pluginDescription.getName(); - HashSet collectingFailedDepends; // Enumerate dependencies DependsEnumeratedSignal dependsSignal = new DependsEnumeratedSignal( @@ -67,15 +63,14 @@ private static HashMap> convertStringHashSetToStringListHas this.postSignal(dependsSignal); + dependsSignal.getDependencies().forEach(this.cache::addDependency); + HashMap resolvedResults; // region Resolve dependencies this.phaseState = DependsCollectState.RESOLVING_DEPENDS; resolvedResults = this.resolveDepends(dependsSignal.getDependencies(), arguments.getAlreadyInstalledPlugins()); - collectingFailedDepends = new HashSet<>(this.indicateResolveErrors(resolvedResults)); // Post signal on failed - - // Remove failed dependencies from resolve results - collectingFailedDepends.stream().parallel().forEach(resolvedResults::remove); + resolvedResults.entrySet().removeIf(entry -> !(entry.getValue() instanceof SuccessResult)); // Remove failures // endregion HashMap downloadResults; @@ -83,25 +78,26 @@ private static HashMap> convertStringHashSetToStringListHas this.phaseState = DependsCollectState.DOWNLOADING_DEPENDS; downloadResults = this.downloadDepends(resolvedResults); - - List downloadFailures = this.indicateDownloadErrors(downloadResults); // Post signal on failed - collectingFailedDepends.addAll(downloadFailures); - - // Remove failed dependencies from download results - downloadFailures.stream().parallel().forEach(downloadResults::remove); + downloadResults.entrySet().removeIf(entry -> !entry.getValue().isSuccess()); // Remove failures // endregion - HashMap> collectFailures; // region Collect dependency's dependencies (Recursive via collectDependsDepends) this.phaseState = DependsCollectState.COLLECTING_DEPENDS_DEPENDS; HashMap dependsDescriptions = downloadResultsToPluginDescriptionFiles(downloadResults); - List loadDescriptionsFailures = this.indicateLoadDescriptionErrors(dependsDescriptions); // Post signal on failed - collectingFailedDepends.addAll(loadDescriptionsFailures); - // Remove failed dependencies from load description results - loadDescriptionsFailures.stream().parallel().forEach(dependsDescriptions::remove); + dependsDescriptions.entrySet().removeIf(entry -> entry.getValue() == null); + + dependsDescriptions.entrySet().stream().parallel() + .filter(entry -> Objects.nonNull(entry.getValue())) + .filter(entry -> downloadResults.containsKey(entry.getKey())) + .forEach(entry -> + this.cache.onCollect(entry.getValue().getName(), downloadResults.get(entry.getKey()).getPath()) + ); + + if (!this.cache.save()) + this.postSignal(new DependsCacheSaveFailedSignal()); //------------------------ // Collect dependency's dependencies @@ -110,52 +106,19 @@ private static HashMap> convertStringHashSetToStringListHas alreadyInstalled.add(pluginName); alreadyInstalled.addAll(dependsDescriptions.keySet()); - - HashMap dependsCollectResults = - this.collectDependsDepends(dependsDescriptions, alreadyInstalled); - - // Post signal on failed - collectFailures = this.indicateCollectDependsDependsErrors(dependsCollectResults); - + this.collectDependsDepends(dependsDescriptions, alreadyInstalled); // endregion - if (!collectFailures.containsKey(pluginName)) - collectFailures.put(pluginName, new HashSet<>()); - collectFailures.get(pluginName).addAll(collectingFailedDepends); - - boolean success = collectingFailedDepends.isEmpty(); + boolean success = this.cache.isErrors(); DependsCollectErrorCause errorCause = success ? null: DependsCollectErrorCause.SOME_DEPENDENCIES_COLLECT_FAILED; return new DependsCollectResult( success, this.phaseState, errorCause, - pluginName, convertStringHashSetToStringListHashMap(collectFailures) + pluginName, this.cache.getCollectedDependencies(), this.cache.getCollectFailedDependencies() ); } - private HashMap> indicateCollectDependsDependsErrors(@NotNull HashMap dependsCollectResults) - { // Not same as other indicate methods - HashMap> collectingFailedDepends = new HashMap<>(); - - for (Map.Entry entry : dependsCollectResults.entrySet()) - { - DependsCollectResult dependsCollectResult = entry.getValue(); - - if (!dependsCollectResult.isSuccess()) - for (Map.Entry> entry2 : dependsCollectResult.getCollectingFailedPlugins().entrySet()) - { - String pluginName = entry2.getKey(); - List collectingFailedDependsList = entry2.getValue(); - if (!collectingFailedDepends.containsKey(pluginName)) - collectingFailedDepends.put(pluginName, new HashSet<>()); - - collectingFailedDepends.get(pluginName).addAll(collectingFailedDependsList); - } - } - - return collectingFailedDepends; - } - private DependsCollectResult passCollector(@NotNull PluginDescriptionFile pluginDescription, @NotNull List alreadyCollectedPlugins) { @@ -165,27 +128,29 @@ private DependsCollectResult passCollector(@NotNull PluginDescriptionFile plugin .runPhase(arguments); } - private HashMap collectDependsDepends(@NotNull HashMap dependsDescriptions, - @NotNull List alreadyCollectedPlugins) + private void collectDependsDepends(@NotNull HashMap dependsDescriptions, + @NotNull List alreadyCollectedPlugins) { - return new HashMap<>(dependsDescriptions.entrySet().stream() - .parallel() - .collect(Collectors.toMap(Map.Entry::getKey, entry -> - this.passCollector(entry.getValue(), alreadyCollectedPlugins)) - )); - } + List alreadyCollected = new ArrayList<>(alreadyCollectedPlugins); - private List indicateLoadDescriptionErrors(@NotNull HashMap dependsDescriptions) - { - List errors = (dependsDescriptions.entrySet().stream()) - .filter(entry -> entry.getValue() == null) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); + for (Map.Entry entry : dependsDescriptions.entrySet()) + { + this.cache.save(); - if (!errors.isEmpty()) - this.postSignal(new DependsDescriptionLoadFailedSignal(errors)); + DependsCollectResult dependsCollectResult = this.passCollector(entry.getValue(), alreadyCollected); - return errors; + this.cache.update(); + + if (!dependsCollectResult.isSuccess()) + { + this.postSignal(new DependsCollectDependsDependsFailedSignal( + dependsCollectResult.getTargetPlugin(), + dependsCollectResult.getCollectingFailedPlugins() + )); + } + else + alreadyCollected.add(entry.getKey()); + } } private PluginDescriptionFile downloadResultToPluginDescriptionFile(@NotNull DownloadResult downloadResult) @@ -215,7 +180,10 @@ private PluginDescriptionFile downloadResultToPluginDescriptionFile(@NotNull Dow { PluginDescriptionFile pluginDescriptionFile = this.downloadResultToPluginDescriptionFile(entry.getValue()); - pluginDescriptionFiles.put(entry.getKey(), pluginDescriptionFile); + if (pluginDescriptionFile == null) + this.postSignal(new DependsLoadDescriptionFailedSignal(entry.getKey())); + else + pluginDescriptionFiles.put(entry.getKey(), pluginDescriptionFile); } return pluginDescriptionFiles; @@ -231,37 +199,17 @@ private DownloadResult passDownloader(@NotNull String url) private HashMap downloadDepends(@NotNull HashMap resolvedPlugins) { - return new HashMap<>(resolvedPlugins.entrySet().stream() + Map downloadResults = resolvedPlugins.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> { SuccessResult successResult = (SuccessResult) entry.getValue(); return passDownloader(successResult.getDownloadUrl()); // Actual downloading - }))); - } + })); - private List indicateDownloadErrors(@NotNull HashMap downloadResults) - { - List errors = (downloadResults.entrySet().stream()) + downloadResults.entrySet().stream() .filter(entry -> !entry.getValue().isSuccess()) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - - if (!errors.isEmpty()) - this.postSignal(new DependsDownloadFailedSignal(errors)); + .forEach(entry -> this.postSignal(new DependsDownloadFailedSignal(entry.getKey()))); - return errors; - } - - private List indicateResolveErrors(@NotNull HashMap resolveResults) - { - List errors = resolveResults.entrySet().stream().parallel() - .filter(entry -> !(entry.getValue() instanceof SuccessResult)) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - - if (!errors.isEmpty()) - this.postSignal(new DependsResolveFailedSignal(errors)); - - return errors; + return new HashMap<>(downloadResults); } private PluginResolveResult passResolver(@NotNull String dependency) @@ -275,12 +223,18 @@ private PluginResolveResult passResolver(@NotNull String dependency) private HashMap resolveDepends(@NotNull List dependencies, @NotNull List alreadyInstalledPlugins) { - return new HashMap<>(dependencies.stream() + Map resolveResults = new HashMap<>(dependencies.stream() .filter(dependency -> !alreadyInstalledPlugins.contains(dependency)) .map(dependency -> new Pair<>( dependency, this.passResolver(dependency).getResolveResult() // Actual resolving )) .collect(Collectors.toMap(Pair::getLeft, Pair::getRight))); + + resolveResults.entrySet().stream() + .filter(entry -> !(entry.getValue() instanceof SuccessResult)) + .forEach(entry -> this.postSignal(new DependsResolveFailedSignal(entry.getKey()))); + + return new HashMap<>(resolveResults); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java index c437aa8d..28f780ca 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java @@ -6,7 +6,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.List; @Value @@ -17,14 +16,19 @@ public class DependsCollectResult extends PhaseResult> collectingFailedPlugins; + List collectedPlugin; + + @NotNull + List collectingFailedPlugins; public DependsCollectResult(boolean success, @NotNull DependsCollectState phase, @Nullable DependsCollectErrorCause errorCause, @NotNull String targetPlugin, - @NotNull HashMap> collectingFailedPlugins) + @NotNull List collectedPlugin, + @NotNull List collectingFailedPlugins) { super(success, phase, errorCause); this.targetPlugin = targetPlugin; + this.collectedPlugin = collectedPlugin; this.collectingFailedPlugins = collectingFailedPlugins; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCacheSaveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCacheSaveFailedSignal.java new file mode 100644 index 00000000..f4b574b6 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCacheSaveFailedSignal.java @@ -0,0 +1,7 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; + +public class DependsCacheSaveFailedSignal implements InstallerSignal +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java index 15f0bf69..d3c01b64 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java @@ -4,11 +4,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; -import java.util.List; - @Value public class DependsDownloadFailedSignal implements InstallerSignal { @NotNull - List downloadFailedDependencies; + String downloadFailedDependency; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDescriptionLoadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java similarity index 56% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDescriptionLoadFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java index 9d591f82..a9061189 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDescriptionLoadFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java @@ -2,11 +2,11 @@ import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; - -import java.util.List; +import org.jetbrains.annotations.NotNull; @Value -public class DependsDescriptionLoadFailedSignal implements InstallerSignal +public class DependsLoadDescriptionFailedSignal implements InstallerSignal { - List descriptionLoadFailedDependencies; + @NotNull + String descriptionLoadFailedDependency; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java index 70030be5..55ca23a4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java @@ -3,10 +3,8 @@ import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import java.util.List; - @Value public class DependsResolveFailedSignal implements InstallerSignal { - List resolveFailedDependencies; + String resolveFailedDependencies; } From 7909326d9001ab9d255d0be46c577b3f937ab9d5 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 14 May 2022 20:10:58 +0900 Subject: [PATCH 160/745] feat: wip: installer: Apply depends collector --- .../installer/install/InstallErrorCause.java | 4 ++++ .../plugin/installer/install/InstallPhases.java | 3 +-- .../installer/install/PluginInstaller.java | 17 +++++++++++++++++ .../phases/depends/DependsCollectArgument.java | 7 +++++++ .../phases/depends/DependsCollectCache.java | 7 +++---- .../phases/depends/DependsCollectPhase.java | 2 +- .../phases/depends/DependsCollectResult.java | 16 +++++++++------- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java index 4731cc0a..daf95b9f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java @@ -2,12 +2,16 @@ public enum InstallErrorCause { + // Phases PHASE_EXCEPTION_OCCURRED, PHASE_FAILED, + SOME_DEPENDENCY_COLLECT_FAILED, + // Environment errors PLUGIN_IGNORED, PLUGIN_ALREADY_INSTALLED, + // Exceptions EXCEPTION_OCCURRED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java index e64c0bed..fcf03400 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java @@ -2,14 +2,13 @@ public enum InstallPhases { - // General phases STARTED, INITIALIZING, - // Install phases RESOLVING_QUERY, DOWNLOADING, LOADING_PLUGIN_DESCRIPTION, CHECKING_ENVIRONMENT, REMOVING_OLD_PLUGIN, + COLLECTING_DEPENDENCIES, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 9928aadf..c5a129e4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -4,6 +4,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; @@ -19,6 +22,8 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.util.HashMap; public class PluginInstaller extends AbstractInstaller { @@ -106,7 +111,19 @@ public InstallResult execute(@NotNull String query) else this.progress.addInstalled(pluginName); + HashMap collectedDependencies; // region Collecting dependencies section. + this.progress.setPhase(InstallPhases.COLLECTING_DEPENDENCIES); + + DependsCollectResult dependsCollectResult = new DependsCollectPhase(progress, signalHandler) + .runPhase(new DependsCollectArgument(pluginDescription)); + + if (!dependsCollectResult.isSuccess()) + return this.error(InstallErrorCause.SOME_DEPENDENCY_COLLECT_FAILED); + + collectedDependencies = dependsCollectResult.getCollectedPlugins(); + //endregion + return this.success(); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java index cd3d745f..acd094da 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java @@ -40,4 +40,11 @@ public DependsCollectArgument(@NotNull PluginDescriptionFile pluginDescription, this.pluginDescription = pluginDescription; this.alreadyInstalledPlugins = alreadyInstalledPlugins; } + + public DependsCollectArgument(@NotNull PluginDescriptionFile pluginDescription) + { + this(pluginDescription, Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(plugin -> plugin.getDescription().getName()) + .collect(Collectors.toList())); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java index 00b8f1ad..1ba30e79 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java @@ -85,12 +85,11 @@ public void onCollect(@NotNull String dependencyName, @Nullable Path dependencyP enumeratedDependencies.put(dependencyName, dependencyPath); } - public List getCollectedDependencies() + public HashMap getCollectedDependencies() { - return this.enumeratedDependencies.entrySet().stream().parallel() + return (HashMap) this.enumeratedDependencies.entrySet().stream().parallel() .filter(entry -> entry.getValue() != null) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } public List getCollectFailedDependencies() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java index 49102698..52c7bd1d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java @@ -145,7 +145,7 @@ private void collectDependsDepends(@NotNull HashMap collectedPlugin; + HashMap collectedPlugins; @NotNull - List collectingFailedPlugins; + List collectFailedPlugins; public DependsCollectResult(boolean success, @NotNull DependsCollectState phase, @Nullable DependsCollectErrorCause errorCause, @NotNull String targetPlugin, - @NotNull List collectedPlugin, - @NotNull List collectingFailedPlugins) + @NotNull HashMap collectedPlugins, + @NotNull List collectFailedPlugins) { super(success, phase, errorCause); this.targetPlugin = targetPlugin; - this.collectedPlugin = collectedPlugin; - this.collectingFailedPlugins = collectingFailedPlugins; + this.collectedPlugins = collectedPlugins; + this.collectFailedPlugins = collectFailedPlugins; } public boolean hasErrors() { - return !collectingFailedPlugins.isEmpty(); + return !collectFailedPlugins.isEmpty(); } } From 00384c11c43028db3a9954f4698e67333e08b97e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 16 May 2022 19:49:51 +0900 Subject: [PATCH 161/745] refactor: wip: installer: Migrate DepCollectPhase to InstallProgress --- .../plugin/AbstractInstaller.java | 2 +- .../plugin/installer/InstallProgress.java | 49 ++++++++++++------- .../phases/depends/DependsCollectCache.java | 2 +- .../phases/depends/DependsCollectPhase.java | 6 +-- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index de129477..e7b70370 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -25,7 +25,7 @@ public abstract class AbstractInstaller, P extends Enum

> public AbstractInstaller(InstallerSignalHandler signalHandler) throws IOException { - this.progress = new InstallProgress<>(true); + this.progress = InstallProgress.of(null); this.signalHandler = signalHandler; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 347332ef..4d3a6efe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -3,19 +3,24 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectCache; import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.UUID; @Getter public class InstallProgress

> { + private static final HashMap> progressCaches; + @Setter private P phase; @@ -24,10 +29,17 @@ public class InstallProgress

> private final List removed; private final List pending; - private final UUID installActionID; + static + { + progressCaches = new HashMap<>(); + } + private final Path installTempDir; - public InstallProgress(boolean createTempDir) throws IOException, SecurityException + private final String installActionID; + private final DependsCollectCache dependsCollectCache; + + private InstallProgress(@Nullable String id) throws IOException, SecurityException { this.upgraded = new ArrayList<>(); this.installed = new ArrayList<>(); @@ -36,30 +48,27 @@ public InstallProgress(boolean createTempDir) throws IOException, SecurityExcept this.phase = null; - this.installActionID = UUID.randomUUID(); - - if (!createTempDir) - { - this.installTempDir = null; - return; - } + if (id == null) + this.installActionID = UUID.randomUUID().toString().substring(0, 8); + else + this.installActionID = id; this.installTempDir = Files.createTempDirectory( TeamKunPluginManager.getPlugin().getDataFolder().toPath(), - this.getInstallActionID().toString() + this.getInstallActionID() ); + + this.dependsCollectCache = new DependsCollectCache(this.installActionID); + + progressCaches.put(this.getInstallActionID(), this); } - public static InstallProgress dummy() + public static

> InstallProgress

of(@Nullable String id) throws IOException, SecurityException { - try - { - return new InstallProgress<>(false); - } - catch (IOException e) - { // should not happen - throw new IllegalStateException(e); - } + if (id == null) + return new InstallProgress<>(null); + else + return (InstallProgress

) progressCaches.get(id); } private void removeFromAll(@NotNull String name) @@ -108,5 +117,7 @@ public void finish() { e.printStackTrace(); } + + progressCaches.remove(this.getInstallActionID()); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java index 1ba30e79..b7bfe60f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java @@ -36,7 +36,7 @@ public class DependsCollectCache @NotNull private String pluginName; - private DependsCollectCache(@NotNull String installId) + public DependsCollectCache(@NotNull String installId) { this.installId = installId; this.enumeratedDependencies = new HashMap<>(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java index 52c7bd1d..e644a2bf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java @@ -43,7 +43,7 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal super(progress, signalHandler); this.signalHandler = signalHandler; - this.cache = DependsCollectCache.of(progress.getInstallActionID().toString()); + this.cache = progress.getDependsCollectCache(); this.phaseState = DependsCollectState.INITIALIZED; } @@ -135,12 +135,8 @@ private void collectDependsDepends(@NotNull HashMap entry : dependsDescriptions.entrySet()) { - this.cache.save(); - DependsCollectResult dependsCollectResult = this.passCollector(entry.getValue(), alreadyCollected); - this.cache.update(); - if (!dependsCollectResult.isSuccess()) { this.postSignal(new DependsCollectDependsDependsFailedSignal( From 83c9d4a2e8e77a37427a9e1d7b56c6bead7bb57e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 16 May 2022 19:57:42 +0900 Subject: [PATCH 162/745] feat: wip: installer: DependencyCollectFailedSignalBase --- .../signals/DependencyCollectFailedSignalBase.java | 12 ++++++++++++ .../signals/DependsDownloadFailedSignal.java | 13 +++++-------- .../signals/DependsLoadDescriptionFailedSignal.java | 13 +++++-------- .../depends/signals/DependsResolveFailedSignal.java | 11 +++++------ 4 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectFailedSignalBase.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectFailedSignalBase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectFailedSignalBase.java new file mode 100644 index 00000000..a9c5fcdc --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectFailedSignalBase.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; + +@AllArgsConstructor +@Getter +public abstract class DependencyCollectFailedSignalBase implements InstallerSignal +{ + private final String failedDependency; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java index d3c01b64..85f46b86 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java @@ -1,12 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import org.jetbrains.annotations.NotNull; - -@Value -public class DependsDownloadFailedSignal implements InstallerSignal +public class DependsDownloadFailedSignal extends DependencyCollectFailedSignalBase { - @NotNull - String downloadFailedDependency; + public DependsDownloadFailedSignal(String failedDependency) + { + super(failedDependency); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java index a9061189..ffb1cdf7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java @@ -1,12 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import org.jetbrains.annotations.NotNull; - -@Value -public class DependsLoadDescriptionFailedSignal implements InstallerSignal +public class DependsLoadDescriptionFailedSignal extends DependencyCollectFailedSignalBase { - @NotNull - String descriptionLoadFailedDependency; + public DependsLoadDescriptionFailedSignal(String failedDependency) + { + super(failedDependency); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java index 55ca23a4..1327408f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java @@ -1,10 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; - -@Value -public class DependsResolveFailedSignal implements InstallerSignal +public class DependsResolveFailedSignal extends DependencyCollectFailedSignalBase { - String resolveFailedDependencies; + public DependsResolveFailedSignal(String failedDependency) + { + super(failedDependency); + } } From 5af8156b2d10d16d78cfcdfc0912526dfaadd1d5 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 16 May 2022 20:00:02 +0900 Subject: [PATCH 163/745] refactor: wip: installer: remove plural form --- .../phases/depends/DependsCollectPhase.java | 16 ++++++++-------- ...cyCollectDependencysDependsFailedSignal.java} | 2 +- .../signals/DependencyDownloadFailedSignal.java | 9 +++++++++ .../DependencyLoadDescriptionFailedSignal.java | 9 +++++++++ .../signals/DependencyResolveFailedSignal.java | 9 +++++++++ .../signals/DependsDownloadFailedSignal.java | 9 --------- .../DependsLoadDescriptionFailedSignal.java | 9 --------- .../signals/DependsResolveFailedSignal.java | 9 --------- 8 files changed, 36 insertions(+), 36 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/{DependsCollectDependsDependsFailedSignal.java => DependencyCollectDependencysDependsFailedSignal.java} (80%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyDownloadFailedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyLoadDescriptionFailedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyResolveFailedSignal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java index e644a2bf..4398ea9c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java @@ -3,12 +3,12 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyDownloadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyResolveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsCacheSaveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsCollectDependsDependsFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsDownloadFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsLoadDescriptionFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsResolveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; @@ -139,7 +139,7 @@ private void collectDependsDepends(@NotNull HashMap downloadDepends(@NotNull HashMap !entry.getValue().isSuccess()) - .forEach(entry -> this.postSignal(new DependsDownloadFailedSignal(entry.getKey()))); + .forEach(entry -> this.postSignal(new DependencyDownloadFailedSignal(entry.getKey()))); return new HashMap<>(downloadResults); } @@ -229,7 +229,7 @@ private HashMap resolveDepends(@NotNull List depe resolveResults.entrySet().stream() .filter(entry -> !(entry.getValue() instanceof SuccessResult)) - .forEach(entry -> this.postSignal(new DependsResolveFailedSignal(entry.getKey()))); + .forEach(entry -> this.postSignal(new DependencyResolveFailedSignal(entry.getKey()))); return new HashMap<>(resolveResults); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCollectDependsDependsFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectDependencysDependsFailedSignal.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCollectDependsDependsFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectDependencysDependsFailedSignal.java index 263b9d3b..5b70e874 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCollectDependsDependsFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectDependencysDependsFailedSignal.java @@ -7,7 +7,7 @@ import java.util.List; @Value -public class DependsCollectDependsDependsFailedSignal implements InstallerSignal +public class DependencyCollectDependencysDependsFailedSignal implements InstallerSignal { @NotNull String pluginName; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyDownloadFailedSignal.java new file mode 100644 index 00000000..964fa7c9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyDownloadFailedSignal.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +public class DependencyDownloadFailedSignal extends DependencyCollectFailedSignalBase +{ + public DependencyDownloadFailedSignal(String failedDependency) + { + super(failedDependency); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyLoadDescriptionFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyLoadDescriptionFailedSignal.java new file mode 100644 index 00000000..af915a2c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyLoadDescriptionFailedSignal.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +public class DependencyLoadDescriptionFailedSignal extends DependencyCollectFailedSignalBase +{ + public DependencyLoadDescriptionFailedSignal(String failedDependency) + { + super(failedDependency); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyResolveFailedSignal.java new file mode 100644 index 00000000..8faed278 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyResolveFailedSignal.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; + +public class DependencyResolveFailedSignal extends DependencyCollectFailedSignalBase +{ + public DependencyResolveFailedSignal(String failedDependency) + { + super(failedDependency); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java deleted file mode 100644 index 85f46b86..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsDownloadFailedSignal.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; - -public class DependsDownloadFailedSignal extends DependencyCollectFailedSignalBase -{ - public DependsDownloadFailedSignal(String failedDependency) - { - super(failedDependency); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java deleted file mode 100644 index ffb1cdf7..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsLoadDescriptionFailedSignal.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; - -public class DependsLoadDescriptionFailedSignal extends DependencyCollectFailedSignalBase -{ - public DependsLoadDescriptionFailedSignal(String failedDependency) - { - super(failedDependency); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java deleted file mode 100644 index 1327408f..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsResolveFailedSignal.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; - -public class DependsResolveFailedSignal extends DependencyCollectFailedSignalBase -{ - public DependsResolveFailedSignal(String failedDependency) - { - super(failedDependency); - } -} From a3909cadc0220d50a7eecdb7119aa79520abba5b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 16 May 2022 20:11:43 +0900 Subject: [PATCH 164/745] feat: wip: installer: DependenciesCollectFailedSignal --- .../plugin/installer/install/PluginInstaller.java | 4 ++++ .../signals/DependenciesCollectFailedSignal.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesCollectFailedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index c5a129e4..e4eafab1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -4,6 +4,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesCollectFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectResult; @@ -119,7 +120,10 @@ public InstallResult execute(@NotNull String query) .runPhase(new DependsCollectArgument(pluginDescription)); if (!dependsCollectResult.isSuccess()) + { + this.postSignal(new DependenciesCollectFailedSignal(dependsCollectResult.getCollectFailedPlugins())); return this.error(InstallErrorCause.SOME_DEPENDENCY_COLLECT_FAILED); + } collectedDependencies = dependsCollectResult.getCollectedPlugins(); //endregion diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesCollectFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesCollectFailedSignal.java new file mode 100644 index 00000000..214d8b51 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesCollectFailedSignal.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; + +import java.util.List; + +@Value +public class DependenciesCollectFailedSignal implements InstallerSignal +{ + List collectFailedPlugins; +} From 5386fdd17833e35abf044b0bac18de4f90c9740d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 17 May 2022 11:04:08 +0900 Subject: [PATCH 165/745] refactor: wip: installer: Change directory --- .../installer/phase/phases/depends/DependsCollectCache.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java index b7bfe60f..d2f09849 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java @@ -42,12 +42,12 @@ public DependsCollectCache(@NotNull String installId) this.enumeratedDependencies = new HashMap<>(); this.pluginName = "undefined-" + installId; - this.cacheFile = Paths.get(".cache", installId, installId + ".kpmcache").toFile(); + this.cacheFile = Paths.get(installId, installId + ".kpmcache").toFile(); } public static DependsCollectCache of(@NotNull String installId) { - File cacheFile = Paths.get(".cache", installId, installId + ".kpmcache").toFile(); + File cacheFile = Paths.get(installId, installId + ".kpmcache").toFile(); if (!cacheFile.exists()) return new DependsCollectCache(installId); From 4b310641489b2b7845237cd295f781bd89e118ce Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 17 May 2022 12:01:32 +0900 Subject: [PATCH 166/745] refactor: wip: installer: depends -> dependencies.collector --- .../plugin/installer/InstallProgress.java | 2 +- .../plugin/installer/install/PluginInstaller.java | 6 +++--- .../collector}/DependsCollectArgument.java | 2 +- .../collector}/DependsCollectCache.java | 2 +- .../collector}/DependsCollectErrorCause.java | 2 +- .../collector}/DependsCollectPhase.java | 14 +++++++------- .../collector}/DependsCollectResult.java | 2 +- .../collector}/DependsCollectState.java | 2 +- ...dencyCollectDependencysDependsFailedSignal.java | 2 +- .../signals/DependencyCollectFailedSignalBase.java | 2 +- .../signals/DependencyDownloadFailedSignal.java | 2 +- .../DependencyLoadDescriptionFailedSignal.java | 2 +- .../signals/DependencyResolveFailedSignal.java | 2 +- .../signals/DependsCacheSaveFailedSignal.java | 2 +- .../signals/DependsEnumeratedSignal.java | 2 +- 15 files changed, 23 insertions(+), 23 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/DependsCollectArgument.java (98%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/DependsCollectCache.java (99%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/DependsCollectErrorCause.java (81%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/DependsCollectPhase.java (95%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/DependsCollectResult.java (97%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/DependsCollectState.java (87%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/signals/DependencyCollectDependencysDependsFailedSignal.java (91%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/signals/DependencyCollectFailedSignalBase.java (89%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/signals/DependencyDownloadFailedSignal.java (86%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/signals/DependencyLoadDescriptionFailedSignal.java (87%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/signals/DependencyResolveFailedSignal.java (86%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/signals/DependsCacheSaveFailedSignal.java (83%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/{depends => dependencies/collector}/signals/DependsEnumeratedSignal.java (91%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 4d3a6efe..9532d680 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -3,7 +3,7 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectCache; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectCache; import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index e4eafab1..14528e2e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -5,9 +5,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesCollectFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.DependsCollectResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectArgument.java similarity index 98% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectArgument.java index acd094da..87430e30 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectArgument.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java similarity index 99% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java index d2f09849..6696b700 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; import com.google.gson.Gson; import lombok.AccessLevel; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectErrorCause.java similarity index 81% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectErrorCause.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectErrorCause.java index 1f9a4545..54485e08 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; public enum DependsCollectErrorCause { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java index 4398ea9c..bc38a13a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyCollectDependencysDependsFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyDownloadFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyLoadDescriptionFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependencyResolveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsCacheSaveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals.DependsEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyDownloadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyResolveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsCacheSaveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java similarity index 97% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java index 87f262f9..c8e73833 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectState.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectState.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectState.java index 281a3cf0..db565881 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/DependsCollectState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; public enum DependsCollectState { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectDependencysDependsFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectDependencysDependsFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java index 5b70e874..94d67f89 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectDependencysDependsFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectFailedSignalBase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectFailedSignalBase.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectFailedSignalBase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectFailedSignalBase.java index a9c5fcdc..78028f63 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyCollectFailedSignalBase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectFailedSignalBase.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyDownloadFailedSignal.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyDownloadFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyDownloadFailedSignal.java index 964fa7c9..72c5b88e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyDownloadFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyDownloadFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; public class DependencyDownloadFailedSignal extends DependencyCollectFailedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyLoadDescriptionFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyLoadDescriptionFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java index af915a2c..a40d8ef3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyLoadDescriptionFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; public class DependencyLoadDescriptionFailedSignal extends DependencyCollectFailedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyResolveFailedSignal.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyResolveFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyResolveFailedSignal.java index 8faed278..e3a6d384 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependencyResolveFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyResolveFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; public class DependencyResolveFailedSignal extends DependencyCollectFailedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCacheSaveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCacheSaveFailedSignal.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCacheSaveFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCacheSaveFailedSignal.java index f4b574b6..192f719f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsCacheSaveFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCacheSaveFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsEnumeratedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsEnumeratedSignal.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsEnumeratedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsEnumeratedSignal.java index 4fd5f58a..a87f5be2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/depends/signals/DependsEnumeratedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsEnumeratedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.depends.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Value; From b9c20d49994da2fedbf4d0ba5668385173c2b885 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 17 May 2022 22:43:51 +0900 Subject: [PATCH 167/745] feat: wip: installer: DependencyElement --- .../dependencies/DependencyElement.java | 25 +++++++++++++++++++ .../collector/DependsCollectCache.java | 19 +++++++------- .../collector/DependsCollectPhase.java | 11 +++++--- .../collector/DependsCollectResult.java | 7 +++--- 4 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java new file mode 100644 index 00000000..6fc5c592 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies; + +import lombok.Data; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +@Data +public class DependencyElement +{ + @NotNull + private final String pluginName; + @NotNull + private final Path pluginPath; + + private int loadOrder; + + public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath) + { + this.pluginName = pluginName; + this.pluginPath = pluginPath; + + this.loadOrder = -1; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java index 6696b700..4ffd331d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java @@ -5,18 +5,18 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; @Data @@ -31,7 +31,7 @@ public class DependsCollectCache private final String installId; @NotNull @Getter(AccessLevel.PRIVATE) - private final HashMap enumeratedDependencies; + private final HashMap enumeratedDependencies; @NotNull private String pluginName; @@ -79,17 +79,18 @@ public boolean isErrors() return enumeratedDependencies.containsValue(null); } - public void onCollect(@NotNull String dependencyName, @Nullable Path dependencyPath) + public void onCollect(@NotNull String dependencyName, DependencyElement dependencyElement) { if (enumeratedDependencies.containsKey(dependencyName)) - enumeratedDependencies.put(dependencyName, dependencyPath); + enumeratedDependencies.put(dependencyName, dependencyElement); } - public HashMap getCollectedDependencies() + public List getCollectedDependencies() { - return (HashMap) this.enumeratedDependencies.entrySet().stream().parallel() - .filter(entry -> entry.getValue() != null) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + return this.enumeratedDependencies.entrySet().stream().parallel() + .map(Map.Entry::getValue) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } public List getCollectFailedDependencies() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java index bc38a13a..9aa45e4b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java @@ -3,6 +3,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyDownloadFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; @@ -92,9 +93,13 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal dependsDescriptions.entrySet().stream().parallel() .filter(entry -> Objects.nonNull(entry.getValue())) .filter(entry -> downloadResults.containsKey(entry.getKey())) - .forEach(entry -> - this.cache.onCollect(entry.getValue().getName(), downloadResults.get(entry.getKey()).getPath()) - ); + .forEach(entry -> { + String exceptedName = entry.getValue().getName(); + String actualName = entry.getKey(); + Path pluginPath = downloadResults.get(actualName).getPath(); + if (pluginPath != null) // Should not be null + this.cache.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath)); + }); if (!this.cache.save()) this.postSignal(new DependsCacheSaveFailedSignal()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java index c8e73833..c26b4056 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java @@ -3,11 +3,10 @@ import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.nio.file.Path; -import java.util.HashMap; import java.util.List; @Value @@ -18,14 +17,14 @@ public class DependsCollectResult extends PhaseResult collectedPlugins; + List collectedPlugins; @NotNull List collectFailedPlugins; public DependsCollectResult(boolean success, @NotNull DependsCollectState phase, @Nullable DependsCollectErrorCause errorCause, @NotNull String targetPlugin, - @NotNull HashMap collectedPlugins, + @NotNull List collectedPlugins, @NotNull List collectFailedPlugins) { super(success, phase, errorCause); From 9f8e481d273a923728fa785573e6c26c4c2b501f Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 17 May 2022 23:00:06 +0900 Subject: [PATCH 168/745] feat: wip: installer: DependencyNameMismatchSignal --- .../collector/DependsCollectPhase.java | 12 ++++++++-- .../signals/DependencyNameMismatchSignal.java | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyNameMismatchSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java index 9aa45e4b..d8e43da5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java @@ -7,6 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyDownloadFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyNameMismatchSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyResolveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsCacheSaveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsEnumeratedSignal; @@ -96,9 +97,16 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal .forEach(entry -> { String exceptedName = entry.getValue().getName(); String actualName = entry.getKey(); + if (!exceptedName.equals(actualName)) + { + this.postSignal(new DependencyNameMismatchSignal(actualName, exceptedName)); + return; + } + Path pluginPath = downloadResults.get(actualName).getPath(); - if (pluginPath != null) // Should not be null - this.cache.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath)); + + assert pluginPath != null; + this.cache.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath)); }); if (!this.cache.save()) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyNameMismatchSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyNameMismatchSignal.java new file mode 100644 index 00000000..e8ee3d56 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyNameMismatchSignal.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; + +public class DependencyNameMismatchSignal extends DependencyCollectFailedSignalBase +{ + private final String exceptedDependencyName; + + public DependencyNameMismatchSignal(String actualDependencyName, String exceptedDependencyName) + { + super(actualDependencyName); + this.exceptedDependencyName = exceptedDependencyName; + } + + public String getExceptedDependencyName() + { + return this.exceptedDependencyName; + } + + public String getActualDependencyName() + { + return getFailedDependency(); + } +} From 588cc830926b85d4b0fc87f0fce0f2ce3b550de8 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 18 May 2022 10:57:16 +0900 Subject: [PATCH 169/745] feat: wip: installer: Description in DependencyElement --- .../phase/phases/dependencies/DependencyElement.java | 7 ++++++- .../phases/dependencies/collector/DependsCollectPhase.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java index 6fc5c592..8b890962 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies; import lombok.Data; +import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; @@ -12,13 +13,17 @@ public class DependencyElement private final String pluginName; @NotNull private final Path pluginPath; + @NotNull + private final PluginDescriptionFile pluginDescription; private int loadOrder; - public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath) + public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath, + @NotNull PluginDescriptionFile pluginDescription) { this.pluginName = pluginName; this.pluginPath = pluginPath; + this.pluginDescription = pluginDescription; this.loadOrder = -1; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java index d8e43da5..c72ce840 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java @@ -106,7 +106,7 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal Path pluginPath = downloadResults.get(actualName).getPath(); assert pluginPath != null; - this.cache.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath)); + this.cache.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath, entry.getValue())); }); if (!this.cache.save()) From 970060392fc6b8ba2b3aad6bdec5ccb88cdb80c6 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 19 May 2022 01:04:10 +0900 Subject: [PATCH 170/745] feat: wip: installer: Dependency load order compute phase --- .../dependencies/DependencyElement.java | 12 -- .../computer/DependsComputeOrderArgument.java | 22 +++ .../DependsComputeOrderErrorCause.java | 5 + .../computer/DependsComputeOrderPhase.java | 164 ++++++++++++++++++ .../computer/DependsComputeOrderResult.java | 24 +++ .../computer/DependsComputeOrderState.java | 9 + 6 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderState.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java index 8b890962..c74631dc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java @@ -15,16 +15,4 @@ public class DependencyElement private final Path pluginPath; @NotNull private final PluginDescriptionFile pluginDescription; - - private int loadOrder; - - public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath, - @NotNull PluginDescriptionFile pluginDescription) - { - this.pluginName = pluginName; - this.pluginPath = pluginPath; - this.pluginDescription = pluginDescription; - - this.loadOrder = -1; - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java new file mode 100644 index 00000000..e6ffc676 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectResult; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class DependsComputeOrderArgument extends PhaseArgument +{ + @Getter + private final List collectedDependencies; + + public DependsComputeOrderArgument(@NotNull DependsCollectResult previousPhaseResult) + { + super(previousPhaseResult); + + this.collectedDependencies = previousPhaseResult.getCollectedPlugins(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java new file mode 100644 index 00000000..e9d5a6da --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; + +public enum DependsComputeOrderErrorCause +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java new file mode 100644 index 00000000..cb051983 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java @@ -0,0 +1,164 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * This class is inspired by the class {@link org.bukkit.plugin.SimplePluginManager#loadPlugins(File, List)} + */ +public class DependsComputeOrderPhase extends InstallPhase +{ + private DependsComputeOrderState state; + + public DependsComputeOrderPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + { + super(progress, signalHandler); + + this.state = DependsComputeOrderState.INITIALIZED; + } + + private static DependencyElement get(String name, List plugins) + { + return plugins.stream().parallel() + .filter(plugin -> plugin.getPluginDescription().getName().equals(name)) + .findFirst().orElse(null); + } + + private static boolean contains(String name, List plugins) + { + return get(name, plugins) != null; + } + + @Override + public @NotNull DependsComputeOrderResult runPhase(@NotNull DependsComputeOrderArgument arguments) + { + this.state = DependsComputeOrderState.CREATING_DEPENDENCY_MAP; + + List plugins = new ArrayList<>(arguments.getCollectedDependencies()); + + Map> dependencies = new HashMap<>(); + Map> softDependencies = new HashMap<>(); + + for (DependencyElement plugin : plugins) + { + PluginDescriptionFile description = plugin.getPluginDescription(); + + List stagingDependencies = description.getDepend(); + if (!stagingDependencies.isEmpty()) + dependencies.put(description.getName(), new ArrayList<>(stagingDependencies)); + + List stagingSoftDependencies = description.getSoftDepend(); + if (!stagingSoftDependencies.isEmpty()) + if (softDependencies.containsKey(description.getName())) + softDependencies.get(description.getName()).addAll(stagingSoftDependencies); + else + softDependencies.put(description.getName(), new ArrayList<>(stagingSoftDependencies)); + + List loadBeforeSet = description.getLoadBefore(); + if (!loadBeforeSet.isEmpty()) + for (String loadBefore : loadBeforeSet) + if (softDependencies.containsKey(loadBefore)) + softDependencies.get(loadBefore).add(description.getName()); + else + softDependencies.put( + loadBefore, + new ArrayList<>(Collections.singletonList(description.getName())) + ); + } + + this.state = DependsComputeOrderState.COMPUTING_DEPENDENCY_LOAD_ORDER; + + List result = new ArrayList<>(); + + while (!plugins.isEmpty()) + { + boolean missingDependency = true; + + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) + { + DependencyElement plugin = iterator.next(); + String name = plugin.getPluginDescription().getName(); + + if (dependencies.containsKey(name)) + { + Iterator dependencyIterator = dependencies.get(name).iterator(); + + while (dependencyIterator.hasNext()) + { + String dependency = dependencyIterator.next(); + + if (contains(dependency, result)) + dependencyIterator.remove(); + else if (!contains(dependency, plugins)) + missingDependency = false; + } + + if (!missingDependency) + { + iterator.remove(); + softDependencies.remove(name); + dependencies.remove(name); + + // Severe log + } + + if (dependencies.containsKey(name) && dependencies.get(name).isEmpty()) + dependencies.remove(name); + } + + if (softDependencies.containsKey(name)) + { + softDependencies.get(name).removeIf(softDependency -> + !contains(softDependency, result) && !contains(softDependency, plugins)); + + if (softDependencies.get(name).isEmpty()) + softDependencies.remove(name); + } + + if (!(dependencies.containsKey(name) || softDependencies.containsKey(name)) && + contains(name, plugins)) + { + iterator.remove(); + missingDependency = false; + + result.add(plugin); + } + } + + if (missingDependency) + { + iterator = plugins.iterator(); + + while (iterator.hasNext()) + { + DependencyElement plugin = iterator.next(); + String name = plugin.getPluginDescription().getName(); + + if (!dependencies.containsKey(name)) + { + softDependencies.remove(name); + iterator.remove(); + + result.add(plugin); + break; + } + } + } + } + + return new DependsComputeOrderResult(true, this.state, null, result); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderResult.java new file mode 100644 index 00000000..29afbbf5 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderResult.java @@ -0,0 +1,24 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class DependsComputeOrderResult extends PhaseResult +{ + @Getter + @NotNull + private final List order; + + public DependsComputeOrderResult(boolean success, @NotNull DependsComputeOrderState phase, + @Nullable DependsComputeOrderErrorCause errorCause, + @NotNull List order) + { + super(success, phase, errorCause); + this.order = order; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderState.java new file mode 100644 index 00000000..a75c8c8a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderState.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; + +public enum DependsComputeOrderState +{ + INITIALIZED, + + CREATING_DEPENDENCY_MAP, + COMPUTING_DEPENDENCY_LOAD_ORDER +} From 8855b63aee67578b2aaa6ebe3fb1de7bd82eb19e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 19 May 2022 02:33:15 +0900 Subject: [PATCH 171/745] refactor: wip: installer: Extract removeOldPlugin --- .../installer/install/PluginInstaller.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 14528e2e..8d70aacb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesCollectFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectResult; @@ -23,8 +24,7 @@ import java.io.File; import java.io.IOException; -import java.nio.file.Path; -import java.util.HashMap; +import java.util.List; public class PluginInstaller extends AbstractInstaller { @@ -93,18 +93,7 @@ public InstallResult execute(@NotNull String query) // region Remove plugin if it is already installed. (only replacePlugin is true) if (replacePlugin) - { - this.progress.setPhase(InstallPhases.REMOVING_OLD_PLUGIN); - - File oldPluginFile = PluginUtil.getFile(sameServerPlugin); - - PluginUtil.unload(sameServerPlugin); // TODO: Replace with uninstall. - - if (!safeDelete(oldPluginFile)) - Runner.runLater(() -> { - safeDelete(oldPluginFile); - }, 10L); - } + this.removeOldPlugin(sameServerPlugin); // endregion if (replacePlugin) @@ -112,7 +101,7 @@ public InstallResult execute(@NotNull String query) else this.progress.addInstalled(pluginName); - HashMap collectedDependencies; + List collectedDependencies; // region Collecting dependencies section. this.progress.setPhase(InstallPhases.COLLECTING_DEPENDENCIES); @@ -131,4 +120,16 @@ public InstallResult execute(@NotNull String query) return this.success(); } + + private void removeOldPlugin(Plugin plugin) + { + File oldPluginFile = PluginUtil.getFile(plugin); + + PluginUtil.unload(plugin); // TODO: Replace with uninstall. + + if (!safeDelete(oldPluginFile)) + Runner.runLater(() -> { + safeDelete(oldPluginFile); + }, 10L); + } } From 4d77c057a6153b6a09cf9d82b860778322972696 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 19 May 2022 22:39:55 +0900 Subject: [PATCH 172/745] refactor: wip: installer: @Data => @Value --- .../phase/phases/dependencies/DependencyElement.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java index c74631dc..17b2edb4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java @@ -1,18 +1,18 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies; -import lombok.Data; +import lombok.Value; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; -@Data +@Value public class DependencyElement { @NotNull - private final String pluginName; + String pluginName; @NotNull - private final Path pluginPath; + Path pluginPath; @NotNull - private final PluginDescriptionFile pluginDescription; + PluginDescriptionFile pluginDescription; } From 14252e5f39e377227da2a9c9cfb9326485a27f0b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 19 May 2022 22:47:18 +0900 Subject: [PATCH 173/745] feat: wip: installer: Apply compute load order phase --- .../installer/install/InstallPhases.java | 1 + .../installer/install/PluginInstaller.java | 26 +++++++++++++++++++ .../DependenciesLoadOrderComputedSignal.java | 15 +++++++++++ .../computer/DependsComputeOrderArgument.java | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesLoadOrderComputedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java index fcf03400..cd5d47e5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java @@ -11,4 +11,5 @@ public enum InstallPhases CHECKING_ENVIRONMENT, REMOVING_OLD_PLUGIN, COLLECTING_DEPENDENCIES, + COMPUTING_LOAD_ORDER } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 8d70aacb..eacc5b12 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -5,10 +5,14 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesCollectFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesLoadOrderComputedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; @@ -24,6 +28,7 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; public class PluginInstaller extends AbstractInstaller @@ -117,6 +122,27 @@ public InstallResult execute(@NotNull String query) collectedDependencies = dependsCollectResult.getCollectedPlugins(); //endregion + ArrayList loadOrder; + // region Compute load order of collected dependencies. + this.progress.setPhase(InstallPhases.COMPUTING_LOAD_ORDER); + + DependsComputeOrderResult dependsComputeOrderResult = new DependsComputeOrderPhase(progress, signalHandler) + .runPhase(new DependsComputeOrderArgument(collectedDependencies)); + + if (!dependsComputeOrderResult.isSuccess()) + throw new IllegalStateException("Compute load order failed."); // Never happens. + + + // Post signal and get order if user is modifying load order. + DependenciesLoadOrderComputedSignal dependenciesLoadOrderComputedSignal = + new DependenciesLoadOrderComputedSignal(new ArrayList<>(dependsComputeOrderResult.getOrder())); + + this.postSignal(dependenciesLoadOrderComputedSignal); + + loadOrder = dependenciesLoadOrderComputedSignal.getDependencies(); + + // endregion + return this.success(); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesLoadOrderComputedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesLoadOrderComputedSignal.java new file mode 100644 index 00000000..f925acc2 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesLoadOrderComputedSignal.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; + +@Data +public class DependenciesLoadOrderComputedSignal implements InstallerSignal +{ + @NotNull + private final ArrayList dependencies; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java index e6ffc676..3177e654 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; +import lombok.AllArgsConstructor; import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; @@ -8,6 +9,7 @@ import java.util.List; +@AllArgsConstructor public class DependsComputeOrderArgument extends PhaseArgument { @Getter From c968191c42a0aa9ae03fe10acbb49a4454fb6d1d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 20 May 2022 23:45:33 +0900 Subject: [PATCH 174/745] fix: wip: installer: already installed compute --- .../computer/DependsComputeOrderPhase.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java index cb051983..2aa373c1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java @@ -4,6 +4,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -41,6 +42,11 @@ private static boolean contains(String name, List plugins) return get(name, plugins) != null; } + private static boolean isInstalled(String name) + { + return Bukkit.getPluginManager().getPlugin(name) != null; + } + @Override public @NotNull DependsComputeOrderResult runPhase(@NotNull DependsComputeOrderArgument arguments) { @@ -81,6 +87,7 @@ private static boolean contains(String name, List plugins) this.state = DependsComputeOrderState.COMPUTING_DEPENDENCY_LOAD_ORDER; List result = new ArrayList<>(); + List last = new ArrayList<>(); while (!plugins.isEmpty()) { @@ -100,7 +107,7 @@ private static boolean contains(String name, List plugins) { String dependency = dependencyIterator.next(); - if (contains(dependency, result)) + if (contains(dependency, result) || isInstalled(dependency)) dependencyIterator.remove(); else if (!contains(dependency, plugins)) missingDependency = false; @@ -108,7 +115,7 @@ else if (!contains(dependency, plugins)) if (!missingDependency) { - iterator.remove(); + last.add(plugin); softDependencies.remove(name); dependencies.remove(name); @@ -159,6 +166,8 @@ else if (!contains(dependency, plugins)) } } + result.addAll(last); + return new DependsComputeOrderResult(true, this.state, null, result); } } From cc299eec20a60c3930d4deda6330cda28c5fa5c8 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 07:15:47 +0900 Subject: [PATCH 175/745] feat: wip: installer: PluginsInstallPhase --- .../install/PluginsInstallArgument.java | 24 +++ .../install/PluginsInstallErrorCause.java | 11 + .../phases/install/PluginsInstallPhase.java | 193 ++++++++++++++++++ .../phases/install/PluginsInstallResult.java | 25 +++ .../phases/install/PluginsInstallState.java | 11 + .../install/signals/PluginLoadedSignal.java | 13 ++ .../signals/PluginOnEnableRunningSignal.java | 13 ++ .../signals/PluginOnLoadRunningSignal.java | 13 ++ .../signals/PluginRelocatingSignal.java | 16 ++ 9 files changed, 319 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginLoadedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnEnableRunningSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnLoadRunningSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginRelocatingSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallArgument.java new file mode 100644 index 00000000..370372e8 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallArgument.java @@ -0,0 +1,24 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; +import java.util.List; + +@Value +@EqualsAndHashCode(callSuper = false) +public class PluginsInstallArgument extends PhaseArgument +{ + @NotNull + Path pluginPath; + @NotNull + PluginDescriptionFile pluginDescription; + + @NotNull + List dependencies; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallErrorCause.java new file mode 100644 index 00000000..57661bbe --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallErrorCause.java @@ -0,0 +1,11 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; + +public enum PluginsInstallErrorCause +{ + RELOCATE_FAILED, + INVALID_PLUGIN, + INVALID_PLUGIN_DESCRIPTION, + + IO_EXCEPTION_OCCURRED, + EXCEPTION_OCCURRED +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java new file mode 100644 index 00000000..2711f3cf --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java @@ -0,0 +1,193 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; + +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginLoadedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginOnEnableRunningSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginOnLoadRunningSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginRelocatingSignal; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; +import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.List; + +public class PluginsInstallPhase extends InstallPhase +{ + private static final Path PLUGIN_DIR; + + static + { + PLUGIN_DIR = TeamKunPluginManager.getPlugin().getDataFolder().toPath().getParent(); + } + + private PluginsInstallState state; + + public PluginsInstallPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + { + super(progress, signalHandler); + + this.state = PluginsInstallState.INITIALIZED; + } + + @Override + public @NotNull PluginsInstallResult runPhase(@NotNull PluginsInstallArgument arguments) + { + List dependencies = arguments.getDependencies(); + + // Install dependencies + for (DependencyElement dependency : dependencies) + { + PluginDescriptionFile pluginDescription = dependency.getPluginDescription(); + Path path = dependency.getPluginPath(); + + PluginsInstallResult result = this.installOne(path, pluginDescription); + if (result != null) + return result; + } + + // Install plugin after dependencies installed + PluginsInstallResult result = this.installOne(arguments.getPluginPath(), arguments.getPluginDescription()); + if (result != null) + return result; + else + return new PluginsInstallResult(true, this.state, null); + } + + @Nullable + private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription) + { + this.state = PluginsInstallState.RELOCATING_PLUGIN; + + + // Relocate plugin + String fileName = pluginDescription.getName() + "-" + pluginDescription.getVersion() + ".jar"; + Path targetPath = PLUGIN_DIR.resolve(fileName); + + PluginsInstallResult mayError = this.movePlugin(path, targetPath); + + if (mayError != null) + return mayError; + + // Load plugin + this.state = PluginsInstallState.LOADING_PLUGIN; + + Plugin target; + try + { + target = Bukkit.getPluginManager().loadPlugin(path.toFile()); + assert target != null; + this.postSignal(new PluginLoadedSignal(target)); + + this.postSignal(new PluginOnLoadRunningSignal(target)); + this.state = PluginsInstallState.RUNNING_ONLOAD; + target.onLoad(); + + } + catch (InvalidDescriptionException e) + { + e.printStackTrace(); + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.INVALID_PLUGIN_DESCRIPTION); + } + catch (InvalidPluginException e) + { + e.printStackTrace(); + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.INVALID_PLUGIN); + } + catch (Exception e) + { + e.printStackTrace(); + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.EXCEPTION_OCCURRED); + } + + // Enable plugin + this.state = PluginsInstallState.RUNNING_ONENABLE; + this.postSignal(new PluginOnEnableRunningSignal(target)); + Bukkit.getPluginManager().enablePlugin(target); + + return null; // Success + } + + @Nullable + private String generateSHA1(@NotNull Path path) throws IOException + { + try (FileInputStream inputStream = new FileInputStream(path.toFile())) + { + return DigestUtils.sha1Hex(inputStream); + } + catch (FileNotFoundException e) + { + return null; + } + } + + private boolean moveFile(@NotNull Path source, @NotNull Path target, boolean overwrite) throws IOException + { + try + { + if (overwrite) + Files.move(source, target, StandardCopyOption.REPLACE_EXISTING); + else + Files.move(source, target); + + return true; + } + catch (FileAlreadyExistsException e) + { + String sourceHash = generateSHA1(source); + String targetHash = generateSHA1(target); + + if (sourceHash == null || targetHash == null) + return false; + + if (sourceHash.equals(targetHash)) + return true; + else + return moveFile(source, target, true); + } + } + + @Nullable + private PluginsInstallResult movePlugin(@NotNull Path source, @NotNull Path target) + { + PluginRelocatingSignal signal = new PluginRelocatingSignal(source, target); + this.postSignal(signal); + + target = signal.getTarget(); // May be changed by signal + + try + { + if (!moveFile(source, target, false)) + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.RELOCATE_FAILED); + else + return null; + } + catch (IOException e) + { + e.printStackTrace(); + + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.IO_EXCEPTION_OCCURRED); + } + catch (Exception e) + { + e.printStackTrace(); + + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.RELOCATE_FAILED); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallResult.java new file mode 100644 index 00000000..b814f585 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallResult.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PluginsInstallResult extends PhaseResult +{ + @Getter + @Nullable + private final String failedPluginName; + + public PluginsInstallResult(boolean success, @NotNull PluginsInstallState phase, @Nullable PluginsInstallErrorCause errorCause) + { + this(success, phase, errorCause, null); + } + + public PluginsInstallResult(boolean success, @NotNull PluginsInstallState phase, + @Nullable PluginsInstallErrorCause errorCause, @Nullable String failedPluginName) + { + super(success, phase, errorCause); + this.failedPluginName = failedPluginName; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallState.java new file mode 100644 index 00000000..ef719874 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallState.java @@ -0,0 +1,11 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; + +public enum PluginsInstallState +{ + INITIALIZED, + + RELOCATING_PLUGIN, + LOADING_PLUGIN, + RUNNING_ONLOAD, + RUNNING_ONENABLE, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginLoadedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginLoadedSignal.java new file mode 100644 index 00000000..01674977 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginLoadedSignal.java @@ -0,0 +1,13 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +@Value +public class PluginLoadedSignal implements InstallerSignal +{ + @NotNull + Plugin plugin; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnEnableRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnEnableRunningSignal.java new file mode 100644 index 00000000..74a3e4b4 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnEnableRunningSignal.java @@ -0,0 +1,13 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +@Value +public class PluginOnEnableRunningSignal implements InstallerSignal +{ + @NotNull + Plugin plugin; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnLoadRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnLoadRunningSignal.java new file mode 100644 index 00000000..9f1febd0 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnLoadRunningSignal.java @@ -0,0 +1,13 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +@Value +public class PluginOnLoadRunningSignal implements InstallerSignal +{ + @NotNull + Plugin plugin; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginRelocatingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginRelocatingSignal.java new file mode 100644 index 00000000..91bd4e2f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginRelocatingSignal.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +@Data +public class PluginRelocatingSignal implements InstallerSignal +{ + @NotNull + private final Path source; + @NotNull + private Path target; +} From 88594c266282a441f0f8ba6bfc8dd18a5377c76e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 07:28:56 +0900 Subject: [PATCH 176/745] refactor: wip: installer: Change signal post timing --- .../plugin/installer/install/PluginInstaller.java | 8 -------- .../computer/DependsComputeOrderPhase.java | 12 ++++++++++-- .../signals/DependenciesLoadOrderComputedSignal.java | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{install => phase/phases/dependencies/computer}/signals/DependenciesLoadOrderComputedSignal.java (80%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index eacc5b12..5e3cbb81 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -5,7 +5,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesCollectFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesLoadOrderComputedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; @@ -134,13 +133,6 @@ public InstallResult execute(@NotNull String query) // Post signal and get order if user is modifying load order. - DependenciesLoadOrderComputedSignal dependenciesLoadOrderComputedSignal = - new DependenciesLoadOrderComputedSignal(new ArrayList<>(dependsComputeOrderResult.getOrder())); - - this.postSignal(dependenciesLoadOrderComputedSignal); - - loadOrder = dependenciesLoadOrderComputedSignal.getDependencies(); - // endregion diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java index 2aa373c1..ae013a4d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java @@ -4,6 +4,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependenciesLoadOrderComputedSignal; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -86,7 +87,7 @@ private static boolean isInstalled(String name) this.state = DependsComputeOrderState.COMPUTING_DEPENDENCY_LOAD_ORDER; - List result = new ArrayList<>(); + ArrayList result = new ArrayList<>(); List last = new ArrayList<>(); while (!plugins.isEmpty()) @@ -168,6 +169,13 @@ else if (!contains(dependency, plugins)) result.addAll(last); - return new DependsComputeOrderResult(true, this.state, null, result); + + DependenciesLoadOrderComputedSignal dependenciesLoadOrderComputedSignal = + new DependenciesLoadOrderComputedSignal(result); + + this.postSignal(dependenciesLoadOrderComputedSignal); + + List actualResult = dependenciesLoadOrderComputedSignal.getDependencies(); + return new DependsComputeOrderResult(true, this.state, null, actualResult); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesLoadOrderComputedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputedSignal.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesLoadOrderComputedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputedSignal.java index f925acc2..6ae175ab 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesLoadOrderComputedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; From 657cbab7ddb17dc24e34004236876906961088dc Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 07:29:59 +0900 Subject: [PATCH 177/745] feat: wip: installer: DependenciesLoadOrderComputingSignal --- .../computer/DependsComputeOrderPhase.java | 4 ++++ .../DependenciesLoadOrderComputingSignal.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputingSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java index ae013a4d..b357a12b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependenciesLoadOrderComputedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependenciesLoadOrderComputingSignal; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -52,6 +53,9 @@ private static boolean isInstalled(String name) public @NotNull DependsComputeOrderResult runPhase(@NotNull DependsComputeOrderArgument arguments) { this.state = DependsComputeOrderState.CREATING_DEPENDENCY_MAP; + this.postSignal(new DependenciesLoadOrderComputingSignal( + Collections.unmodifiableList(arguments.getCollectedDependencies()) + )); List plugins = new ArrayList<>(arguments.getCollectedDependencies()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputingSignal.java new file mode 100644 index 00000000..538c1969 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputingSignal.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@Data +public class DependenciesLoadOrderComputingSignal implements InstallerSignal +{ + @NotNull + private final List dependencies; +} From 981d8ca0dbab710d37743686f7d78b5e7df94c96 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 07:30:36 +0900 Subject: [PATCH 178/745] refactor: wip: installer: Dependencies => Depends --- .../plugin/installer/install/PluginInstaller.java | 3 --- .../computer/DependsComputeOrderPhase.java | 14 +++++++------- ...al.java => DependsLoadOrderComputedSignal.java} | 2 +- ...l.java => DependsLoadOrderComputingSignal.java} | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/{DependenciesLoadOrderComputedSignal.java => DependsLoadOrderComputedSignal.java} (85%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/{DependenciesLoadOrderComputingSignal.java => DependsLoadOrderComputingSignal.java} (85%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 5e3cbb81..9d3df023 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -130,9 +130,6 @@ public InstallResult execute(@NotNull String query) if (!dependsComputeOrderResult.isSuccess()) throw new IllegalStateException("Compute load order failed."); // Never happens. - - - // Post signal and get order if user is modifying load order. // endregion diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java index b357a12b..0d3bbfaf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java @@ -4,8 +4,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependenciesLoadOrderComputedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependenciesLoadOrderComputingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependsLoadOrderComputedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependsLoadOrderComputingSignal; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -53,7 +53,7 @@ private static boolean isInstalled(String name) public @NotNull DependsComputeOrderResult runPhase(@NotNull DependsComputeOrderArgument arguments) { this.state = DependsComputeOrderState.CREATING_DEPENDENCY_MAP; - this.postSignal(new DependenciesLoadOrderComputingSignal( + this.postSignal(new DependsLoadOrderComputingSignal( Collections.unmodifiableList(arguments.getCollectedDependencies()) )); @@ -174,12 +174,12 @@ else if (!contains(dependency, plugins)) result.addAll(last); - DependenciesLoadOrderComputedSignal dependenciesLoadOrderComputedSignal = - new DependenciesLoadOrderComputedSignal(result); + DependsLoadOrderComputedSignal dependsLoadOrderComputedSignal = + new DependsLoadOrderComputedSignal(result); - this.postSignal(dependenciesLoadOrderComputedSignal); + this.postSignal(dependsLoadOrderComputedSignal); - List actualResult = dependenciesLoadOrderComputedSignal.getDependencies(); + List actualResult = dependsLoadOrderComputedSignal.getDependencies(); return new DependsComputeOrderResult(true, this.state, null, actualResult); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputedSignal.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputedSignal.java index 6ae175ab..3efe8894 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputedSignal.java @@ -8,7 +8,7 @@ import java.util.ArrayList; @Data -public class DependenciesLoadOrderComputedSignal implements InstallerSignal +public class DependsLoadOrderComputedSignal implements InstallerSignal { @NotNull private final ArrayList dependencies; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputingSignal.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputingSignal.java index 538c1969..c0ef6bdc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependenciesLoadOrderComputingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputingSignal.java @@ -8,7 +8,7 @@ import java.util.List; @Data -public class DependenciesLoadOrderComputingSignal implements InstallerSignal +public class DependsLoadOrderComputingSignal implements InstallerSignal { @NotNull private final List dependencies; From 4082cb336b1d7a7cc27862705f123661aa5779cc Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 08:12:53 +0900 Subject: [PATCH 179/745] feat: wip: installer: Apply installer --- .../installer/install/InstallPhases.java | 3 ++- .../installer/install/PluginInstaller.java | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java index cd5d47e5..c793beca 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java @@ -11,5 +11,6 @@ public enum InstallPhases CHECKING_ENVIRONMENT, REMOVING_OLD_PLUGIN, COLLECTING_DEPENDENCIES, - COMPUTING_LOAD_ORDER + COMPUTING_LOAD_ORDER, + INSTALLING_PLUGINS, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 9d3df023..8f15be37 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -11,10 +11,11 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.AlreadyInstalledPluginSignal; @@ -27,7 +28,6 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.List; public class PluginInstaller extends AbstractInstaller @@ -121,15 +121,14 @@ public InstallResult execute(@NotNull String query) collectedDependencies = dependsCollectResult.getCollectedPlugins(); //endregion - ArrayList loadOrder; - // region Compute load order of collected dependencies. - this.progress.setPhase(InstallPhases.COMPUTING_LOAD_ORDER); + // region Do compute dependencies load order and install them. + PluginsInstallResult pluginsInstallResult = (PluginsInstallResult) + this.submitter(InstallPhases.COMPUTING_LOAD_ORDER, new DependsComputeOrderPhase(progress, signalHandler)) + .then(InstallPhases.INSTALLING_PLUGINS, new PluginsInstallPhase(progress, signalHandler)) + .submit(new DependsComputeOrderArgument(collectedDependencies)); - DependsComputeOrderResult dependsComputeOrderResult = new DependsComputeOrderPhase(progress, signalHandler) - .runPhase(new DependsComputeOrderArgument(collectedDependencies)); - - if (!dependsComputeOrderResult.isSuccess()) - throw new IllegalStateException("Compute load order failed."); // Never happens. + if (!pluginsInstallResult.isSuccess()) + return handlePhaseError(pluginDescriptionResult); // endregion From fcc2a7f22d3375dc7798449cb6952992eba5f4ec Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 08:14:25 +0900 Subject: [PATCH 180/745] feat: wip: installer: REMOVING_OLD_PLUGIN --- .../plugin/installer/install/PluginInstaller.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 8f15be37..beec70a3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -137,6 +137,8 @@ public InstallResult execute(@NotNull String query) private void removeOldPlugin(Plugin plugin) { + this.progress.setPhase(InstallPhases.REMOVING_OLD_PLUGIN); + File oldPluginFile = PluginUtil.getFile(plugin); PluginUtil.unload(plugin); // TODO: Replace with uninstall. From b016fc92a2c2ded82e99a1872fade7ff9836b814 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 08:20:02 +0900 Subject: [PATCH 181/745] refactor: wip: installer: COLLECTING_DEPENDENCIES --- .../installer/install/InstallErrorCause.java | 2 -- .../installer/install/PluginInstaller.java | 28 +++---------------- .../collector/DependsCollectPhase.java | 7 ++++- .../signals/DependsCollectFailedSignal.java} | 4 +-- 4 files changed, 12 insertions(+), 29 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{install/signals/DependenciesCollectFailedSignal.java => phase/phases/dependencies/collector/signals/DependsCollectFailedSignal.java} (50%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java index daf95b9f..3e843f2f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java @@ -6,8 +6,6 @@ public enum InstallErrorCause PHASE_EXCEPTION_OCCURRED, PHASE_FAILED, - SOME_DEPENDENCY_COLLECT_FAILED, - // Environment errors PLUGIN_IGNORED, PLUGIN_ALREADY_INSTALLED, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index beec70a3..576568c1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -4,12 +4,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.DependenciesCollectFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; @@ -28,7 +24,6 @@ import java.io.File; import java.io.IOException; -import java.util.List; public class PluginInstaller extends AbstractInstaller { @@ -105,27 +100,12 @@ public InstallResult execute(@NotNull String query) else this.progress.addInstalled(pluginName); - List collectedDependencies; - // region Collecting dependencies section. - this.progress.setPhase(InstallPhases.COLLECTING_DEPENDENCIES); - - DependsCollectResult dependsCollectResult = new DependsCollectPhase(progress, signalHandler) - .runPhase(new DependsCollectArgument(pluginDescription)); - - if (!dependsCollectResult.isSuccess()) - { - this.postSignal(new DependenciesCollectFailedSignal(dependsCollectResult.getCollectFailedPlugins())); - return this.error(InstallErrorCause.SOME_DEPENDENCY_COLLECT_FAILED); - } - - collectedDependencies = dependsCollectResult.getCollectedPlugins(); - //endregion - - // region Do compute dependencies load order and install them. + // region Do collect dependencies, compute dependencies load order and install them. PluginsInstallResult pluginsInstallResult = (PluginsInstallResult) - this.submitter(InstallPhases.COMPUTING_LOAD_ORDER, new DependsComputeOrderPhase(progress, signalHandler)) + this.submitter(InstallPhases.COLLECTING_DEPENDENCIES, new DependsCollectPhase(progress, signalHandler)) + .then(InstallPhases.COMPUTING_LOAD_ORDER, new DependsComputeOrderPhase(progress, signalHandler)) .then(InstallPhases.INSTALLING_PLUGINS, new PluginsInstallPhase(progress, signalHandler)) - .submit(new DependsComputeOrderArgument(collectedDependencies)); + .submit(new DependsCollectArgument(pluginDescription)); if (!pluginsInstallResult.isSuccess()) return handlePhaseError(pluginDescriptionResult); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java index c72ce840..cb96dbff 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java @@ -10,6 +10,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyNameMismatchSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyResolveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsCacheSaveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsCollectFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; @@ -126,9 +127,13 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal boolean success = this.cache.isErrors(); DependsCollectErrorCause errorCause = success ? null: DependsCollectErrorCause.SOME_DEPENDENCIES_COLLECT_FAILED; + List collectFailedDependencies = this.cache.getCollectFailedDependencies(); + if (!success) + this.postSignal(new DependsCollectFailedSignal(collectFailedDependencies)); + return new DependsCollectResult( success, this.phaseState, errorCause, - pluginName, this.cache.getCollectedDependencies(), this.cache.getCollectFailedDependencies() + pluginName, this.cache.getCollectedDependencies(), collectFailedDependencies ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesCollectFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCollectFailedSignal.java similarity index 50% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesCollectFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCollectFailedSignal.java index 214d8b51..2d6ba324 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/DependenciesCollectFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCollectFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; @@ -6,7 +6,7 @@ import java.util.List; @Value -public class DependenciesCollectFailedSignal implements InstallerSignal +public class DependsCollectFailedSignal implements InstallerSignal { List collectFailedPlugins; } From f4a03dcd5c2a2121b868d03d32c439f5d3efe04c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 22:12:41 +0900 Subject: [PATCH 182/745] fix: wip: installer: Fix counter --- .../installer/phase/phases/install/PluginsInstallPhase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java index 2711f3cf..9a3acbac 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java @@ -94,6 +94,8 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr assert target != null; this.postSignal(new PluginLoadedSignal(target)); + this.progress.addInstalled(target.getName()); + this.postSignal(new PluginOnLoadRunningSignal(target)); this.state = PluginsInstallState.RUNNING_ONLOAD; target.onLoad(); From 901afa60b4fc4931973018615ab5b7efbb9faacd Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 21 May 2022 22:22:13 +0900 Subject: [PATCH 183/745] refactor: wip: installer: Change type of String to PluginDescriptionFile on PluginModifiedSignal --- .../plugin/AbstractInstaller.java | 2 +- .../plugin/installer/InstallProgress.java | 44 ++++++++++++++----- .../installer/install/PluginInstaller.java | 4 +- .../phases/install/PluginsInstallPhase.java | 2 +- .../signals/PluginModifiedSignal.java | 2 - 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index e7b70370..eee7f400 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -25,7 +25,7 @@ public abstract class AbstractInstaller, P extends Enum

> public AbstractInstaller(InstallerSignalHandler signalHandler) throws IOException { - this.progress = InstallProgress.of(null); + this.progress = InstallProgress.of(signalHandler, null); this.signalHandler = signalHandler; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 9532d680..6e28142f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -4,7 +4,9 @@ import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectCache; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; import org.apache.commons.io.FileUtils; +import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,10 +39,13 @@ public class InstallProgress

> private final Path installTempDir; private final String installActionID; + private final InstallerSignalHandler signalHandler; private final DependsCollectCache dependsCollectCache; - private InstallProgress(@Nullable String id) throws IOException, SecurityException + private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable String id) throws IOException, SecurityException { + this.signalHandler = signalHandler; + this.upgraded = new ArrayList<>(); this.installed = new ArrayList<>(); this.removed = new ArrayList<>(); @@ -63,10 +68,11 @@ private InstallProgress(@Nullable String id) throws IOException, SecurityExcepti progressCaches.put(this.getInstallActionID(), this); } - public static

> InstallProgress

of(@Nullable String id) throws IOException, SecurityException + public static

> InstallProgress

of(@NotNull InstallerSignalHandler signalHandler, + @Nullable String id) throws IOException, SecurityException { if (id == null) - return new InstallProgress<>(null); + return new InstallProgress<>(signalHandler, null); else return (InstallProgress

) progressCaches.get(id); } @@ -79,25 +85,39 @@ private void removeFromAll(@NotNull String name) this.pending.remove(name); } - public void addUpgraded(@NotNull String pluginName) + public void addUpgraded(@NotNull PluginDescriptionFile pluginDescription) { - this.removeFromAll(pluginName); + this.removeFromAll(pluginDescription.getName()); - this.upgraded.add(pluginName); + this.signalHandler.handleSignal( + this, + new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.UPGRADE) + ); + this.upgraded.add(pluginDescription.getName()); } - public void addInstalled(@NotNull String pluginName) + public void addInstalled(@NotNull PluginDescriptionFile pluginDescription) { - this.removeFromAll(pluginName); + this.removeFromAll(pluginDescription.getName()); - this.installed.add(pluginName); + this.signalHandler.handleSignal( + this, + new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.ADD) + ); + + + this.installed.add(pluginDescription.getName()); } - public void addRemoved(@NotNull String pluginName) + public void addRemoved(@NotNull PluginDescriptionFile pluginDescription) { - this.removeFromAll(pluginName); + this.removeFromAll(pluginDescription.getName()); - this.removed.add(pluginName); + this.signalHandler.handleSignal( + this, + new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.REMOVE) + ); + this.removed.add(pluginDescription.getName()); } public void addPending(@NotNull String pluginName) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 576568c1..4525c722 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -96,9 +96,9 @@ public InstallResult execute(@NotNull String query) // endregion if (replacePlugin) - this.progress.addUpgraded(pluginName); + this.progress.addUpgraded(pluginDescription); else - this.progress.addInstalled(pluginName); + this.progress.addInstalled(pluginDescription); // region Do collect dependencies, compute dependencies load order and install them. PluginsInstallResult pluginsInstallResult = (PluginsInstallResult) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java index 9a3acbac..824bec65 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java @@ -94,7 +94,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr assert target != null; this.postSignal(new PluginLoadedSignal(target)); - this.progress.addInstalled(target.getName()); + this.progress.addInstalled(target.getDescription()); this.postSignal(new PluginOnLoadRunningSignal(target)); this.state = PluginsInstallState.RUNNING_ONLOAD; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java index 27578b23..780ce2bb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java @@ -8,8 +8,6 @@ @Value public class PluginModifiedSignal implements InstallerSignal { - @NotNull - String pluginName; @NotNull PluginDescriptionFile pluginDescription; @NotNull From 35554080a7337777a7506be7bb7b8997ef67416b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 24 May 2022 02:15:52 +0900 Subject: [PATCH 184/745] refactor: wip: installer: Location of alreadyInstalledPluginSignal --- .../plugin/installer/install/PluginInstaller.java | 2 +- .../signals}/AlreadyInstalledPluginSignal.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{signals/assertion => install/signals}/AlreadyInstalledPluginSignal.java (90%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 4525c722..a465ec45 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -4,6 +4,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderPhase; @@ -14,7 +15,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/AlreadyInstalledPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/AlreadyInstalledPluginSignal.java similarity index 90% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/AlreadyInstalledPluginSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/AlreadyInstalledPluginSignal.java index d60be946..8ac66120 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/AlreadyInstalledPluginSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/AlreadyInstalledPluginSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; From 9fef714801ac08930221527e19b430c87435607c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 31 May 2022 01:34:16 +0900 Subject: [PATCH 185/745] feat: Debug Command --- .../commands/CommandDebug.java | 37 ++++ .../commands/debug/CommandInstallDebug.java | 85 +++++++++ .../commands/debug/DebugSignalHandler.java | 170 ++++++++++++++++++ src/main/resources/plugin.yml | 7 + 4 files changed, 299 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java new file mode 100644 index 00000000..86c2e369 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java @@ -0,0 +1,37 @@ +package net.kunmc.lab.teamkunpluginmanager.commands; + +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +public class CommandDebug extends SubCommandWith +{ + @Override + protected String getName() + { + return "debug"; + } + + @Override + protected Map getSubCommands(@NotNull CommandSender sender) + { + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.debug"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("KPMのデバッグに使用します。"); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java new file mode 100644 index 00000000..a1ac27da --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java @@ -0,0 +1,85 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.debug; + +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.InstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.InstallPhases; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.PluginInstaller; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; + +public class CommandInstallDebug extends CommandBase +{ + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 1)) + return; + + String query = args[0]; + + Runner.runAsync(() -> { + try + { + PluginInstaller installer = new PluginInstaller(new DebugSignalHandler(terminal)); + + InstallResult installResult = installer.execute(query); + + if (installResult instanceof InstallFailedInstallResult) + { + InstallFailedInstallResult failedInstallResult = + (InstallFailedInstallResult) installResult; + + terminal.error("Install has failed for " + + failedInstallResult.getReason() + " in " + failedInstallResult.getProgress() + " of " + + failedInstallResult.getPhaseStatus()); + } + + terminal.success("Install succeed: "); + terminal.info("Installed: " + Arrays.toString(installResult.getInstalled())); + terminal.info("Pending: " + Arrays.toString(installResult.getPending())); + terminal.info("Removed: " + Arrays.toString(installResult.getRemoved())); + terminal.info("Upgraded: " + Arrays.toString(installResult.getUpgraded())); + } + catch (Exception e) + { + e.printStackTrace(); + terminal.error(e.getClass() + ": " + e.getMessage()); + } + }); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.debug.install"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("インストールのデバッグコマンドです。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("query", "Query") + }; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java new file mode 100644 index 00000000..2e24b3da --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -0,0 +1,170 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.debug; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Question; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.Map; + +@AllArgsConstructor +public class DebugSignalHandler implements InstallerSignalHandler +{ + private final Terminal terminal; + + private static void handleInputSignals(T signal, Terminal terminal) + { + try + { + if (signal instanceof AlreadyInstalledPluginSignal) + { + AlreadyInstalledPluginSignal alreadyInstalledPluginSignal = (AlreadyInstalledPluginSignal) signal; + + Question question = terminal.getInput().showYNQuestion("Newly install?"); + alreadyInstalledPluginSignal.setReplacePlugin(question.waitAndGetResult().test(QuestionAttribute.YES)); + } + else if (signal instanceof IgnoredPluginSignal) + { + IgnoredPluginSignal ignoredPluginSignal = (IgnoredPluginSignal) signal; + + Question question = terminal.getInput().showYNQuestion("Cancel?"); + ignoredPluginSignal.setCancelInstall(question.waitAndGetResult().test(QuestionAttribute.YES)); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + private static void printSignal(T signal, Terminal terminal) + { + terminal.writeLine("===================="); + terminal.info("On Signal: " + signal.getClass().getSimpleName()); + terminal.info("Values:"); + varDump(signal, terminal); + terminal.writeLine("===================="); + } + + private static void printField(String fieldName, Object o, Terminal terminal, int indent) + { + String typePrefix = getTypePrefix(o); + + String indentStr = StringUtils.repeat(" ", indent); + + boolean noValue = o != null && + o.getClass().isArray() || + o instanceof Collection || + o instanceof Map; + + + if (noValue) + terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + typePrefix); + else if (o instanceof Map.Entry) + { + Map.Entry entry = (Map.Entry) o; + terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + + typePrefix + " " + entry.getKey() + ": " + entry.getValue()); + } + else + terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + typePrefix + o); + } + + private static String getTypePrefix(Object o) + { + if (o == null) + return ChatColor.GRAY + "null"; + + if (!(o instanceof Class) && o.getClass().isArray()) + return getTypePrefix(o.getClass().getComponentType()) + "["; + + Class clazz; + if (o instanceof Class) + clazz = (Class) o; + else + clazz = o.getClass(); + + if (Integer.class.isAssignableFrom(clazz) || int.class.isAssignableFrom(clazz)) + return ChatColor.BLUE + "I"; + else if (String.class.isAssignableFrom(clazz)) + return ChatColor.GOLD + "S"; + else if (Boolean.class.isAssignableFrom(clazz) || boolean.class.isAssignableFrom(clazz)) + return ChatColor.GREEN + "B"; + else if (Character.class.isAssignableFrom(clazz) || char.class.isAssignableFrom(clazz)) + return ChatColor.DARK_PURPLE + "C"; + else if (Double.class.isAssignableFrom(clazz) || double.class.isAssignableFrom(clazz)) + return ChatColor.AQUA + "D"; + else if (Float.class.isAssignableFrom(clazz) || float.class.isAssignableFrom(clazz)) + return ChatColor.DARK_AQUA + "F"; + else if (Long.class.isAssignableFrom(clazz) || long.class.isAssignableFrom(clazz)) + return ChatColor.DARK_GREEN + "L"; + else if (Short.class.isAssignableFrom(clazz) || short.class.isAssignableFrom(clazz)) + return ChatColor.DARK_RED + "S"; + else if (Byte.class.isAssignableFrom(clazz) || byte.class.isAssignableFrom(clazz)) + return ChatColor.DARK_PURPLE + "BY"; + else if (Map.Entry.class.isAssignableFrom(clazz)) + return getTypePrefix(clazz.getGenericSuperclass()) + " => " + getTypePrefix(clazz.getGenericInterfaces()[0]); + else + return "L" + clazz.getName() + ";: "; + } + + private static void varDumpRecursive(Field field, Object o, Terminal terminal, int indent) + throws IllegalAccessException + { + Object value = field.get(o); + printField(field.getName(), value, terminal, indent); + + if (value != null) + { + if (value.getClass().isArray()) + for (int i = 0; i < Array.getLength(value); i++) + { + Object element = Array.get(value, i); + varDumpRecursive(field, element, terminal, indent + 1); + } + else if (value instanceof Collection) + for (Object element : (Collection) value) + varDumpRecursive(field, element, terminal, indent + 1); + else if (value instanceof Map) + for (Map.Entry entry : ((Map) value).entrySet()) + varDumpRecursive(field, entry, terminal, indent + 1); + } + } + + private static void varDump(Object o, Terminal terminal) + { + Field[] fields = o.getClass().getDeclaredFields(); + for (Field field : fields) + { + field.setAccessible(true); + + try + { + varDumpRecursive(field, field.get(o), terminal, 0); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + } + } + } + + @Override + public void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal) + { + printSignal(signal, terminal); + + handleInputSignals(signal, terminal); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1e051569..51a7e8dd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -48,3 +48,10 @@ permissions: description: "エイリアス定義データベースを更新します。" kpm.help: description: "プラグインのヘルプを表示します。" + + kpm.debug: + description: "プラグインのデバッグを行います。" + default: false + children: + kpm.debug.install: true + From bc30feebe39ed1b34f8a3cf3578d767a67974c94 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Tue, 31 May 2022 02:37:38 +0900 Subject: [PATCH 186/745] feat: Debug Command --- .../teamkunpluginmanager/TeamKunPluginManager.java | 2 ++ .../teamkunpluginmanager/commands/CommandDebug.java | 12 +++++++++++- .../commands/debug/DebugSignalHandler.java | 3 +-- src/main/resources/plugin.yml | 6 ++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 54ba686b..682d7f90 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -7,6 +7,7 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.commands.CommandAutoRemove; import net.kunmc.lab.teamkunpluginmanager.commands.CommandClean; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandDebug; import net.kunmc.lab.teamkunpluginmanager.commands.CommandFix; import net.kunmc.lab.teamkunpluginmanager.commands.CommandInfo; import net.kunmc.lab.teamkunpluginmanager.commands.CommandInstall; @@ -118,6 +119,7 @@ public static void registerCommands(CommandManager commandManager) commandManager.registerCommand("status", new CommandStatus()); commandManager.registerCommand("uninstall", new CommandUninstall(), "remove", "rm"); commandManager.registerCommand("update", new CommandUpdate()); + commandManager.registerCommand("debug", new CommandDebug()); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java index 86c2e369..d2294fb9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java @@ -2,15 +2,25 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; +import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandInstallDebug; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.Map; public class CommandDebug extends SubCommandWith { + private static final HashMap COMMANDS; + + static + { + COMMANDS = new HashMap<>(); + COMMANDS.put("installDebug", new CommandInstallDebug()); + } + @Override protected String getName() { @@ -20,7 +30,7 @@ protected String getName() @Override protected Map getSubCommands(@NotNull CommandSender sender) { - return null; + return COMMANDS; } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 2e24b3da..13a0c20a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -119,10 +119,9 @@ else if (Map.Entry.class.isAssignableFrom(clazz)) return "L" + clazz.getName() + ";: "; } - private static void varDumpRecursive(Field field, Object o, Terminal terminal, int indent) + private static void varDumpRecursive(Field field, Object value, Terminal terminal, int indent) throws IllegalAccessException { - Object value = field.get(o); printField(field.getName(), value, terminal, indent); if (value != null) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 51a7e8dd..371020f5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -51,7 +51,9 @@ permissions: kpm.debug: description: "プラグインのデバッグを行います。" - default: false + default: op children: - kpm.debug.install: true + kpm.debug.install: + description: "プラグインをインストールします。" + default: op From ef1f87556639298e4618488230ce2ff9cefa4f29 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:59:11 +0900 Subject: [PATCH 187/745] fix: Debug handler --- .../commands/debug/DebugSignalHandler.java | 103 ++++++++++++++---- 1 file changed, 81 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 13a0c20a..e2e90040 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -16,6 +16,8 @@ import java.lang.reflect.Array; import java.lang.reflect.Field; import java.util.Collection; +import java.util.HashMap; +import java.util.List; import java.util.Map; @AllArgsConstructor @@ -57,18 +59,12 @@ private static void printSignal(T signal, Terminal t terminal.writeLine("===================="); } - private static void printField(String fieldName, Object o, Terminal terminal, int indent) + private static void printField(String fieldName, Object o, Terminal terminal, int indent, boolean noValue) { String typePrefix = getTypePrefix(o); String indentStr = StringUtils.repeat(" ", indent); - boolean noValue = o != null && - o.getClass().isArray() || - o instanceof Collection || - o instanceof Map; - - if (noValue) terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + typePrefix); else if (o instanceof Map.Entry) @@ -81,13 +77,44 @@ else if (o instanceof Map.Entry) terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + typePrefix + o); } + private static void printString(String fieldName, String value, Terminal terminal, int indent) + { + String indentStr = StringUtils.repeat(" ", indent); + terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + value); + } + + private static boolean isCompatible(Object o) + { + if (o == null) + return true; + + Class clazz = o.getClass(); + + return clazz.isPrimitive() || + clazz.isAssignableFrom(String.class) || + clazz.isAssignableFrom(Integer.class) || + clazz.isAssignableFrom(Boolean.class) || + clazz.isAssignableFrom(Double.class) || + clazz.isAssignableFrom(Float.class) || + clazz.isAssignableFrom(Long.class) || + clazz.isAssignableFrom(Short.class) || + clazz.isAssignableFrom(Byte.class) || + clazz.isAssignableFrom(Character.class) || + clazz.isArray() || + clazz.isEnum() || + clazz.isAssignableFrom(HashMap.class) || + clazz.isAssignableFrom(List.class); + } + private static String getTypePrefix(Object o) { if (o == null) return ChatColor.GRAY + "null"; + String prefix = ""; + if (!(o instanceof Class) && o.getClass().isArray()) - return getTypePrefix(o.getClass().getComponentType()) + "["; + prefix = "[" + getTypePrefix(o.getClass().getComponentType()); Class clazz; if (o instanceof Class) @@ -96,33 +123,43 @@ private static String getTypePrefix(Object o) clazz = o.getClass(); if (Integer.class.isAssignableFrom(clazz) || int.class.isAssignableFrom(clazz)) - return ChatColor.BLUE + "I"; + return prefix + ChatColor.BLUE + "I"; else if (String.class.isAssignableFrom(clazz)) - return ChatColor.GOLD + "S"; + return prefix + ChatColor.GOLD + "S"; else if (Boolean.class.isAssignableFrom(clazz) || boolean.class.isAssignableFrom(clazz)) - return ChatColor.GREEN + "B"; + return prefix + ChatColor.GREEN + "Z"; else if (Character.class.isAssignableFrom(clazz) || char.class.isAssignableFrom(clazz)) - return ChatColor.DARK_PURPLE + "C"; + return prefix + ChatColor.DARK_PURPLE + "C"; else if (Double.class.isAssignableFrom(clazz) || double.class.isAssignableFrom(clazz)) - return ChatColor.AQUA + "D"; + return prefix + ChatColor.AQUA + "D"; else if (Float.class.isAssignableFrom(clazz) || float.class.isAssignableFrom(clazz)) - return ChatColor.DARK_AQUA + "F"; + return prefix + ChatColor.DARK_AQUA + "F"; else if (Long.class.isAssignableFrom(clazz) || long.class.isAssignableFrom(clazz)) - return ChatColor.DARK_GREEN + "L"; + return prefix + ChatColor.DARK_GREEN + "J"; else if (Short.class.isAssignableFrom(clazz) || short.class.isAssignableFrom(clazz)) - return ChatColor.DARK_RED + "S"; + return prefix + ChatColor.DARK_RED + "S"; else if (Byte.class.isAssignableFrom(clazz) || byte.class.isAssignableFrom(clazz)) - return ChatColor.DARK_PURPLE + "BY"; + return prefix + ChatColor.DARK_PURPLE + "B"; else if (Map.Entry.class.isAssignableFrom(clazz)) - return getTypePrefix(clazz.getGenericSuperclass()) + " => " + getTypePrefix(clazz.getGenericInterfaces()[0]); + return prefix + getTypePrefix(clazz.getGenericSuperclass()) + " => " + + getTypePrefix(clazz.getGenericInterfaces()[0]); else - return "L" + clazz.getName() + ";: "; + return prefix + "L" + clazz.getName() + ";: "; } private static void varDumpRecursive(Field field, Object value, Terminal terminal, int indent) throws IllegalAccessException { - printField(field.getName(), value, terminal, indent); + if (!isCompatible(value)) + { + printField(field.getName(), value, terminal, indent, false); + varDump(value, terminal, indent + 1); + return; + } + + printField(field.getName(), value, terminal, indent, + value != null && value.getClass().isArray() || value instanceof Collection || value instanceof Map + ); if (value != null) { @@ -141,7 +178,7 @@ else if (value instanceof Map) } } - private static void varDump(Object o, Terminal terminal) + private static void varDump(Object o, Terminal terminal, int indent) { Field[] fields = o.getClass().getDeclaredFields(); for (Field field : fields) @@ -150,15 +187,37 @@ private static void varDump(Object o, Terminal terminal) try { - varDumpRecursive(field, field.get(o), terminal, 0); + Object value = field.get(o); + + if (value.equals(o)) + printString(field.getName(), ChatColor.RED + "Singleton", terminal, indent); + + varDumpRecursive(field, value, terminal, indent); } catch (IllegalAccessException e) { + printString(field.getName(), + ChatColor.RED + "Unable to get the field value: An exception has occurred.", terminal, indent + ); e.printStackTrace(); } + catch (Exception e) + { + if (e.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) + printString(field.getName(), + ChatColor.RED + "Unable to get the field value: VM security error.", terminal, indent + ); + else + e.printStackTrace(); + } } } + private static void varDump(Object o, Terminal terminal) + { + varDump(o, terminal, 0); + } + @Override public void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal) { From 2d4406e7a0c992fed8f35683a4ac4b83b11b997d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 2 Jun 2022 21:16:55 +0900 Subject: [PATCH 188/745] fix: Installer error --- .../teamkunpluginmanager/plugin/AbstractInstaller.java | 3 ++- .../plugin/installer/install/PluginInstaller.java | 9 +++++---- .../plugin/installer/phase/PhaseSubmitter.java | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index eee7f400..fef385c8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -55,7 +55,8 @@ public , S extends Enum> InstallFailedInstallResult, T extends Enum> InstallResult

handlePhaseError(@NotNull PhaseResult result) + @SuppressWarnings("rawtypes") + protected InstallResult

handlePhaseError(@NotNull PhaseResult result) { if (result.getErrorCause() != null) return this.error(result.getErrorCause(), result.getPhase()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index a465ec45..45517dbd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderPhase; @@ -12,7 +13,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; @@ -33,13 +33,14 @@ public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOE } @Override + @SuppressWarnings("rawtypes") public InstallResult execute(@NotNull String query) { PluginDescriptionFile pluginDescription; String pluginName; // region Do plugin resolve, download and description load. - DescriptionLoadResult pluginDescriptionResult = (DescriptionLoadResult) + PhaseResult pluginDescriptionResult = this.submitter(InstallPhases.RESOLVING_QUERY, new PluginResolvePhase(progress, signalHandler)) .then(InstallPhases.DOWNLOADING, new DownloadPhase(progress, signalHandler)) .then(InstallPhases.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadPhase(progress, signalHandler)) @@ -48,7 +49,7 @@ public InstallResult execute(@NotNull String query) if (!pluginDescriptionResult.isSuccess()) return handlePhaseError(pluginDescriptionResult); - pluginDescription = pluginDescriptionResult.getDescription(); + pluginDescription = ((DescriptionLoadResult) pluginDescriptionResult).getDescription(); assert pluginDescription != null; // Not null because isSuccess() is true. pluginName = pluginDescription.getName(); @@ -101,7 +102,7 @@ public InstallResult execute(@NotNull String query) this.progress.addInstalled(pluginDescription); // region Do collect dependencies, compute dependencies load order and install them. - PluginsInstallResult pluginsInstallResult = (PluginsInstallResult) + PhaseResult pluginsInstallResult = this.submitter(InstallPhases.COLLECTING_DEPENDENCIES, new DependsCollectPhase(progress, signalHandler)) .then(InstallPhases.COMPUTING_LOAD_ORDER, new DependsComputeOrderPhase(progress, signalHandler)) .then(InstallPhases.INSTALLING_PLUGINS, new PluginsInstallPhase(progress, signalHandler)) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java index fc8d4ea3..7130c7b6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java @@ -78,6 +78,9 @@ private PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E p { while (submitter.next != null) { + if (!result.isSuccess()) + return result; + submitter = submitter.next; installer.getProgress().setPhase(submitter.phaseState); @@ -85,8 +88,6 @@ private PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E p result = submitter.submitOnceUnsafe(nextArgument); - if (!result.isSuccess()) - return result; } } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) From 61b904fd6b75edd4cb23861594861fe12b841ed7 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 4 Jun 2022 06:40:57 +0900 Subject: [PATCH 189/745] feat: ZprintErrorMessage on DebugSignalHandler --- .../commands/debug/DebugSignalHandler.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index e2e90040..bdb5b631 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -153,7 +153,7 @@ private static void varDumpRecursive(Field field, Object value, Terminal termina if (!isCompatible(value)) { printField(field.getName(), value, terminal, indent, false); - varDump(value, terminal, indent + 1); + varDump(value, terminal, indent + 1, false); return; } @@ -178,7 +178,7 @@ else if (value instanceof Map) } } - private static void varDump(Object o, Terminal terminal, int indent) + private static void varDump(Object o, Terminal terminal, int indent, boolean printFailedMessage) { Field[] fields = o.getClass().getDeclaredFields(); for (Field field : fields) @@ -196,17 +196,21 @@ private static void varDump(Object o, Terminal terminal, int indent) } catch (IllegalAccessException e) { - printString(field.getName(), - ChatColor.RED + "Unable to get the field value: An exception has occurred.", terminal, indent - ); + if (printFailedMessage) + printString(field.getName(), + ChatColor.RED + "Unable to get the field value: An exception has occurred.", terminal, indent + ); e.printStackTrace(); } catch (Exception e) { if (e.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) - printString(field.getName(), - ChatColor.RED + "Unable to get the field value: VM security error.", terminal, indent - ); + { + if (printFailedMessage) + printString(field.getName(), + ChatColor.RED + "Unable to get the field value: VM security error.", terminal, indent + ); + } else e.printStackTrace(); } @@ -215,7 +219,7 @@ private static void varDump(Object o, Terminal terminal, int indent) private static void varDump(Object o, Terminal terminal) { - varDump(o, terminal, 0); + varDump(o, terminal, 0, false); } @Override From 386bcf1808620636198c69868999faf3125de264 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 4 Jun 2022 10:49:43 +0900 Subject: [PATCH 190/745] fix: Array signature handling --- .../commands/debug/DebugSignalHandler.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index bdb5b631..71b1a002 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -16,8 +16,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Field; import java.util.Collection; -import java.util.HashMap; -import java.util.List; import java.util.Map; @AllArgsConstructor @@ -102,8 +100,8 @@ private static boolean isCompatible(Object o) clazz.isAssignableFrom(Character.class) || clazz.isArray() || clazz.isEnum() || - clazz.isAssignableFrom(HashMap.class) || - clazz.isAssignableFrom(List.class); + clazz.isAssignableFrom(Map.class) || + clazz.isAssignableFrom(Collection.class); } private static String getTypePrefix(Object o) @@ -113,15 +111,15 @@ private static String getTypePrefix(Object o) String prefix = ""; - if (!(o instanceof Class) && o.getClass().isArray()) - prefix = "[" + getTypePrefix(o.getClass().getComponentType()); - Class clazz; if (o instanceof Class) clazz = (Class) o; else clazz = o.getClass(); + if (clazz.isArray()) + prefix = "[" + getTypePrefix(clazz.getComponentType()); + if (Integer.class.isAssignableFrom(clazz) || int.class.isAssignableFrom(clazz)) return prefix + ChatColor.BLUE + "I"; else if (String.class.isAssignableFrom(clazz)) From 0964aa21f8661ef85a8d4c90545332bf8d97e406 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 4 Jun 2022 21:21:27 +0900 Subject: [PATCH 191/745] fix: Class cast exception --- .../commands/debug/DebugSignalHandler.java | 2 +- .../installer/phase/PhaseSubmitter.java | 62 +++++++++++-------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 71b1a002..c4765872 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -187,7 +187,7 @@ private static void varDump(Object o, Terminal terminal, int indent, boolean pri { Object value = field.get(o); - if (value.equals(o)) + if (o.equals(value)) printString(field.getName(), ChatColor.RED + "Singleton", terminal, indent); varDumpRecursive(field, value, terminal, indent); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java index 7130c7b6..ef2e1ff3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java @@ -6,6 +6,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.ParameterizedType; public class PhaseSubmitter< T extends PhaseArgument, @@ -67,6 +68,39 @@ private PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E p return this.phase.runPhase((A) argument); } + @SuppressWarnings("unchecked") + private static > Class getPhaseArgumentOf(@NotNull T phase) + { + return (Class) ((ParameterizedType) phase.getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; + } + + @SuppressWarnings("unchecked") + private static Constructor getConstructor(@NotNull Class clazz, + @NotNull PhaseResult parentResult) + { + + try + { + for (Constructor constructor : clazz.getConstructors()) + { + Class[] parameterTypes = constructor.getParameterTypes(); + if (parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(parentResult.getClass())) + { + constructor.setAccessible(true); + return (Constructor) constructor; + } + } + } + catch (Exception e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + + throw new IllegalArgumentException("No constructor found for " + clazz.getName()); + } + public @NotNull PhaseResult submit(@NotNull T firstArgument) { PhaseSubmitter submitter = this.first; @@ -84,7 +118,7 @@ private PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E p submitter = submitter.next; installer.getProgress().setPhase(submitter.phaseState); - PhaseArgument nextArgument = getConstructor(result).newInstance(result); + PhaseArgument nextArgument = getConstructor(getPhaseArgumentOf(submitter.phase), result).newInstance(result); result = submitter.submitOnceUnsafe(nextArgument); @@ -97,30 +131,4 @@ private PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E p return result; } - - @SuppressWarnings("unchecked") - private Constructor getConstructor(@NotNull PhaseResult parentResult) - { - Class argumentClass = PhaseArgument.class; - - try - { - for (Constructor constructor : argumentClass.getConstructors()) - { - Class[] parameterTypes = constructor.getParameterTypes(); - if (parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(parentResult.getClass())) - { - constructor.setAccessible(true); - return (Constructor) constructor; - } - } - } - catch (Exception e) - { - e.printStackTrace(); - throw new RuntimeException(e); - } - - throw new IllegalArgumentException("No constructor found for " + argumentClass.getName()); - } } From ec4f55c9e64309c6f900465236c455aed1490730 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 8 Jun 2022 18:31:47 +0900 Subject: [PATCH 192/745] fix: success flag --- .../plugin/installer/phase/phases/download/DownloadPhase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java index 5eac5eae..64cf6a20 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadPhase.java @@ -94,13 +94,13 @@ else if (e.getMessage().startsWith("No response body was returned")) DownloadErrorSignal error = new DownloadErrorSignal(cause, this.randomDownloadID, signalValue); this.postSignal(error); - return new DownloadResult(true, this.phaseState, path, -1, this.randomDownloadID, cause); + return new DownloadResult(false, this.phaseState, path, -1, this.randomDownloadID, cause); } catch (Exception e) { this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, this.randomDownloadID, e)); - return new DownloadResult(true, this.phaseState, path, -1, this.randomDownloadID, + return new DownloadResult(false, this.phaseState, path, -1, this.randomDownloadID, DownloadErrorCause.UNKNOWN_ERROR ); } From 286f2cbc66a2434054c554799d7b6625faea4728 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 10 Jun 2022 05:00:19 +0900 Subject: [PATCH 193/745] refactor: Change cache directory --- .../plugin/installer/InstallProgress.java | 17 ++++++++-- .../collector/DependsCollectCache.java | 34 +++---------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 6e28142f..44460dc1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -22,6 +22,7 @@ public class InstallProgress

> { private static final HashMap> progressCaches; + private static final Path CACHE_DIRECTORY; @Setter private P phase; @@ -34,6 +35,18 @@ public class InstallProgress

> static { progressCaches = new HashMap<>(); + CACHE_DIRECTORY = TeamKunPluginManager.getPlugin().getDataFolder().toPath().resolve(".cache"); + + if (!Files.exists(CACHE_DIRECTORY)) + try + { + Files.createDirectory(CACHE_DIRECTORY); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } } private final Path installTempDir; @@ -59,11 +72,11 @@ private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable this.installActionID = id; this.installTempDir = Files.createTempDirectory( - TeamKunPluginManager.getPlugin().getDataFolder().toPath(), + CACHE_DIRECTORY, this.getInstallActionID() ); - this.dependsCollectCache = new DependsCollectCache(this.installActionID); + this.dependsCollectCache = new DependsCollectCache(this); progressCaches.put(this.getInstallActionID(), this); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java index 4ffd331d..03390b04 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java @@ -5,14 +5,13 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,31 +35,13 @@ public class DependsCollectCache @NotNull private String pluginName; - public DependsCollectCache(@NotNull String installId) + public DependsCollectCache(InstallProgress progress) { - this.installId = installId; + this.installId = progress.getInstallActionID(); this.enumeratedDependencies = new HashMap<>(); - this.pluginName = "undefined-" + installId; + this.pluginName = "undefined-" + this.installId; - this.cacheFile = Paths.get(installId, installId + ".kpmcache").toFile(); - } - - public static DependsCollectCache of(@NotNull String installId) - { - File cacheFile = Paths.get(installId, installId + ".kpmcache").toFile(); - - if (!cacheFile.exists()) - return new DependsCollectCache(installId); - - try (FileReader fis = new FileReader(cacheFile)) - { - return gson.fromJson(fis, DependsCollectCache.class); - } - catch (IOException e) - { - e.printStackTrace(); - return new DependsCollectCache(installId); - } + this.cacheFile = progress.getInstallTempDir().resolve(this.installId + ".kpmcache").toFile(); } public void addDependency(@NotNull String dependencyName) @@ -114,9 +95,4 @@ public boolean save() return false; } } - - public DependsCollectCache update() - { - return of(this.installId); - } } From 6e12b081872a4322af3ea4765738c8c842e6ee78 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Fri, 10 Jun 2022 05:00:56 +0900 Subject: [PATCH 194/745] refactor: progressCaches => PROGRESS_CACHES --- .../plugin/installer/InstallProgress.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 44460dc1..3eb97eac 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -21,7 +21,7 @@ @Getter public class InstallProgress

> { - private static final HashMap> progressCaches; + private static final HashMap> PROGRESS_CACHES; private static final Path CACHE_DIRECTORY; @Setter @@ -34,7 +34,7 @@ public class InstallProgress

> static { - progressCaches = new HashMap<>(); + PROGRESS_CACHES = new HashMap<>(); CACHE_DIRECTORY = TeamKunPluginManager.getPlugin().getDataFolder().toPath().resolve(".cache"); if (!Files.exists(CACHE_DIRECTORY)) @@ -78,7 +78,7 @@ private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable this.dependsCollectCache = new DependsCollectCache(this); - progressCaches.put(this.getInstallActionID(), this); + PROGRESS_CACHES.put(this.getInstallActionID(), this); } public static

> InstallProgress

of(@NotNull InstallerSignalHandler signalHandler, @@ -87,7 +87,7 @@ public static

> InstallProgress

of(@NotNull InstallerSignal if (id == null) return new InstallProgress<>(signalHandler, null); else - return (InstallProgress

) progressCaches.get(id); + return (InstallProgress

) PROGRESS_CACHES.get(id); } private void removeFromAll(@NotNull String name) @@ -151,6 +151,6 @@ public void finish() e.printStackTrace(); } - progressCaches.remove(this.getInstallActionID()); + PROGRESS_CACHES.remove(this.getInstallActionID()); } } From 89f3e2e37df3c3b70402881a42ca72f9d63f46bd Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 13 Jul 2022 17:45:58 +0900 Subject: [PATCH 195/745] fix: Invalid merge --- .../plugin/installer/install/PluginInstaller.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 45517dbd..2878fc70 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -16,6 +16,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -122,7 +123,7 @@ private void removeOldPlugin(Plugin plugin) File oldPluginFile = PluginUtil.getFile(plugin); - PluginUtil.unload(plugin); // TODO: Replace with uninstall. + PluginLoader.getInstance().unloadPlugin(plugin); // TODO: Replace with uninstall. if (!safeDelete(oldPluginFile)) Runner.runLater(() -> { From 70f69d5359cc7392184262885348e102038f5531 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 28 Jul 2022 03:58:05 +0900 Subject: [PATCH 196/745] fix: Degrade of previous rebasing --- .../lab/teamkunpluginmanager/plugin/Installer.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index cc9b2e6d..52a0cca5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -9,6 +9,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; @@ -103,7 +104,7 @@ public static void unInstall(@NotNull Terminal terminal, @NotNull String name, b terminal.writeLine(ChatColor.LIGHT_PURPLE + "プラグインを削除中..."); //プラグインをアンロード - PluginUtil.unload(plugin); + PluginLoader.getInstance().unloadPlugin(plugin); //非同期実行 Runner.runLaterAsync(() -> { @@ -362,7 +363,7 @@ else if (resolveResult instanceof SuccessResult) )); //バージョンの低いプラグインをアンインストール。 - PluginUtil.unload(plugin); + PluginLoader.getInstance().unloadPlugin(plugin); Runner.runLater(() -> { //削除する場合は削除 @@ -516,7 +517,7 @@ else if (resolveResult instanceof SuccessResult) //依存関係が1つでも読まれた場合はかかった時間を表示 if (!dependFirst) - terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, BigDecimal.ROUND_DOWN) + "秒で取得しました。"); + terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, RoundingMode.DOWN) + "秒で取得しました。"); //結果を表示しないモードで依存関係エラーが発生した場合はreturn if (!terminal.isPlayer() && !failedResolve.isEmpty()) @@ -555,7 +556,7 @@ else if (resolveResult instanceof SuccessResult) delete(terminal, new File("plugins/" + f.getFileName())); //プラグインをアンロード - PluginUtil.unload(plugin); + PluginLoader.getInstance().unloadPlugin(plugin); Runner.runLaterAsync(() -> { File file = PluginUtil.getFile(plugin); @@ -564,8 +565,7 @@ else if (resolveResult instanceof SuccessResult) }, 20L); } - //依存関係をロード - PluginUtil.load(f.getFileName().substring(0, f.getFileName().length() - 4)); + PluginLoader.getInstance().loadPlugin(new File("plugins", f.getFileName()).toPath()); } catch (Exception e) //例外が発生した場合 { From 7091f1bc4bc219c31c703799903d56509643f5b4 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 30 Jul 2022 04:28:01 +0900 Subject: [PATCH 197/745] fix: Throttling var_dump in debugger --- .../commands/debug/DebugSignalHandler.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index c4765872..279b412e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -8,19 +8,26 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadProgressSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Array; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.util.Collection; import java.util.Map; @AllArgsConstructor public class DebugSignalHandler implements InstallerSignalHandler { + private static final int MAX_INDENT = 5; + private final Terminal terminal; private static void handleInputSignals(T signal, Terminal terminal) @@ -139,8 +146,27 @@ else if (Short.class.isAssignableFrom(clazz) || short.class.isAssignableFrom(cla else if (Byte.class.isAssignableFrom(clazz) || byte.class.isAssignableFrom(clazz)) return prefix + ChatColor.DARK_PURPLE + "B"; else if (Map.Entry.class.isAssignableFrom(clazz)) - return prefix + getTypePrefix(clazz.getGenericSuperclass()) + " => " + - getTypePrefix(clazz.getGenericInterfaces()[0]); + { + Map.Entry entry = (Map.Entry) o; + return prefix + getTypePrefix(entry.getKey()) + " => " + getTypePrefix(entry.getValue()); + } + else if (Collection.class.isAssignableFrom(clazz)) + { + Type type = clazz.getGenericSuperclass(); + if (type instanceof ParameterizedType) + { + ParameterizedType parameterizedType = (ParameterizedType) type; + Type[] typeArguments = parameterizedType.getActualTypeArguments(); + if (typeArguments.length == 1) + return prefix + getTypePrefix(typeArguments[0]) + "[]"; + } + + return prefix + ChatColor.DARK_GRAY + "Collection[?]"; + } + else if (clazz.isEnum()) + return prefix + ChatColor.DARK_PURPLE + "E"; + else if (clazz.isPrimitive()) + return prefix + ChatColor.GRAY + clazz.getSimpleName(); else return prefix + "L" + clazz.getName() + ";: "; } @@ -150,8 +176,9 @@ private static void varDumpRecursive(Field field, Object value, Terminal termina { if (!isCompatible(value)) { + printField(field.getName(), value, terminal, indent, false); - varDump(value, terminal, indent + 1, false); + varDump(value, terminal, indent + 1, false, Modifier.STATIC | Modifier.FINAL); return; } @@ -176,11 +203,17 @@ else if (value instanceof Map) } } - private static void varDump(Object o, Terminal terminal, int indent, boolean printFailedMessage) + private static void varDump(Object o, Terminal terminal, int indent, boolean printFailedMessage, int... ignoreModifiers) { + if (indent > MAX_INDENT) + return; + Field[] fields = o.getClass().getDeclaredFields(); for (Field field : fields) { + if (ArrayUtils.contains(ignoreModifiers, field.getModifiers())) + continue; + field.setAccessible(true); try @@ -223,7 +256,8 @@ private static void varDump(Object o, Terminal terminal) @Override public void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal) { - printSignal(signal, terminal); + if (!(signal instanceof DownloadProgressSignal)) + printSignal(signal, terminal); handleInputSignals(signal, terminal); } From ed9d768ff30ef957b71439217d649699decdef0a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 30 Jul 2022 05:32:43 +0900 Subject: [PATCH 198/745] fix: Reverted error detecting process --- .../phases/dependencies/collector/DependsCollectCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java index 03390b04..49addca4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java @@ -57,7 +57,7 @@ public boolean isCollected(@NotNull String dependencyName) public boolean isErrors() { - return enumeratedDependencies.containsValue(null); + return !enumeratedDependencies.containsValue(null); } public void onCollect(@NotNull String dependencyName, DependencyElement dependencyElement) From 3d5da81bd77d079295b107c6ce3ac97a04711a7c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 30 Jul 2022 06:30:36 +0900 Subject: [PATCH 199/745] fix: Installing error --- .../installer/install/PluginInstaller.java | 28 +++++++++++++++++-- .../description/DescriptionLoadPhase.java | 11 +++++--- .../description/DescriptionLoadResult.java | 8 +++++- .../phases/install/PluginsInstallPhase.java | 2 +- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 2878fc70..4294ced2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -6,12 +6,15 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallPhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; @@ -25,6 +28,8 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.util.List; public class PluginInstaller extends AbstractInstaller { @@ -37,6 +42,7 @@ public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOE @SuppressWarnings("rawtypes") public InstallResult execute(@NotNull String query) { + Path pluginFilePath; PluginDescriptionFile pluginDescription; String pluginName; // region Do plugin resolve, download and description load. @@ -50,7 +56,10 @@ public InstallResult execute(@NotNull String query) if (!pluginDescriptionResult.isSuccess()) return handlePhaseError(pluginDescriptionResult); - pluginDescription = ((DescriptionLoadResult) pluginDescriptionResult).getDescription(); + DescriptionLoadResult descriptionLoadResult = (DescriptionLoadResult) pluginDescriptionResult; + + pluginFilePath = descriptionLoadResult.getPluginFile(); + pluginDescription = descriptionLoadResult.getDescription(); assert pluginDescription != null; // Not null because isSuccess() is true. pluginName = pluginDescription.getName(); @@ -102,13 +111,26 @@ public InstallResult execute(@NotNull String query) else this.progress.addInstalled(pluginDescription); + List dependenciesLoadOrder; // region Do collect dependencies, compute dependencies load order and install them. - PhaseResult pluginsInstallResult = + PhaseResult dependsComputeOrderResult = this.submitter(InstallPhases.COLLECTING_DEPENDENCIES, new DependsCollectPhase(progress, signalHandler)) .then(InstallPhases.COMPUTING_LOAD_ORDER, new DependsComputeOrderPhase(progress, signalHandler)) - .then(InstallPhases.INSTALLING_PLUGINS, new PluginsInstallPhase(progress, signalHandler)) .submit(new DependsCollectArgument(pluginDescription)); + if (!dependsComputeOrderResult.isSuccess()) + return handlePhaseError(pluginDescriptionResult); + + dependenciesLoadOrder = ((DependsComputeOrderResult) dependsComputeOrderResult).getOrder(); + // endregion + + // region Install plugins. + + PhaseResult pluginsInstallResult = + this.submitter(InstallPhases.INSTALLING_PLUGINS, new PluginsInstallPhase(progress, signalHandler)) + .submit(new PluginsInstallArgument( + pluginFilePath, pluginDescription, dependenciesLoadOrder)); + if (!pluginsInstallResult.isSuccess()) return handlePhaseError(pluginDescriptionResult); // endregion diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java index 6b028306..1f6dbef3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull; import java.io.IOException; +import java.nio.file.Path; public class DescriptionLoadPhase extends InstallPhase { @@ -24,6 +25,8 @@ public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull Insta @Override public @NotNull DescriptionLoadResult runPhase(@NotNull DescriptionLoadArgument arguments) { + Path pluginFile = arguments.getPluginFile(); + this.postSignal(new LoadPluginDescriptionSignal(arguments.getPluginFile())); PluginDescriptionFile pluginYml; @@ -37,13 +40,13 @@ public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull Insta { if (e.getMessage().equals("This file isn't plugin.")) return new DescriptionLoadResult(false, this.phaseState, - DescriptionLoadErrorCause.NOT_A_PLUGIN, null + DescriptionLoadErrorCause.NOT_A_PLUGIN, pluginFile, null ); else { e.printStackTrace(); return new DescriptionLoadResult(false, this.phaseState, - DescriptionLoadErrorCause.INVALID_DESCRIPTION, null + DescriptionLoadErrorCause.INVALID_DESCRIPTION, pluginFile, null ); } } @@ -51,10 +54,10 @@ public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull Insta { e.printStackTrace(); return new DescriptionLoadResult(false, this.phaseState, - DescriptionLoadErrorCause.IO_EXCEPTION, null + DescriptionLoadErrorCause.IO_EXCEPTION, pluginFile, null ); } - return new DescriptionLoadResult(true, this.phaseState, null, pluginYml); + return new DescriptionLoadResult(true, this.phaseState, null, pluginFile, pluginYml); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java index 7796355c..181acabd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java @@ -6,17 +6,23 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.nio.file.Path; + @Getter public class DescriptionLoadResult extends PhaseResult { + @NotNull + private final Path pluginFile; @Nullable private final PluginDescriptionFile description; public DescriptionLoadResult(boolean success, @NotNull DescriptionLoadState phase, @Nullable DescriptionLoadErrorCause errorCause, - @Nullable PluginDescriptionFile description) + @NotNull Path pluginFile, @Nullable PluginDescriptionFile description) { super(success, phase, errorCause); + + this.pluginFile = pluginFile; this.description = description; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java index 824bec65..cc27080f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java @@ -90,7 +90,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr Plugin target; try { - target = Bukkit.getPluginManager().loadPlugin(path.toFile()); + target = Bukkit.getPluginManager().loadPlugin(targetPath.toFile()); assert target != null; this.postSignal(new PluginLoadedSignal(target)); From d988478b6e8fe3758de059fe32d46900db2f1d58 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 30 Jul 2022 07:07:46 +0900 Subject: [PATCH 200/745] fix: StackOverFlowError on depends save --- .../dependencies/DependencyElement.java | 24 +++++++++++++++++++ .../collector/DependsCollectCache.java | 5 +++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java index 17b2edb4..f2035ca1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java @@ -1,18 +1,42 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies; +import com.google.gson.annotations.Expose; +import lombok.AllArgsConstructor; import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; @Value +@AllArgsConstructor public class DependencyElement { + @Expose @NotNull String pluginName; + @Expose @NotNull Path pluginPath; + @NotNull PluginDescriptionFile pluginDescription; + + public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath) + { + this.pluginName = pluginName; + this.pluginPath = pluginPath; + + try + { + this.pluginDescription = PluginUtil.loadDescription(pluginPath.toFile()); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java index 49addca4..6c2ce57e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; @@ -22,7 +23,9 @@ @AllArgsConstructor public class DependsCollectCache { - private static final Gson gson = new Gson(); + private static final Gson gson = new GsonBuilder() + .excludeFieldsWithoutExposeAnnotation() + .create(); @NotNull private final File cacheFile; From 5e64bc96635c1551229cea58a4e58e43c29a6179 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 30 Jul 2022 07:39:38 +0900 Subject: [PATCH 201/745] fix: Invalid error message --- .../plugin/installer/install/PluginInstaller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 4294ced2..40d35c58 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -119,7 +119,7 @@ public InstallResult execute(@NotNull String query) .submit(new DependsCollectArgument(pluginDescription)); if (!dependsComputeOrderResult.isSuccess()) - return handlePhaseError(pluginDescriptionResult); + return handlePhaseError(dependsComputeOrderResult); dependenciesLoadOrder = ((DependsComputeOrderResult) dependsComputeOrderResult).getOrder(); // endregion From 2295e6d59796888b4b648a2daf80edbd156b02cf Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 31 Jul 2022 00:33:00 +0900 Subject: [PATCH 202/745] revert: Remove cache --- .../plugin/installer/InstallProgress.java | 6 ++--- .../collector/DependsCollectPhase.java | 20 ++++++-------- ...ctCache.java => DependsCollectStatus.java} | 26 ++----------------- 3 files changed, 13 insertions(+), 39 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/{DependsCollectCache.java => DependsCollectStatus.java} (79%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 3eb97eac..06e85772 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -3,7 +3,7 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectCache; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectStatus; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; import org.apache.commons.io.FileUtils; import org.bukkit.plugin.PluginDescriptionFile; @@ -53,7 +53,7 @@ public class InstallProgress

> private final String installActionID; private final InstallerSignalHandler signalHandler; - private final DependsCollectCache dependsCollectCache; + private final DependsCollectStatus dependsCollectStatus; private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable String id) throws IOException, SecurityException { @@ -76,7 +76,7 @@ private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable this.getInstallActionID() ); - this.dependsCollectCache = new DependsCollectCache(this); + this.dependsCollectStatus = new DependsCollectStatus(this); PROGRESS_CACHES.put(this.getInstallActionID(), this); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java index cb96dbff..de0a2d5a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java @@ -9,7 +9,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyNameMismatchSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyResolveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsCacheSaveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsCollectFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; @@ -37,7 +36,7 @@ public class DependsCollectPhase extends InstallPhase { // TODO: きれいに private final InstallerSignalHandler signalHandler; - private final DependsCollectCache cache; + private final DependsCollectStatus status; private DependsCollectState phaseState; @@ -46,7 +45,7 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal super(progress, signalHandler); this.signalHandler = signalHandler; - this.cache = progress.getDependsCollectCache(); + this.status = progress.getDependsCollectStatus(); this.phaseState = DependsCollectState.INITIALIZED; } @@ -55,7 +54,7 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal public @NotNull DependsCollectResult runPhase(@NotNull DependsCollectArgument arguments) { PluginDescriptionFile pluginDescription = arguments.getPluginDescription(); - this.cache.setPluginName(pluginDescription.getName()); + this.status.setPluginName(pluginDescription.getName()); String pluginName = pluginDescription.getName(); // Enumerate dependencies @@ -66,7 +65,7 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal this.postSignal(dependsSignal); - dependsSignal.getDependencies().forEach(this.cache::addDependency); + dependsSignal.getDependencies().forEach(this.status::addDependency); HashMap resolvedResults; // region Resolve dependencies @@ -107,12 +106,9 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal Path pluginPath = downloadResults.get(actualName).getPath(); assert pluginPath != null; - this.cache.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath, entry.getValue())); + this.status.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath, entry.getValue())); }); - if (!this.cache.save()) - this.postSignal(new DependsCacheSaveFailedSignal()); - //------------------------ // Collect dependency's dependencies @@ -124,16 +120,16 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal // endregion - boolean success = this.cache.isErrors(); + boolean success = this.status.isErrors(); DependsCollectErrorCause errorCause = success ? null: DependsCollectErrorCause.SOME_DEPENDENCIES_COLLECT_FAILED; - List collectFailedDependencies = this.cache.getCollectFailedDependencies(); + List collectFailedDependencies = this.status.getCollectFailedDependencies(); if (!success) this.postSignal(new DependsCollectFailedSignal(collectFailedDependencies)); return new DependsCollectResult( success, this.phaseState, errorCause, - pluginName, this.cache.getCollectedDependencies(), collectFailedDependencies + pluginName, this.status.getCollectedDependencies(), collectFailedDependencies ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectStatus.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectStatus.java index 6c2ce57e..097fb442 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectCache.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectStatus.java @@ -10,9 +10,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -21,14 +18,11 @@ @Data @AllArgsConstructor -public class DependsCollectCache +public class DependsCollectStatus { private static final Gson gson = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .create(); - - @NotNull - private final File cacheFile; @NotNull private final String installId; @NotNull @@ -38,13 +32,11 @@ public class DependsCollectCache @NotNull private String pluginName; - public DependsCollectCache(InstallProgress progress) + public DependsCollectStatus(InstallProgress progress) { this.installId = progress.getInstallActionID(); this.enumeratedDependencies = new HashMap<>(); this.pluginName = "undefined-" + this.installId; - - this.cacheFile = progress.getInstallTempDir().resolve(this.installId + ".kpmcache").toFile(); } public void addDependency(@NotNull String dependencyName) @@ -84,18 +76,4 @@ public List getCollectFailedDependencies() .map(Map.Entry::getKey) .collect(Collectors.toList()); } - - public boolean save() - { - try (FileWriter fos = new FileWriter(this.cacheFile)) - { - fos.write(gson.toJson(this)); - return true; - } - catch (IOException e) - { - e.printStackTrace(); - return false; - } - } } From b81d49bc4e943a2459fb49086ef0afe433993979 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 14 Aug 2022 17:46:30 +0900 Subject: [PATCH 203/745] fix: Debugger error --- .../commands/debug/DebugSignalHandler.java | 67 +++++++------------ 1 file changed, 24 insertions(+), 43 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 279b412e..4587830f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -18,8 +18,6 @@ import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; import java.util.Collection; import java.util.Map; @@ -64,22 +62,23 @@ private static void printSignal(T signal, Terminal t terminal.writeLine("===================="); } - private static void printField(String fieldName, Object o, Terminal terminal, int indent, boolean noValue) + private static void printField(String fieldName, Object o, Terminal terminal, int indent, boolean noValue, boolean noName) { String typePrefix = getTypePrefix(o); String indentStr = StringUtils.repeat(" ", indent); + String prefix = indentStr + ChatColor.YELLOW + (noName ? " ": fieldName + " ==> ") + typePrefix; + if (noValue) - terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + typePrefix); + terminal.writeLine(prefix); else if (o instanceof Map.Entry) { Map.Entry entry = (Map.Entry) o; - terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + - typePrefix + " " + entry.getKey() + ": " + entry.getValue()); + terminal.writeLine(prefix + entry.getKey() + ": " + entry.getValue()); } else - terminal.writeLine(indentStr + ChatColor.YELLOW + fieldName + " ==> " + typePrefix + o); + terminal.writeLine(prefix + o); } private static void printString(String fieldName, String value, Terminal terminal, int indent) @@ -96,19 +95,19 @@ private static boolean isCompatible(Object o) Class clazz = o.getClass(); return clazz.isPrimitive() || - clazz.isAssignableFrom(String.class) || - clazz.isAssignableFrom(Integer.class) || - clazz.isAssignableFrom(Boolean.class) || - clazz.isAssignableFrom(Double.class) || - clazz.isAssignableFrom(Float.class) || - clazz.isAssignableFrom(Long.class) || - clazz.isAssignableFrom(Short.class) || - clazz.isAssignableFrom(Byte.class) || - clazz.isAssignableFrom(Character.class) || + String.class.isAssignableFrom(clazz) || + Integer.class.isAssignableFrom(clazz) || + Boolean.class.isAssignableFrom(clazz) || + Double.class.isAssignableFrom(clazz) || + Float.class.isAssignableFrom(clazz) || + Long.class.isAssignableFrom(clazz) || + Short.class.isAssignableFrom(clazz) || + Byte.class.isAssignableFrom(clazz) || + Character.class.isAssignableFrom(clazz) || clazz.isArray() || clazz.isEnum() || - clazz.isAssignableFrom(Map.class) || - clazz.isAssignableFrom(Collection.class); + Map.class.isAssignableFrom(clazz) || + Collection.class.isAssignableFrom(clazz); } private static String getTypePrefix(Object o) @@ -145,24 +144,6 @@ else if (Short.class.isAssignableFrom(clazz) || short.class.isAssignableFrom(cla return prefix + ChatColor.DARK_RED + "S"; else if (Byte.class.isAssignableFrom(clazz) || byte.class.isAssignableFrom(clazz)) return prefix + ChatColor.DARK_PURPLE + "B"; - else if (Map.Entry.class.isAssignableFrom(clazz)) - { - Map.Entry entry = (Map.Entry) o; - return prefix + getTypePrefix(entry.getKey()) + " => " + getTypePrefix(entry.getValue()); - } - else if (Collection.class.isAssignableFrom(clazz)) - { - Type type = clazz.getGenericSuperclass(); - if (type instanceof ParameterizedType) - { - ParameterizedType parameterizedType = (ParameterizedType) type; - Type[] typeArguments = parameterizedType.getActualTypeArguments(); - if (typeArguments.length == 1) - return prefix + getTypePrefix(typeArguments[0]) + "[]"; - } - - return prefix + ChatColor.DARK_GRAY + "Collection[?]"; - } else if (clazz.isEnum()) return prefix + ChatColor.DARK_PURPLE + "E"; else if (clazz.isPrimitive()) @@ -171,19 +152,19 @@ else if (clazz.isPrimitive()) return prefix + "L" + clazz.getName() + ";: "; } - private static void varDumpRecursive(Field field, Object value, Terminal terminal, int indent) + private static void varDumpRecursive(Field field, Object value, Terminal terminal, int indent, boolean noName) throws IllegalAccessException { if (!isCompatible(value)) { - printField(field.getName(), value, terminal, indent, false); + printField(field.getName(), value, terminal, indent, false, noName); varDump(value, terminal, indent + 1, false, Modifier.STATIC | Modifier.FINAL); return; } printField(field.getName(), value, terminal, indent, - value != null && value.getClass().isArray() || value instanceof Collection || value instanceof Map + value != null && value.getClass().isArray() || value instanceof Collection || value instanceof Map, noName ); if (value != null) @@ -192,14 +173,14 @@ private static void varDumpRecursive(Field field, Object value, Terminal termina for (int i = 0; i < Array.getLength(value); i++) { Object element = Array.get(value, i); - varDumpRecursive(field, element, terminal, indent + 1); + varDumpRecursive(field, element, terminal, indent + 1, true); } else if (value instanceof Collection) for (Object element : (Collection) value) - varDumpRecursive(field, element, terminal, indent + 1); + varDumpRecursive(field, element, terminal, indent + 1, true); else if (value instanceof Map) for (Map.Entry entry : ((Map) value).entrySet()) - varDumpRecursive(field, entry, terminal, indent + 1); + varDumpRecursive(field, entry, terminal, indent + 1, true); } } @@ -223,7 +204,7 @@ private static void varDump(Object o, Terminal terminal, int indent, boolean pri if (o.equals(value)) printString(field.getName(), ChatColor.RED + "Singleton", terminal, indent); - varDumpRecursive(field, value, terminal, indent); + varDumpRecursive(field, value, terminal, indent, false); } catch (IllegalAccessException e) { From b2730d06c6fea11ff24d2e9b8f53be017d506af7 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 15 Aug 2022 09:41:29 +0900 Subject: [PATCH 204/745] =?UTF-8?q?refactor:=20Pending=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/installer/install/PluginInstaller.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 40d35c58..4783816c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -106,10 +106,8 @@ public InstallResult execute(@NotNull String query) this.removeOldPlugin(sameServerPlugin); // endregion - if (replacePlugin) - this.progress.addUpgraded(pluginDescription); - else - this.progress.addInstalled(pluginDescription); + this.progress.addPending(pluginDescription.getName()); + List dependenciesLoadOrder; // region Do collect dependencies, compute dependencies load order and install them. @@ -135,6 +133,10 @@ public InstallResult execute(@NotNull String query) return handlePhaseError(pluginDescriptionResult); // endregion + if (replacePlugin) + this.progress.addUpgraded(pluginDescription); + else + this.progress.addInstalled(pluginDescription); return this.success(); } From b834bcc819c8003d8164a34207f8b0678a49fb6c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:38:11 +0900 Subject: [PATCH 205/745] refactor: Phase => Task --- .../commands/debug/CommandInstallDebug.java | 10 +- .../commands/debug/DebugSignalHandler.java | 2 +- .../plugin/AbstractInstaller.java | 28 ++-- .../installer/InstallFailedInstallResult.java | 8 +- .../plugin/installer/InstallProgress.java | 8 +- .../installer/install/InstallErrorCause.java | 6 +- .../{InstallPhases.java => InstallTasks.java} | 2 +- .../installer/install/PluginInstaller.java | 58 ++++---- .../phase/GeneralPhaseErrorCause.java | 8 -- .../plugin/installer/phase/PhaseArgument.java | 22 --- .../installer/phase/PhaseSubmitter.java | 134 ------------------ .../collector/DependsCollectErrorCause.java | 6 - .../computer/DependsComputeOrderArgument.java | 24 ---- .../DependsComputeOrderErrorCause.java | 5 - .../description/DescriptionLoadArgument.java | 32 ----- .../installer/task/GeneralTaskErrorCause.java | 8 ++ .../InstallTask.java} | 6 +- .../plugin/installer/task/TaskArgument.java | 22 +++ .../PhaseResult.java => task/TaskResult.java} | 6 +- .../plugin/installer/task/TaskSubmitter.java | 134 ++++++++++++++++++ .../dependencies/DependencyElement.java | 2 +- .../collector/DependsCollectArgument.java | 8 +- .../collector/DependsCollectErrorCause.java | 6 + .../collector/DependsCollectResult.java | 12 +- .../collector/DependsCollectState.java | 2 +- .../collector/DependsCollectStatus.java | 4 +- .../collector/DependsCollectTask.java} | 62 ++++---- ...CollectDependencysDependsFailedSignal.java | 2 +- .../DependencyCollectFailedSignalBase.java | 2 +- .../DependencyDownloadFailedSignal.java | 2 +- ...DependencyLoadDescriptionFailedSignal.java | 2 +- .../signals/DependencyNameMismatchSignal.java | 2 +- .../DependencyResolveFailedSignal.java | 2 +- .../signals/DependsCacheSaveFailedSignal.java | 2 +- .../signals/DependsCollectFailedSignal.java | 2 +- .../signals/DependsEnumeratedSignal.java | 2 +- .../computer/DependsComputeOrderArgument.java | 24 ++++ .../DependsComputeOrderErrorCause.java | 5 + .../computer/DependsComputeOrderResult.java | 12 +- .../computer/DependsComputeOrderState.java | 2 +- .../computer/DependsComputeOrderTask.java} | 16 +-- .../DependsLoadOrderComputedSignal.java | 4 +- .../DependsLoadOrderComputingSignal.java | 4 +- .../description/DescriptionLoadArgument.java | 32 +++++ .../DescriptionLoadErrorCause.java | 2 +- .../description/DescriptionLoadResult.java | 10 +- .../description/DescriptionLoadState.java | 2 +- .../description/DescriptionLoadTask.java} | 26 ++-- .../signals/LoadPluginDescriptionSignal.java | 2 +- .../tasks}/download/DownloadArgument.java | 8 +- .../tasks}/download/DownloadErrorCause.java | 2 +- .../tasks}/download/DownloadResult.java | 14 +- .../tasks}/download/DownloadState.java | 2 +- .../tasks/download/DownloadTask.java} | 32 ++--- .../download/signals/DownloadErrorSignal.java | 4 +- .../signals/DownloadProgressSignal.java | 2 +- .../signals/DownloadStartingSignal.java | 2 +- .../signals/DownloadSucceedSignal.java | 2 +- .../install/PluginsInstallArgument.java | 8 +- .../install/PluginsInstallErrorCause.java | 2 +- .../tasks}/install/PluginsInstallResult.java | 14 +- .../tasks}/install/PluginsInstallState.java | 2 +- .../tasks/install/PluginsInstallTask.java} | 20 +-- .../install/signals/PluginLoadedSignal.java | 2 +- .../signals/PluginOnEnableRunningSignal.java | 2 +- .../signals/PluginOnLoadRunningSignal.java | 2 +- .../signals/PluginRelocatingSignal.java | 2 +- .../tasks}/resolve/PluginResolveArgument.java | 6 +- .../resolve/PluginResolveErrorCause.java | 2 +- .../tasks}/resolve/PluginResolveResult.java | 14 +- .../tasks}/resolve/PluginResolveState.java | 2 +- .../tasks/resolve/PluginResolveTask.java} | 36 ++--- .../signals/MultiplePluginResolvedSignal.java | 2 +- .../signals/PluginResolveErrorSignal.java | 2 +- .../PluginResolvedSuccessfulSignal.java | 2 +- .../signals/PluginResolvingSignal.java | 2 +- 76 files changed, 487 insertions(+), 487 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/{InstallPhases.java => InstallTasks.java} (92%) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectErrorCause.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/InstallPhase.java => task/InstallTask.java} (70%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/PhaseResult.java => task/TaskResult.java} (61%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/DependencyElement.java (90%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/DependsCollectArgument.java (82%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/DependsCollectResult.java (68%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/DependsCollectState.java (62%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/DependsCollectStatus.java (92%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases/dependencies/collector/DependsCollectPhase.java => task/tasks/dependencies/collector/DependsCollectTask.java} (75%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java (77%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependencyCollectFailedSignalBase.java (73%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependencyDownloadFailedSignal.java (65%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java (67%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependencyNameMismatchSignal.java (83%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependencyResolveFailedSignal.java (65%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependsCacheSaveFailedSignal.java (58%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependsCollectFailedSignal.java (69%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/collector/signals/DependsEnumeratedSignal.java (78%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/computer/DependsComputeOrderResult.java (50%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/computer/DependsComputeOrderState.java (56%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases/dependencies/computer/DependsComputeOrderPhase.java => task/tasks/dependencies/computer/DependsComputeOrderTask.java} (87%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/computer/signals/DependsLoadOrderComputedSignal.java (60%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/dependencies/computer/signals/DependsLoadOrderComputingSignal.java (60%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/description/DescriptionLoadErrorCause.java (54%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/description/DescriptionLoadResult.java (65%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/description/DescriptionLoadState.java (50%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases/description/DescriptionLoadPhase.java => task/tasks/description/DescriptionLoadTask.java} (56%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/description/signals/LoadPluginDescriptionSignal.java (78%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/DownloadArgument.java (74%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/DownloadErrorCause.java (60%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/DownloadResult.java (61%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/DownloadState.java (52%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases/download/DownloadPhase.java => task/tasks/download/DownloadTask.java} (67%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/signals/DownloadErrorSignal.java (65%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/signals/DownloadProgressSignal.java (77%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/signals/DownloadStartingSignal.java (79%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/download/signals/DownloadSucceedSignal.java (78%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/PluginsInstallArgument.java (54%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/PluginsInstallErrorCause.java (66%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/PluginsInstallResult.java (52%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/PluginsInstallState.java (63%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases/install/PluginsInstallPhase.java => task/tasks/install/PluginsInstallTask.java} (85%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/signals/PluginLoadedSignal.java (75%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/signals/PluginOnEnableRunningSignal.java (76%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/signals/PluginOnLoadRunningSignal.java (75%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/install/signals/PluginRelocatingSignal.java (78%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/PluginResolveArgument.java (55%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/PluginResolveErrorCause.java (52%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/PluginResolveResult.java (59%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/PluginResolveState.java (63%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases/resolve/PluginResolvePhase.java => task/tasks/resolve/PluginResolveTask.java} (65%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/signals/MultiplePluginResolvedSignal.java (86%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/signals/PluginResolveErrorSignal.java (77%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/signals/PluginResolvedSuccessfulSignal.java (79%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{phase/phases => task/tasks}/resolve/signals/PluginResolvingSignal.java (80%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java index a1ac27da..616b02c1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java @@ -6,7 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.InstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.InstallPhases; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.InstallTasks; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.PluginInstaller; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -31,16 +31,16 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { PluginInstaller installer = new PluginInstaller(new DebugSignalHandler(terminal)); - InstallResult installResult = installer.execute(query); + InstallResult installResult = installer.execute(query); if (installResult instanceof InstallFailedInstallResult) { - InstallFailedInstallResult failedInstallResult = - (InstallFailedInstallResult) installResult; + InstallFailedInstallResult failedInstallResult = + (InstallFailedInstallResult) installResult; terminal.error("Install has failed for " + failedInstallResult.getReason() + " in " + failedInstallResult.getProgress() + " of " + - failedInstallResult.getPhaseStatus()); + failedInstallResult.getTaskStatus()); } terminal.success("Install succeed: "); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 4587830f..ed211016 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -8,8 +8,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals.DownloadProgressSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index fef385c8..f48e7d3e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -7,11 +7,11 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.GeneralPhaseErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseSubmitter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.GeneralTaskErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskSubmitter; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -49,27 +49,27 @@ protected InstallResult

success() public , S extends Enum> InstallFailedInstallResult error( @NotNull T reason, - @NotNull S phaseStatus) + @NotNull S taskStatus) { // TODO: Implement debug mode - return new InstallFailedInstallResult<>(this.progress, reason, phaseStatus); + return new InstallFailedInstallResult<>(this.progress, reason, taskStatus); } @NotNull @SuppressWarnings("rawtypes") - protected InstallResult

handlePhaseError(@NotNull PhaseResult result) + protected InstallResult

handleTaskError(@NotNull TaskResult result) { if (result.getErrorCause() != null) - return this.error(result.getErrorCause(), result.getPhase()); + return this.error(result.getErrorCause(), result.getTask()); else - return this.error(GeneralPhaseErrorCause.ILLEGAL_INTERNAL_STATE, result.getPhase()); + return this.error(GeneralTaskErrorCause.ILLEGAL_INTERNAL_STATE, result.getTask()); } @NotNull - protected , PP extends InstallPhase> - PhaseSubmitter, A, R, PP> - submitter(@NotNull P phaseState, @NotNull PP phase) + protected , TT extends InstallTask> + TaskSubmitter, A, R, TT> + submitter(@NotNull P taskState, @NotNull TT task) { - return new PhaseSubmitter<>(phaseState, this, phase); + return new TaskSubmitter<>(taskState, this, task); } protected boolean isPluginIgnored(@NotNull String pluginName) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index 4279fadc..48f2316e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -11,19 +11,19 @@ public class InstallFailedInstallResult

, T extends Enum, S @NotNull private final T reason; @Nullable - private final S phaseStatus; + private final S taskStatus; - public InstallFailedInstallResult(@NotNull InstallProgress

progress, @NotNull T reason, @NotNull S phaseStatus) + public InstallFailedInstallResult(@NotNull InstallProgress

progress, @NotNull T reason, @NotNull S taskStatus) { super(false, progress); this.reason = reason; - this.phaseStatus = phaseStatus; + this.taskStatus = taskStatus; } public InstallFailedInstallResult(InstallProgress

progress, @NotNull T reason) { super(false, progress); this.reason = reason; - this.phaseStatus = null; + this.taskStatus = null; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 06e85772..c3f3740f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -3,8 +3,8 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectStatus; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectStatus; import org.apache.commons.io.FileUtils; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -19,13 +19,13 @@ import java.util.UUID; @Getter -public class InstallProgress

> +public class InstallProgress> { private static final HashMap> PROGRESS_CACHES; private static final Path CACHE_DIRECTORY; @Setter - private P phase; + private T currentTask; private final List upgraded; private final List installed; @@ -64,7 +64,7 @@ private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable this.removed = new ArrayList<>(); this.pending = new ArrayList<>(); - this.phase = null; + this.currentTask = null; if (id == null) this.installActionID = UUID.randomUUID().toString().substring(0, 8); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java index 3e843f2f..61999c99 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java @@ -2,9 +2,9 @@ public enum InstallErrorCause { - // Phases - PHASE_EXCEPTION_OCCURRED, - PHASE_FAILED, + // Tasks + TASK_EXCEPTION_OCCURRED, + TASK_FAILED, // Environment errors PLUGIN_IGNORED, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallTasks.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallTasks.java index c793beca..2392906b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallPhases.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallTasks.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; -public enum InstallPhases +public enum InstallTasks { STARTED, INITIALIZING, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java index 4783816c..38aa6f3d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java @@ -5,20 +5,20 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.DependsComputeOrderResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.PluginsInstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; @@ -31,7 +31,7 @@ import java.nio.file.Path; import java.util.List; -public class PluginInstaller extends AbstractInstaller +public class PluginInstaller extends AbstractInstaller { public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOException { @@ -40,21 +40,21 @@ public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOE @Override @SuppressWarnings("rawtypes") - public InstallResult execute(@NotNull String query) + public InstallResult execute(@NotNull String query) { Path pluginFilePath; PluginDescriptionFile pluginDescription; String pluginName; // region Do plugin resolve, download and description load. - PhaseResult pluginDescriptionResult = - this.submitter(InstallPhases.RESOLVING_QUERY, new PluginResolvePhase(progress, signalHandler)) - .then(InstallPhases.DOWNLOADING, new DownloadPhase(progress, signalHandler)) - .then(InstallPhases.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadPhase(progress, signalHandler)) + TaskResult pluginDescriptionResult = + this.submitter(InstallTasks.RESOLVING_QUERY, new PluginResolveTask(progress, signalHandler)) + .then(InstallTasks.DOWNLOADING, new DownloadTask(progress, signalHandler)) + .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(progress, signalHandler)) .submit(new PluginResolveArgument(query)); if (!pluginDescriptionResult.isSuccess()) - return handlePhaseError(pluginDescriptionResult); + return handleTaskError(pluginDescriptionResult); DescriptionLoadResult descriptionLoadResult = (DescriptionLoadResult) pluginDescriptionResult; @@ -68,7 +68,7 @@ public InstallResult execute(@NotNull String query) boolean replacePlugin = false; // region Do assertions. - this.progress.setPhase(InstallPhases.CHECKING_ENVIRONMENT); + this.progress.setCurrentTask(InstallTasks.CHECKING_ENVIRONMENT); // region Check if plugin is ignored. if (this.isPluginIgnored(pluginName)) @@ -111,26 +111,26 @@ public InstallResult execute(@NotNull String query) List dependenciesLoadOrder; // region Do collect dependencies, compute dependencies load order and install them. - PhaseResult dependsComputeOrderResult = - this.submitter(InstallPhases.COLLECTING_DEPENDENCIES, new DependsCollectPhase(progress, signalHandler)) - .then(InstallPhases.COMPUTING_LOAD_ORDER, new DependsComputeOrderPhase(progress, signalHandler)) + TaskResult dependsComputeOrderResult = + this.submitter(InstallTasks.COLLECTING_DEPENDENCIES, new DependsCollectTask(progress, signalHandler)) + .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(progress, signalHandler)) .submit(new DependsCollectArgument(pluginDescription)); if (!dependsComputeOrderResult.isSuccess()) - return handlePhaseError(dependsComputeOrderResult); + return handleTaskError(dependsComputeOrderResult); dependenciesLoadOrder = ((DependsComputeOrderResult) dependsComputeOrderResult).getOrder(); // endregion // region Install plugins. - PhaseResult pluginsInstallResult = - this.submitter(InstallPhases.INSTALLING_PLUGINS, new PluginsInstallPhase(progress, signalHandler)) + TaskResult pluginsInstallResult = + this.submitter(InstallTasks.INSTALLING_PLUGINS, new PluginsInstallTask(progress, signalHandler)) .submit(new PluginsInstallArgument( pluginFilePath, pluginDescription, dependenciesLoadOrder)); if (!pluginsInstallResult.isSuccess()) - return handlePhaseError(pluginDescriptionResult); + return handleTaskError(pluginDescriptionResult); // endregion if (replacePlugin) @@ -143,7 +143,7 @@ public InstallResult execute(@NotNull String query) private void removeOldPlugin(Plugin plugin) { - this.progress.setPhase(InstallPhases.REMOVING_OLD_PLUGIN); + this.progress.setCurrentTask(InstallTasks.REMOVING_OLD_PLUGIN); File oldPluginFile = PluginUtil.getFile(plugin); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java deleted file mode 100644 index af3f1821..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/GeneralPhaseErrorCause.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; - -public enum GeneralPhaseErrorCause -{ - // General internal errors - ILLEGAL_INTERNAL_STATE, - IO_EXCEPTION_OCCURRED, -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java deleted file mode 100644 index 483e577f..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseArgument.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; - -import lombok.Getter; - -public abstract class PhaseArgument -{ - @Getter - private final boolean chain; - - public PhaseArgument(PhaseResult previousPhaseResult) - { - this.chain = true; - if (!previousPhaseResult.isSuccess()) - throw new IllegalStateException("Previous must be successful"); - - } - - public PhaseArgument() - { - this.chain = false; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java deleted file mode 100644 index ef2e1ff3..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseSubmitter.java +++ /dev/null @@ -1,134 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; - -import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.ParameterizedType; - -public class PhaseSubmitter< - T extends PhaseArgument, - P extends Enum

, - I extends AbstractInstaller, - A extends PhaseArgument, - R extends PhaseResult, - E extends InstallPhase> -{ - @NotNull - private final I installer; - @NotNull - private final E phase; - @NotNull - private final P phaseState; - - @NotNull - private final PhaseSubmitter first; - @Nullable - private PhaseSubmitter next; - - public PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E phase) - { - this(phaseState, installer, phase, null, null); - } - - private PhaseSubmitter(@NotNull P phaseState, @NotNull I installer, @NotNull E phase, - @Nullable PhaseSubmitter first, @Nullable PhaseSubmitter next) - { - this.installer = installer; - this.phase = phase; - this.phaseState = phaseState; - - this.next = next; - - if (first == null) - this.first = this; - else - this.first = first; - } - - public , PE extends InstallPhase> - @NotNull PhaseSubmitter then(@NotNull P phaseState, @NotNull PE phase) - { - PhaseSubmitter submitter = new PhaseSubmitter<>(phaseState, installer, phase, this.first, null); - this.next = submitter; - - return submitter; - } - - public @NotNull R submitOnce(@NotNull A argument) - { - return this.phase.runPhase(argument); - } - - @SuppressWarnings("unchecked") - protected @NotNull R submitOnceUnsafe(@NotNull PA argument) - { - return this.phase.runPhase((A) argument); - } - - @SuppressWarnings("unchecked") - private static > Class getPhaseArgumentOf(@NotNull T phase) - { - return (Class) ((ParameterizedType) phase.getClass().getGenericSuperclass()) - .getActualTypeArguments()[0]; - } - - @SuppressWarnings("unchecked") - private static Constructor getConstructor(@NotNull Class clazz, - @NotNull PhaseResult parentResult) - { - - try - { - for (Constructor constructor : clazz.getConstructors()) - { - Class[] parameterTypes = constructor.getParameterTypes(); - if (parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(parentResult.getClass())) - { - constructor.setAccessible(true); - return (Constructor) constructor; - } - } - } - catch (Exception e) - { - e.printStackTrace(); - throw new RuntimeException(e); - } - - throw new IllegalArgumentException("No constructor found for " + clazz.getName()); - } - - public @NotNull PhaseResult submit(@NotNull T firstArgument) - { - PhaseSubmitter submitter = this.first; - - installer.getProgress().setPhase(phaseState); - PhaseResult result = submitter.submitOnceUnsafe(firstArgument); - - try - { - while (submitter.next != null) - { - if (!result.isSuccess()) - return result; - - submitter = submitter.next; - - installer.getProgress().setPhase(submitter.phaseState); - PhaseArgument nextArgument = getConstructor(getPhaseArgumentOf(submitter.phase), result).newInstance(result); - - result = submitter.submitOnceUnsafe(nextArgument); - - } - } - catch (InstantiationException | IllegalAccessException | InvocationTargetException e) - { - e.printStackTrace(); - } - - return result; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectErrorCause.java deleted file mode 100644 index 54485e08..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectErrorCause.java +++ /dev/null @@ -1,6 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; - -public enum DependsCollectErrorCause -{ - SOME_DEPENDENCIES_COLLECT_FAILED, -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java deleted file mode 100644 index 3177e654..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderArgument.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.DependsCollectResult; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -@AllArgsConstructor -public class DependsComputeOrderArgument extends PhaseArgument -{ - @Getter - private final List collectedDependencies; - - public DependsComputeOrderArgument(@NotNull DependsCollectResult previousPhaseResult) - { - super(previousPhaseResult); - - this.collectedDependencies = previousPhaseResult.getCollectedPlugins(); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java deleted file mode 100644 index e9d5a6da..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderErrorCause.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; - -public enum DependsComputeOrderErrorCause -{ -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java deleted file mode 100644 index 8bb85720..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadArgument.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; - -import lombok.EqualsAndHashCode; -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; -import org.jetbrains.annotations.NotNull; - -import java.nio.file.Path; - -@Value -@EqualsAndHashCode(callSuper = false) -public class DescriptionLoadArgument extends PhaseArgument -{ - @NotNull - Path pluginFile; - - public DescriptionLoadArgument(@NotNull Path pluginFile) - { - this.pluginFile = pluginFile; - } - - public DescriptionLoadArgument(DownloadResult previousPhaseResult) - { - super(previousPhaseResult); - - if (previousPhaseResult.getPath() == null) - throw new IllegalArgumentException("DownloadResult.path is null"); - - this.pluginFile = previousPhaseResult.getPath(); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java new file mode 100644 index 00000000..b55b90bf --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java @@ -0,0 +1,8 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; + +public enum GeneralTaskErrorCause +{ + // General internal errors + ILLEGAL_INTERNAL_STATE, + IO_EXCEPTION_OCCURRED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java similarity index 70% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java index ee796734..db093c37 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/InstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; import lombok.AllArgsConstructor; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; @@ -7,14 +7,14 @@ import org.jetbrains.annotations.NotNull; @AllArgsConstructor -public abstract class InstallPhase, ? extends Enum>> +public abstract class InstallTask, ? extends Enum>> { @NotNull protected final InstallProgress progress; @NotNull private final InstallerSignalHandler signalHandler; - public abstract @NotNull R runPhase(@NotNull A arguments); + public abstract @NotNull R runTask(@NotNull A arguments); public void postSignal(@NotNull InstallerSignal signal) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java new file mode 100644 index 00000000..7a3c716a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; + +import lombok.Getter; + +public abstract class TaskArgument +{ + @Getter + private final boolean chain; + + public TaskArgument(TaskResult previousTaskResult) + { + this.chain = true; + if (!previousTaskResult.isSuccess()) + throw new IllegalStateException("Previous must be successful"); + + } + + public TaskArgument() + { + this.chain = false; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java similarity index 61% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java index 2d4df0a5..3d687c84 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/PhaseResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; import lombok.AllArgsConstructor; import lombok.Getter; @@ -7,11 +7,11 @@ @AllArgsConstructor @Getter -public abstract class PhaseResult, C extends Enum> +public abstract class TaskResult, C extends Enum> { private final boolean success; @NotNull - private final R phase; + private final R task; @Nullable private final C errorCause; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java new file mode 100644 index 00000000..1921de3d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java @@ -0,0 +1,134 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; + +import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.ParameterizedType; + +public class TaskSubmitter< + T extends TaskArgument, + TS extends Enum, + I extends AbstractInstaller, + A extends TaskArgument, + R extends TaskResult, + E extends InstallTask> +{ + @NotNull + private final I installer; + @NotNull + private final E task; + @NotNull + private final TS taskState; + + @NotNull + private final TaskSubmitter first; + @Nullable + private TaskSubmitter next; + + public TaskSubmitter(@NotNull TS taskState, @NotNull I installer, @NotNull E task) + { + this(taskState, installer, task, null, null); + } + + private TaskSubmitter(@NotNull TS taskState, @NotNull I installer, @NotNull E task, + @Nullable TaskSubmitter first, @Nullable TaskSubmitter next) + { + this.installer = installer; + this.task = task; + this.taskState = taskState; + + this.next = next; + + if (first == null) + this.first = this; + else + this.first = first; + } + + @SuppressWarnings("unchecked") + private static > Class getTaskArgumentOf(@NotNull T task) + { + return (Class) ((ParameterizedType) task.getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; + } + + @SuppressWarnings("unchecked") + private static Constructor getConstructor(@NotNull Class clazz, + @NotNull TaskResult parentResult) + { + + try + { + for (Constructor constructor : clazz.getConstructors()) + { + Class[] parameterTypes = constructor.getParameterTypes(); + if (parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(parentResult.getClass())) + { + constructor.setAccessible(true); + return (Constructor) constructor; + } + } + } + catch (Exception e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + + throw new IllegalArgumentException("No constructor found for " + clazz.getName()); + } + + public , TE extends InstallTask> + @NotNull TaskSubmitter then(@NotNull TS taskState, @NotNull TE task) + { + TaskSubmitter submitter = new TaskSubmitter<>(taskState, installer, task, this.first, null); + this.next = submitter; + + return submitter; + } + + public @NotNull R submitOnce(@NotNull A argument) + { + return this.task.runTask(argument); + } + + @SuppressWarnings("unchecked") + protected @NotNull R submitOnceUnsafe(@NotNull PA argument) + { + return this.task.runTask((A) argument); + } + + public @NotNull TaskResult submit(@NotNull T firstArgument) + { + TaskSubmitter submitter = this.first; + + installer.getProgress().setCurrentTask(taskState); + TaskResult result = submitter.submitOnceUnsafe(firstArgument); + + try + { + while (submitter.next != null) + { + if (!result.isSuccess()) + return result; + + submitter = submitter.next; + + installer.getProgress().setCurrentTask(submitter.taskState); + TaskArgument nextArgument = getConstructor(getTaskArgumentOf(submitter.task), result).newInstance(result); + + result = submitter.submitOnceUnsafe(nextArgument); + + } + } + catch (InstantiationException | IllegalAccessException | InvocationTargetException e) + { + e.printStackTrace(); + } + + return result; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java similarity index 90% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java index f2035ca1..1f252e7c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/DependencyElement.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies; import com.google.gson.annotations.Expose; import lombok.AllArgsConstructor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectArgument.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java index 87430e30..d2a00f9e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.DescriptionLoadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadResult; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -14,7 +14,7 @@ @Value @EqualsAndHashCode(callSuper = false) -public class DependsCollectArgument extends PhaseArgument +public class DependsCollectArgument extends TaskArgument { @NotNull PluginDescriptionFile pluginDescription; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java new file mode 100644 index 00000000..048bf5c0 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java @@ -0,0 +1,6 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; + +public enum DependsCollectErrorCause +{ + SOME_DEPENDENCIES_COLLECT_FAILED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java similarity index 68% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java index c26b4056..325f3c90 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,7 +11,7 @@ @Value @EqualsAndHashCode(callSuper = true) -public class DependsCollectResult extends PhaseResult +public class DependsCollectResult extends TaskResult { @NotNull String targetPlugin; @@ -22,12 +22,12 @@ public class DependsCollectResult extends PhaseResult collectFailedPlugins; - public DependsCollectResult(boolean success, @NotNull DependsCollectState phase, + public DependsCollectResult(boolean success, @NotNull DependsCollectState taskState, @Nullable DependsCollectErrorCause errorCause, @NotNull String targetPlugin, @NotNull List collectedPlugins, @NotNull List collectFailedPlugins) { - super(success, phase, errorCause); + super(success, taskState, errorCause); this.targetPlugin = targetPlugin; this.collectedPlugins = collectedPlugins; this.collectFailedPlugins = collectFailedPlugins; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectState.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java index db565881..e89c0ba0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; public enum DependsCollectState { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectStatus.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index 097fb442..cae4754f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -7,7 +7,7 @@ import lombok.Data; import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java similarity index 75% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index de0a2d5a..09522cd5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/DependsCollectPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -1,22 +1,22 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyDownloadFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyNameMismatchSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependencyResolveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsCollectFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals.DependsEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolvePhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyDownloadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsCollectFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; @@ -33,25 +33,25 @@ import java.util.Objects; import java.util.stream.Collectors; -public class DependsCollectPhase extends InstallPhase +public class DependsCollectTask extends InstallTask { // TODO: きれいに private final InstallerSignalHandler signalHandler; private final DependsCollectStatus status; - private DependsCollectState phaseState; + private DependsCollectState taskState; - public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + public DependsCollectTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); this.signalHandler = signalHandler; this.status = progress.getDependsCollectStatus(); - this.phaseState = DependsCollectState.INITIALIZED; + this.taskState = DependsCollectState.INITIALIZED; } @Override - public @NotNull DependsCollectResult runPhase(@NotNull DependsCollectArgument arguments) + public @NotNull DependsCollectResult runTask(@NotNull DependsCollectArgument arguments) { PluginDescriptionFile pluginDescription = arguments.getPluginDescription(); this.status.setPluginName(pluginDescription.getName()); @@ -69,7 +69,7 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal HashMap resolvedResults; // region Resolve dependencies - this.phaseState = DependsCollectState.RESOLVING_DEPENDS; + this.taskState = DependsCollectState.RESOLVING_DEPENDS; resolvedResults = this.resolveDepends(dependsSignal.getDependencies(), arguments.getAlreadyInstalledPlugins()); resolvedResults.entrySet().removeIf(entry -> !(entry.getValue() instanceof SuccessResult)); // Remove failures @@ -77,14 +77,14 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal HashMap downloadResults; // region Download dependencies - this.phaseState = DependsCollectState.DOWNLOADING_DEPENDS; + this.taskState = DependsCollectState.DOWNLOADING_DEPENDS; downloadResults = this.downloadDepends(resolvedResults); downloadResults.entrySet().removeIf(entry -> !entry.getValue().isSuccess()); // Remove failures // endregion // region Collect dependency's dependencies (Recursive via collectDependsDepends) - this.phaseState = DependsCollectState.COLLECTING_DEPENDS_DEPENDS; + this.taskState = DependsCollectState.COLLECTING_DEPENDS_DEPENDS; HashMap dependsDescriptions = downloadResultsToPluginDescriptionFiles(downloadResults); @@ -128,7 +128,7 @@ public DependsCollectPhase(@NotNull InstallProgress progress, @NotNull Instal this.postSignal(new DependsCollectFailedSignal(collectFailedDependencies)); return new DependsCollectResult( - success, this.phaseState, errorCause, + success, this.taskState, errorCause, pluginName, this.status.getCollectedDependencies(), collectFailedDependencies ); } @@ -138,8 +138,8 @@ private DependsCollectResult passCollector(@NotNull PluginDescriptionFile plugin { DependsCollectArgument arguments = new DependsCollectArgument(pluginDescription, alreadyCollectedPlugins); - return new DependsCollectPhase(this.progress, this.signalHandler) // do new() because DependsCollectPhase is stateful. - .runPhase(arguments); + return new DependsCollectTask(this.progress, this.signalHandler) // do new() because DependsCollectTask is stateful. + .runTask(arguments); } private void collectDependsDepends(@NotNull HashMap dependsDescriptions, @@ -203,8 +203,8 @@ private DownloadResult passDownloader(@NotNull String url) { DownloadArgument argument = new DownloadArgument(url); - return new DownloadPhase(this.progress, this.signalHandler) - .runPhase(argument); + return new DownloadTask(this.progress, this.signalHandler) + .runTask(argument); } private HashMap downloadDepends(@NotNull HashMap resolvedPlugins) @@ -226,8 +226,8 @@ private PluginResolveResult passResolver(@NotNull String dependency) { PluginResolveArgument resolveArgument = new PluginResolveArgument(dependency); - return new PluginResolvePhase(this.progress, this.signalHandler) - .runPhase(resolveArgument); + return new PluginResolveTask(this.progress, this.signalHandler) + .runTask(resolveArgument); } private HashMap resolveDepends(@NotNull List dependencies, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java index 94d67f89..752e25a7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectFailedSignalBase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java similarity index 73% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectFailedSignalBase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java index 78028f63..9585f6b1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyCollectFailedSignalBase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyDownloadFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java index 72c5b88e..2f471b8a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyDownloadFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; public class DependencyDownloadFailedSignal extends DependencyCollectFailedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java similarity index 67% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java index a40d8ef3..1e8145d0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; public class DependencyLoadDescriptionFailedSignal extends DependencyCollectFailedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyNameMismatchSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyNameMismatchSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java index e8ee3d56..dd569022 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyNameMismatchSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; public class DependencyNameMismatchSignal extends DependencyCollectFailedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyResolveFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java index e3a6d384..2369b411 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependencyResolveFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; public class DependencyResolveFailedSignal extends DependencyCollectFailedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCacheSaveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCacheSaveFailedSignal.java similarity index 58% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCacheSaveFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCacheSaveFailedSignal.java index 192f719f..ed5c0176 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCacheSaveFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCacheSaveFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCollectFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java similarity index 69% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCollectFailedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java index 2d6ba324..82f800bd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsCollectFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsEnumeratedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsEnumeratedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java index a87f5be2..032120f5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/collector/signals/DependsEnumeratedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java new file mode 100644 index 00000000..76c216c2 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java @@ -0,0 +1,24 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectResult; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@AllArgsConstructor +public class DependsComputeOrderArgument extends TaskArgument +{ + @Getter + private final List collectedDependencies; + + public DependsComputeOrderArgument(@NotNull DependsCollectResult previousTaskResult) + { + super(previousTaskResult); + + this.collectedDependencies = previousTaskResult.getCollectedPlugins(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java new file mode 100644 index 00000000..836e5217 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; + +public enum DependsComputeOrderErrorCause +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java similarity index 50% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java index 29afbbf5..bd9b6f99 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java @@ -1,24 +1,24 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class DependsComputeOrderResult extends PhaseResult +public class DependsComputeOrderResult extends TaskResult { @Getter @NotNull private final List order; - public DependsComputeOrderResult(boolean success, @NotNull DependsComputeOrderState phase, + public DependsComputeOrderResult(boolean success, @NotNull DependsComputeOrderState taskState, @Nullable DependsComputeOrderErrorCause errorCause, @NotNull List order) { - super(success, phase, errorCause); + super(success, taskState, errorCause); this.order = order; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java similarity index 56% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderState.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java index a75c8c8a..51472993 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; public enum DependsComputeOrderState { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index 0d3bbfaf..8eb5cda4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/DependsComputeOrderPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependsLoadOrderComputedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals.DependsLoadOrderComputingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -21,11 +21,11 @@ /** * This class is inspired by the class {@link org.bukkit.plugin.SimplePluginManager#loadPlugins(File, List)} */ -public class DependsComputeOrderPhase extends InstallPhase +public class DependsComputeOrderTask extends InstallTask { private DependsComputeOrderState state; - public DependsComputeOrderPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + public DependsComputeOrderTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); @@ -50,7 +50,7 @@ private static boolean isInstalled(String name) } @Override - public @NotNull DependsComputeOrderResult runPhase(@NotNull DependsComputeOrderArgument arguments) + public @NotNull DependsComputeOrderResult runTask(@NotNull DependsComputeOrderArgument arguments) { this.state = DependsComputeOrderState.CREATING_DEPENDENCY_MAP; this.postSignal(new DependsLoadOrderComputingSignal( diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputedSignal.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputedSignal.java index 3efe8894..1673e4fe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java index c0ef6bdc..983bd4bd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/dependencies/computer/signals/DependsLoadOrderComputingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.computer.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java new file mode 100644 index 00000000..2dc51700 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java @@ -0,0 +1,32 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +@Value +@EqualsAndHashCode(callSuper = false) +public class DescriptionLoadArgument extends TaskArgument +{ + @NotNull + Path pluginFile; + + public DescriptionLoadArgument(@NotNull Path pluginFile) + { + this.pluginFile = pluginFile; + } + + public DescriptionLoadArgument(DownloadResult previousTaskResult) + { + super(previousTaskResult); + + if (previousTaskResult.getPath() == null) + throw new IllegalArgumentException("DownloadResult.path is null"); + + this.pluginFile = previousTaskResult.getPath(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java similarity index 54% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java index 02b5c165..7c21f986 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; public enum DescriptionLoadErrorCause diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java index 181acabd..fdc0cca8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,18 +9,18 @@ import java.nio.file.Path; @Getter -public class DescriptionLoadResult extends PhaseResult +public class DescriptionLoadResult extends TaskResult { @NotNull private final Path pluginFile; @Nullable private final PluginDescriptionFile description; - public DescriptionLoadResult(boolean success, @NotNull DescriptionLoadState phase, + public DescriptionLoadResult(boolean success, @NotNull DescriptionLoadState taskState, @Nullable DescriptionLoadErrorCause errorCause, @NotNull Path pluginFile, @Nullable PluginDescriptionFile description) { - super(success, phase, errorCause); + super(success, taskState, errorCause); this.pluginFile = pluginFile; this.description = description; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java similarity index 50% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java index 7f25f7f6..c8abb31a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; public enum DescriptionLoadState diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java similarity index 56% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java index 1f6dbef3..064e61ce 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/DescriptionLoadPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.signals.LoadPluginDescriptionSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; @@ -12,18 +12,18 @@ import java.io.IOException; import java.nio.file.Path; -public class DescriptionLoadPhase extends InstallPhase +public class DescriptionLoadTask extends InstallTask { - private DescriptionLoadState phaseState; + private DescriptionLoadState taskState; - public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + public DescriptionLoadTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); - this.phaseState = DescriptionLoadState.INITIALIZED; + this.taskState = DescriptionLoadState.INITIALIZED; } @Override - public @NotNull DescriptionLoadResult runPhase(@NotNull DescriptionLoadArgument arguments) + public @NotNull DescriptionLoadResult runTask(@NotNull DescriptionLoadArgument arguments) { Path pluginFile = arguments.getPluginFile(); @@ -33,19 +33,19 @@ public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull Insta try { - this.phaseState = DescriptionLoadState.LOADING_PLUGIN_DESCRIPTION; + this.taskState = DescriptionLoadState.LOADING_PLUGIN_DESCRIPTION; pluginYml = PluginUtil.loadDescription(arguments.getPluginFile().toFile()); } catch (InvalidDescriptionException e) { if (e.getMessage().equals("This file isn't plugin.")) - return new DescriptionLoadResult(false, this.phaseState, + return new DescriptionLoadResult(false, this.taskState, DescriptionLoadErrorCause.NOT_A_PLUGIN, pluginFile, null ); else { e.printStackTrace(); - return new DescriptionLoadResult(false, this.phaseState, + return new DescriptionLoadResult(false, this.taskState, DescriptionLoadErrorCause.INVALID_DESCRIPTION, pluginFile, null ); } @@ -53,11 +53,11 @@ public DescriptionLoadPhase(@NotNull InstallProgress progress, @NotNull Insta catch (IOException e) { e.printStackTrace(); - return new DescriptionLoadResult(false, this.phaseState, + return new DescriptionLoadResult(false, this.taskState, DescriptionLoadErrorCause.IO_EXCEPTION, pluginFile, null ); } - return new DescriptionLoadResult(true, this.phaseState, null, pluginFile, pluginYml); + return new DescriptionLoadResult(true, this.taskState, null, pluginFile, pluginYml); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/signals/LoadPluginDescriptionSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/signals/LoadPluginDescriptionSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java index 008b017b..3b711b15 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/description/signals/LoadPluginDescriptionSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.description.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.signals; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java similarity index 74% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java index 1d65c097..de1aeed2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.PluginResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,7 +11,7 @@ @Value @EqualsAndHashCode(callSuper = false) -public class DownloadArgument extends PhaseArgument +public class DownloadArgument extends TaskArgument { @NotNull String url; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java index 780d035e..dffe331e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; public enum DownloadErrorCause diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java similarity index 61% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java index 8bd02268..5347a6c5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/DownloadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.nio.file.Path; @Getter -public class DownloadResult extends PhaseResult +public class DownloadResult extends TaskResult { @Nullable private final Path path; @@ -17,18 +17,18 @@ public class DownloadResult extends PhaseResult +public class DownloadTask extends InstallTask { private final String randomDownloadID; - private DownloadState phaseState; + private DownloadState taskState; - public DownloadPhase(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + public DownloadTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); this.randomDownloadID = UUID.randomUUID().toString(); - this.phaseState = DownloadState.INITIALIZED; + this.taskState = DownloadState.INITIALIZED; } private void onDownload(DownloadProgress downloadProgress) { - this.phaseState = DownloadState.DOWNLOADING; + this.taskState = DownloadState.DOWNLOADING; this.postSignal(new DownloadProgressSignal( this.randomDownloadID, @@ -44,7 +44,7 @@ private void onDownload(DownloadProgress downloadProgress) } @Override - public @NotNull DownloadResult runPhase(@NotNull DownloadArgument arguments) + public @NotNull DownloadResult runTask(@NotNull DownloadArgument arguments) { Path downloadPath = arguments.getPath(); if (downloadPath == null) @@ -56,7 +56,7 @@ private void onDownload(DownloadProgress downloadProgress) arguments.getUrl() ); - this.phaseState = DownloadState.START_DOWNLOADING; + this.taskState = DownloadState.START_DOWNLOADING; this.postSignal(downloadingSignal); // SignalHandler can change the download URL and download path. Path path = downloadingSignal.getDownloadPath(); @@ -68,7 +68,7 @@ private void onDownload(DownloadProgress downloadProgress) this.postSignal(new DownloadSucceedSignal(this.randomDownloadID, path, size)); - return new DownloadResult(true, this.phaseState, path, size, this.randomDownloadID); + return new DownloadResult(true, this.taskState, path, size, this.randomDownloadID); } catch (IOException e) { @@ -94,13 +94,13 @@ else if (e.getMessage().startsWith("No response body was returned")) DownloadErrorSignal error = new DownloadErrorSignal(cause, this.randomDownloadID, signalValue); this.postSignal(error); - return new DownloadResult(false, this.phaseState, path, -1, this.randomDownloadID, cause); + return new DownloadResult(false, this.taskState, path, -1, this.randomDownloadID, cause); } catch (Exception e) { this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, this.randomDownloadID, e)); - return new DownloadResult(false, this.phaseState, path, -1, this.randomDownloadID, + return new DownloadResult(false, this.taskState, path, -1, this.randomDownloadID, DownloadErrorCause.UNKNOWN_ERROR ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java index 272bb054..377371db 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.DownloadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadErrorCause; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadProgressSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java index a49fd475..7348f66d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadProgressSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadStartingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadStartingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java index 58a5ddf7..fb7f42fa 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadStartingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadSucceedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadSucceedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java index b18a372a..e2bec4b5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/download/signals/DownloadSucceedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.download.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java similarity index 54% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallArgument.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java index 370372e8..569188c1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -12,7 +12,7 @@ @Value @EqualsAndHashCode(callSuper = false) -public class PluginsInstallArgument extends PhaseArgument +public class PluginsInstallArgument extends TaskArgument { @NotNull Path pluginPath; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java similarity index 66% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallErrorCause.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java index 57661bbe..c8fa8b79 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; public enum PluginsInstallErrorCause { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java similarity index 52% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java index b814f585..abb711c4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java @@ -1,25 +1,25 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class PluginsInstallResult extends PhaseResult +public class PluginsInstallResult extends TaskResult { @Getter @Nullable private final String failedPluginName; - public PluginsInstallResult(boolean success, @NotNull PluginsInstallState phase, @Nullable PluginsInstallErrorCause errorCause) + public PluginsInstallResult(boolean success, @NotNull PluginsInstallState taskState, @Nullable PluginsInstallErrorCause errorCause) { - this(success, phase, errorCause, null); + this(success, taskState, errorCause, null); } - public PluginsInstallResult(boolean success, @NotNull PluginsInstallState phase, + public PluginsInstallResult(boolean success, @NotNull PluginsInstallState taskState, @Nullable PluginsInstallErrorCause errorCause, @Nullable String failedPluginName) { - super(success, phase, errorCause); + super(success, taskState, errorCause); this.failedPluginName = failedPluginName; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java similarity index 63% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallState.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java index ef719874..a83e9a6d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; public enum PluginsInstallState { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index cc27080f..b8f5d756 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/PluginsInstallPhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginLoadedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginOnEnableRunningSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginOnLoadRunningSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginLoadedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnEnableRunningSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.plugin.InvalidDescriptionException; @@ -27,7 +27,7 @@ import java.nio.file.StandardCopyOption; import java.util.List; -public class PluginsInstallPhase extends InstallPhase +public class PluginsInstallTask extends InstallTask { private static final Path PLUGIN_DIR; @@ -38,7 +38,7 @@ public class PluginsInstallPhase extends InstallPhase progress, @NotNull InstallerSignalHandler signalHandler) + public PluginsInstallTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); @@ -46,7 +46,7 @@ public PluginsInstallPhase(@NotNull InstallProgress progress, @NotNull Instal } @Override - public @NotNull PluginsInstallResult runPhase(@NotNull PluginsInstallArgument arguments) + public @NotNull PluginsInstallResult runTask(@NotNull PluginsInstallArgument arguments) { List dependencies = arguments.getDependencies(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginLoadedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadedSignal.java similarity index 75% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginLoadedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadedSignal.java index 01674977..760ef781 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginLoadedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnEnableRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java similarity index 76% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnEnableRunningSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java index 74a3e4b4..5f689888 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnEnableRunningSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnLoadRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java similarity index 75% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnLoadRunningSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java index 9f1febd0..c7eb3005 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginOnLoadRunningSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginRelocatingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginRelocatingSignal.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginRelocatingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginRelocatingSignal.java index 91bd4e2f..310130b8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/install/signals/PluginRelocatingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginRelocatingSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.install.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveArgument.java similarity index 55% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveArgument.java index 392979fd..69f55369 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveArgument.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; @Data @EqualsAndHashCode(callSuper = false) -public class PluginResolveArgument extends PhaseArgument +public class PluginResolveArgument extends TaskArgument { @NotNull String query; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java similarity index 52% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java index 1c661cdf..7b995a48 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; public enum PluginResolveErrorCause diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java similarity index 59% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java index 266ca275..fff78416 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java @@ -1,27 +1,27 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.PhaseResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class PluginResolveResult extends PhaseResult +public class PluginResolveResult extends TaskResult { @Getter @Nullable private final SuccessResult resolveResult; - public PluginResolveResult(boolean success, @NotNull PluginResolveState phase, + public PluginResolveResult(boolean success, @NotNull PluginResolveState taskState, @NotNull PluginResolveErrorCause errorCause, @Nullable SuccessResult resolveResult) { - super(success, phase, errorCause); + super(success, taskState, errorCause); this.resolveResult = resolveResult; } - public PluginResolveResult(boolean success, @NotNull PluginResolveState phase, @NotNull SuccessResult resolveResult) + public PluginResolveResult(boolean success, @NotNull PluginResolveState taskState, @NotNull SuccessResult resolveResult) { - super(success, phase, null); + super(success, taskState, null); this.resolveResult = resolveResult; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveState.java similarity index 63% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveState.java index 15f43f90..588c1d1f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolveState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; public enum PluginResolveState { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java index 3d2de359..47daa27e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/PluginResolvePhase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.InstallPhase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals.MultiplePluginResolvedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals.PluginResolveErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals.PluginResolvingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolvingSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class PluginResolvePhase extends InstallPhase +public class PluginResolveTask extends InstallTask { private static final PluginResolver PLUGIN_RESOLVER; @@ -24,13 +24,13 @@ public class PluginResolvePhase extends InstallPhase progress, @NotNull InstallerSignalHandler signalHandler) + public PluginResolveTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) { super(progress, signalHandler); - this.phaseState = PluginResolveState.INITIALIZED; + this.taskState = PluginResolveState.INITIALIZED; } private @Nullable ResolveResult resolveMultipleResults(@NotNull String query, @NotNull MultiResult results) @@ -56,27 +56,27 @@ public PluginResolvePhase(@NotNull InstallProgress progress, @NotNull Install } @Override - public @NotNull PluginResolveResult runPhase(@NotNull PluginResolveArgument arguments) + public @NotNull PluginResolveResult runTask(@NotNull PluginResolveArgument arguments) { String query = arguments.getQuery(); - this.phaseState = PluginResolveState.PRE_RESOLVING; + this.taskState = PluginResolveState.PRE_RESOLVING; this.postSignal(new PluginResolvingSignal(query, PLUGIN_RESOLVER)); ResolveResult queryResolveResult = PLUGIN_RESOLVER.resolve(query); - this.phaseState = PluginResolveState.PRE_RESOLVE_FINISHED; + this.taskState = PluginResolveState.PRE_RESOLVE_FINISHED; if (queryResolveResult instanceof ErrorResult) { this.postSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); - return new PluginResolveResult(false, this.phaseState, + return new PluginResolveResult(false, this.taskState, PluginResolveErrorCause.GOT_ERROR_RESULT, null ); } else if (queryResolveResult instanceof MultiResult) { - this.phaseState = PluginResolveState.MULTI_RESOLVING; + this.taskState = PluginResolveState.MULTI_RESOLVING; MultiResult multiResult = (MultiResult) queryResolveResult; ResolveResult actualResolveResult = resolveMultipleResults(arguments.getQuery(), multiResult); @@ -85,7 +85,7 @@ else if (queryResolveResult instanceof MultiResult) { // MultiResult has been resolved, but the actual result is an error this.postSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); - return new PluginResolveResult(false, this.phaseState, PluginResolveErrorCause.GOT_ERROR_RESULT, null); + return new PluginResolveResult(false, this.taskState, PluginResolveErrorCause.GOT_ERROR_RESULT, null); } // MultiResult has been resolved, and the actual result is a SuccessResult @@ -94,11 +94,11 @@ else if (queryResolveResult instanceof MultiResult) queryResolveResult = actualResolveResult; } - this.phaseState = PluginResolveState.RESOLVE_FINISHED; + this.taskState = PluginResolveState.RESOLVE_FINISHED; if (!(queryResolveResult instanceof SuccessResult)) - return new PluginResolveResult(false, this.phaseState, PluginResolveErrorCause.ILLEGAL_INTERNAL_STATE, null); + return new PluginResolveResult(false, this.taskState, PluginResolveErrorCause.ILLEGAL_INTERNAL_STATE, null); - return new PluginResolveResult(true, this.phaseState, (SuccessResult) queryResolveResult); + return new PluginResolveResult(true, this.taskState, (SuccessResult) queryResolveResult); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/MultiplePluginResolvedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/MultiplePluginResolvedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java index 4621ab50..d1db511a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/MultiplePluginResolvedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolveErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolveErrorSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java index 6abff8b5..c5d38317 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolveErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals; import lombok.Data; import lombok.NonNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvedSuccessfulSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvedSuccessfulSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java index c2d2d11e..eabf1a5f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvedSuccessfulSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvingSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java index 81cb1727..7ef46aa1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/phase/phases/resolve/signals/PluginResolvingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.phase.phases.resolve.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals; import lombok.AllArgsConstructor; import lombok.Data; From 17c6c2415d419494fc6c73a918bd2837e809fa43 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:03:49 +0900 Subject: [PATCH 206/745] refactor: installer => installers --- .../commands/debug/CommandInstallDebug.java | 6 +++--- .../commands/debug/DebugSignalHandler.java | 2 +- .../installer/{ => impls}/install/InstallErrorCause.java | 2 +- .../plugin/installer/{ => impls}/install/InstallTasks.java | 2 +- .../installer/{ => impls}/install/PluginInstaller.java | 4 ++-- .../install/signals/AlreadyInstalledPluginSignal.java | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{ => impls}/install/InstallErrorCause.java (74%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{ => impls}/install/InstallTasks.java (77%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{ => impls}/install/PluginInstaller.java (97%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/{ => impls}/install/signals/AlreadyInstalledPluginSignal.java (89%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java index 616b02c1..793fe7bb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java @@ -5,9 +5,9 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.InstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.InstallTasks; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.PluginInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallTasks; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index ed211016..097d284f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -7,7 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; import org.apache.commons.lang.ArrayUtils; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java similarity index 74% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java index 61999c99..308ffd23 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; public enum InstallErrorCause { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallTasks.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallTasks.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java index 2392906b..f0f583f0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/InstallTasks.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; public enum InstallTasks { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java similarity index 97% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index 38aa6f3d..35f646c8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/AlreadyInstalledPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/AlreadyInstalledPluginSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java index 8ac66120..bedb5dd7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/install/signals/AlreadyInstalledPluginSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.install.signals; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; From d1c705b0381426b30a1d8d6b1614db2e0a4e52f1 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 15 Aug 2022 17:01:58 +0900 Subject: [PATCH 207/745] refactor: Change generics signature --- .../lab/teamkunpluginmanager/plugin/AbstractInstaller.java | 4 ++-- .../plugin/installer/task/TaskResult.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index f48e7d3e..b6fa9542 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -59,9 +59,9 @@ public , S extends Enum> InstallFailedInstallResult handleTaskError(@NotNull TaskResult result) { if (result.getErrorCause() != null) - return this.error(result.getErrorCause(), result.getTask()); + return this.error(result.getErrorCause(), result.getState()); else - return this.error(GeneralTaskErrorCause.ILLEGAL_INTERNAL_STATE, result.getTask()); + return this.error(GeneralTaskErrorCause.ILLEGAL_INTERNAL_STATE, result.getState()); } @NotNull diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java index 3d687c84..4547690b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java @@ -7,12 +7,12 @@ @AllArgsConstructor @Getter -public abstract class TaskResult, C extends Enum> +public abstract class TaskResult, EC extends Enum> { private final boolean success; @NotNull - private final R task; + private final S state; @Nullable - private final C errorCause; + private final EC errorCause; } From 5dc7217f945cf0e61fa414a9f8b5266f65306a6a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 17 Aug 2022 14:12:46 +0900 Subject: [PATCH 208/745] revert: "fix: Reverted error detecting process" revert: ed9d768ff30ef957b71439217d649699decdef0a --- .../task/tasks/dependencies/collector/DependsCollectStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index cae4754f..1821228a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -52,7 +52,7 @@ public boolean isCollected(@NotNull String dependencyName) public boolean isErrors() { - return !enumeratedDependencies.containsValue(null); + return enumeratedDependencies.containsValue(null); } public void onCollect(@NotNull String dependencyName, DependencyElement dependencyElement) From 6e231f82609beb2f053a1804aca93c0a00ad7262 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Wed, 17 Aug 2022 15:41:14 +0900 Subject: [PATCH 209/745] refactor: Refactor spaghetti code of TaskSubmitter. --- .../plugin/AbstractInstaller.java | 6 +- .../impls/install/PluginInstaller.java | 22 ++- .../plugin/installer/task/TaskSubmitter.java | 134 ------------------ .../collector/DependsCollectTask.java | 2 +- 4 files changed, 23 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index b6fa9542..2e163ba4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -10,8 +10,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.GeneralTaskErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskChain; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskSubmitter; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -66,10 +66,10 @@ protected InstallResult

handleTaskError(@NotNull TaskResult result) @NotNull protected , TT extends InstallTask> - TaskSubmitter, A, R, TT> + TaskChain submitter(@NotNull P taskState, @NotNull TT task) { - return new TaskSubmitter<>(taskState, this, task); + return new TaskChain<>(task, taskState, this); } protected boolean isPluginIgnored(@NotNull String pluginName) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index 35f646c8..7e676120 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -10,10 +10,13 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallTask; @@ -50,8 +53,20 @@ public InstallResult execute(@NotNull String query) TaskResult pluginDescriptionResult = this.submitter(InstallTasks.RESOLVING_QUERY, new PluginResolveTask(progress, signalHandler)) .then(InstallTasks.DOWNLOADING, new DownloadTask(progress, signalHandler)) + .bridgeArgument(result -> { + if (result.getResolveResult() == null) + throw new IllegalArgumentException("Plugin Resolving must be successful"); + + return new DownloadArgument(result.getResolveResult().getDownloadUrl()); + }) .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(progress, signalHandler)) - .submit(new PluginResolveArgument(query)); + .bridgeArgument(result -> { + if (result.getPath() == null) + throw new IllegalArgumentException("Plugin Description Loading must be successful"); + + return new DescriptionLoadArgument(result.getPath()); + }) + .submitAll(new PluginResolveArgument(query)); if (!pluginDescriptionResult.isSuccess()) return handleTaskError(pluginDescriptionResult); @@ -114,7 +129,8 @@ public InstallResult execute(@NotNull String query) TaskResult dependsComputeOrderResult = this.submitter(InstallTasks.COLLECTING_DEPENDENCIES, new DependsCollectTask(progress, signalHandler)) .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(progress, signalHandler)) - .submit(new DependsCollectArgument(pluginDescription)); + .bridgeArgument(result -> new DependsComputeOrderArgument(result.getCollectedPlugins())) + .submitAll(new DependsCollectArgument(pluginDescription)); if (!dependsComputeOrderResult.isSuccess()) return handleTaskError(dependsComputeOrderResult); @@ -126,7 +142,7 @@ public InstallResult execute(@NotNull String query) TaskResult pluginsInstallResult = this.submitter(InstallTasks.INSTALLING_PLUGINS, new PluginsInstallTask(progress, signalHandler)) - .submit(new PluginsInstallArgument( + .submitAll(new PluginsInstallArgument( pluginFilePath, pluginDescription, dependenciesLoadOrder)); if (!pluginsInstallResult.isSuccess()) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java deleted file mode 100644 index 1921de3d..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskSubmitter.java +++ /dev/null @@ -1,134 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; - -import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.ParameterizedType; - -public class TaskSubmitter< - T extends TaskArgument, - TS extends Enum, - I extends AbstractInstaller, - A extends TaskArgument, - R extends TaskResult, - E extends InstallTask> -{ - @NotNull - private final I installer; - @NotNull - private final E task; - @NotNull - private final TS taskState; - - @NotNull - private final TaskSubmitter first; - @Nullable - private TaskSubmitter next; - - public TaskSubmitter(@NotNull TS taskState, @NotNull I installer, @NotNull E task) - { - this(taskState, installer, task, null, null); - } - - private TaskSubmitter(@NotNull TS taskState, @NotNull I installer, @NotNull E task, - @Nullable TaskSubmitter first, @Nullable TaskSubmitter next) - { - this.installer = installer; - this.task = task; - this.taskState = taskState; - - this.next = next; - - if (first == null) - this.first = this; - else - this.first = first; - } - - @SuppressWarnings("unchecked") - private static > Class getTaskArgumentOf(@NotNull T task) - { - return (Class) ((ParameterizedType) task.getClass().getGenericSuperclass()) - .getActualTypeArguments()[0]; - } - - @SuppressWarnings("unchecked") - private static Constructor getConstructor(@NotNull Class clazz, - @NotNull TaskResult parentResult) - { - - try - { - for (Constructor constructor : clazz.getConstructors()) - { - Class[] parameterTypes = constructor.getParameterTypes(); - if (parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(parentResult.getClass())) - { - constructor.setAccessible(true); - return (Constructor) constructor; - } - } - } - catch (Exception e) - { - e.printStackTrace(); - throw new RuntimeException(e); - } - - throw new IllegalArgumentException("No constructor found for " + clazz.getName()); - } - - public , TE extends InstallTask> - @NotNull TaskSubmitter then(@NotNull TS taskState, @NotNull TE task) - { - TaskSubmitter submitter = new TaskSubmitter<>(taskState, installer, task, this.first, null); - this.next = submitter; - - return submitter; - } - - public @NotNull R submitOnce(@NotNull A argument) - { - return this.task.runTask(argument); - } - - @SuppressWarnings("unchecked") - protected @NotNull R submitOnceUnsafe(@NotNull PA argument) - { - return this.task.runTask((A) argument); - } - - public @NotNull TaskResult submit(@NotNull T firstArgument) - { - TaskSubmitter submitter = this.first; - - installer.getProgress().setCurrentTask(taskState); - TaskResult result = submitter.submitOnceUnsafe(firstArgument); - - try - { - while (submitter.next != null) - { - if (!result.isSuccess()) - return result; - - submitter = submitter.next; - - installer.getProgress().setCurrentTask(submitter.taskState); - TaskArgument nextArgument = getConstructor(getTaskArgumentOf(submitter.task), result).newInstance(result); - - result = submitter.submitOnceUnsafe(nextArgument); - - } - } - catch (InstantiationException | IllegalAccessException | InvocationTargetException e) - { - e.printStackTrace(); - } - - return result; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 09522cd5..1c4892db 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -120,7 +120,7 @@ public DependsCollectTask(@NotNull InstallProgress progress, @NotNull Install // endregion - boolean success = this.status.isErrors(); + boolean success = !this.status.isErrors(); DependsCollectErrorCause errorCause = success ? null: DependsCollectErrorCause.SOME_DEPENDENCIES_COLLECT_FAILED; List collectFailedDependencies = this.status.getCollectFailedDependencies(); From 5e220536de341feedca13dc9011d7a02d2c6e1a1 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:53:55 +0900 Subject: [PATCH 210/745] feat: PluginInstallingSignal and some Pre, Post signals. --- .../tasks/install/PluginsInstallState.java | 8 ++-- .../tasks/install/PluginsInstallTask.java | 25 +++++++----- ...ignal.java => PluginInstallingSignal.java} | 10 +++-- .../install/signals/PluginLoadSignal.java | 40 +++++++++++++++++++ .../signals/PluginOnEnableRunningSignal.java | 22 ++++++++-- .../signals/PluginOnLoadRunningSignal.java | 22 ++++++++-- 6 files changed, 104 insertions(+), 23 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/{PluginLoadedSignal.java => PluginInstallingSignal.java} (54%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java index a83e9a6d..30e2d1e3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java @@ -4,8 +4,8 @@ public enum PluginsInstallState { INITIALIZED, - RELOCATING_PLUGIN, - LOADING_PLUGIN, - RUNNING_ONLOAD, - RUNNING_ONENABLE, + PLUGIN_RELOCATING, + PLUGIN_LOADING, + ONLOAD_RUNNING, + PLUGIN_ENABLING, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index b8f5d756..1ba3cdf5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -5,7 +5,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginLoadedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginInstallingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginLoadSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnEnableRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; @@ -72,8 +73,9 @@ public PluginsInstallTask(@NotNull InstallProgress progress, @NotNull Install @Nullable private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription) { - this.state = PluginsInstallState.RELOCATING_PLUGIN; + this.postSignal(new PluginInstallingSignal(path, pluginDescription)); + this.state = PluginsInstallState.PLUGIN_RELOCATING; // Relocate plugin String fileName = pluginDescription.getName() + "-" + pluginDescription.getVersion() + ".jar"; @@ -84,21 +86,23 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr if (mayError != null) return mayError; - // Load plugin - this.state = PluginsInstallState.LOADING_PLUGIN; - Plugin target; try { + // Load plugin + this.state = PluginsInstallState.PLUGIN_LOADING; + this.postSignal(new PluginLoadSignal.Pre(path, pluginDescription)); target = Bukkit.getPluginManager().loadPlugin(targetPath.toFile()); assert target != null; - this.postSignal(new PluginLoadedSignal(target)); + this.postSignal(new PluginLoadSignal.Post(path, pluginDescription, target)); this.progress.addInstalled(target.getDescription()); - this.postSignal(new PluginOnLoadRunningSignal(target)); - this.state = PluginsInstallState.RUNNING_ONLOAD; + // Run Plugin#onLoad + this.state = PluginsInstallState.ONLOAD_RUNNING; + this.postSignal(new PluginOnLoadRunningSignal.Pre(target)); target.onLoad(); + this.postSignal(new PluginOnLoadRunningSignal.Post(target)); } catch (InvalidDescriptionException e) @@ -118,9 +122,10 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr } // Enable plugin - this.state = PluginsInstallState.RUNNING_ONENABLE; - this.postSignal(new PluginOnEnableRunningSignal(target)); + this.state = PluginsInstallState.PLUGIN_ENABLING; + this.postSignal(new PluginOnEnableRunningSignal.Pre(target)); Bukkit.getPluginManager().enablePlugin(target); + this.postSignal(new PluginOnEnableRunningSignal.Post(target)); return null; // Success } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginInstallingSignal.java similarity index 54% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadedSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginInstallingSignal.java index 760ef781..2c18a952 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginInstallingSignal.java @@ -2,12 +2,16 @@ import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +import java.nio.file.Path; + @Value -public class PluginLoadedSignal implements InstallerSignal +public class PluginInstallingSignal implements InstallerSignal { @NotNull - Plugin plugin; + Path path; + @NotNull + PluginDescriptionFile pluginDescription; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java new file mode 100644 index 00000000..e303ba88 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java @@ -0,0 +1,40 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals; + +import lombok.Data; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +@Data +public class PluginLoadSignal implements InstallerSignal +{ + @NotNull + private final Path pluginPath; + @NotNull + private final PluginDescriptionFile pluginDescription; + + public static class Pre extends PluginLoadSignal + { + public Pre(@NotNull Path pluginPath, @NotNull PluginDescriptionFile pluginDescription) + { + super(pluginPath, pluginDescription); + } + } + + public static class Post extends PluginLoadSignal + { + @NotNull + @Getter + private final Plugin plugin; + + public Post(@NotNull Path pluginPath, @NotNull PluginDescriptionFile pluginDescription, @NotNull Plugin plugin) + { + super(pluginPath, pluginDescription); + this.plugin = plugin; + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java index 5f689888..24d59883 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java @@ -1,13 +1,29 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals; -import lombok.Value; +import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -@Value +@Data public class PluginOnEnableRunningSignal implements InstallerSignal { @NotNull - Plugin plugin; + private final Plugin plugin; + + public static class Pre extends PluginOnEnableRunningSignal + { + public Pre(@NotNull Plugin plugin) + { + super(plugin); + } + } + + public static class Post extends PluginOnEnableRunningSignal + { + public Post(@NotNull Plugin plugin) + { + super(plugin); + } + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java index c7eb3005..d7591754 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java @@ -1,13 +1,29 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals; -import lombok.Value; +import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -@Value +@Data public class PluginOnLoadRunningSignal implements InstallerSignal { @NotNull - Plugin plugin; + private final Plugin plugin; + + public static class Pre extends PluginOnLoadRunningSignal + { + public Pre(@NotNull Plugin plugin) + { + super(plugin); + } + } + + public static class Post extends PluginOnLoadRunningSignal + { + public Post(@NotNull Plugin plugin) + { + super(plugin); + } + } } From a7450446d7f436516eff07ccda5583f8ed0b1c71 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:59:57 +0900 Subject: [PATCH 211/745] refactor: Make PluginManager as static final --- .../installer/task/tasks/install/PluginsInstallTask.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index 1ba3cdf5..88c9016e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -16,6 +16,7 @@ import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,10 +32,12 @@ public class PluginsInstallTask extends InstallTask { private static final Path PLUGIN_DIR; + private static final PluginManager PLUGIN_MANAGER; static { PLUGIN_DIR = TeamKunPluginManager.getPlugin().getDataFolder().toPath().getParent(); + PLUGIN_MANAGER = Bukkit.getPluginManager(); } private PluginsInstallState state; @@ -92,7 +95,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr // Load plugin this.state = PluginsInstallState.PLUGIN_LOADING; this.postSignal(new PluginLoadSignal.Pre(path, pluginDescription)); - target = Bukkit.getPluginManager().loadPlugin(targetPath.toFile()); + target = PLUGIN_MANAGER.loadPlugin(targetPath.toFile()); assert target != null; this.postSignal(new PluginLoadSignal.Post(path, pluginDescription, target)); @@ -124,7 +127,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr // Enable plugin this.state = PluginsInstallState.PLUGIN_ENABLING; this.postSignal(new PluginOnEnableRunningSignal.Pre(target)); - Bukkit.getPluginManager().enablePlugin(target); + PLUGIN_MANAGER.enablePlugin(target); this.postSignal(new PluginOnEnableRunningSignal.Post(target)); return null; // Success From dbb7c20495b8a243f923f2b75e6462dc3074ddc6 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:36:53 +0900 Subject: [PATCH 212/745] feat: Patch command after installation --- .../tasks/install/PluginsInstallTask.java | 59 ++++++++++++++----- .../plugin/loader/CommandsPatcher.java | 10 +++- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index 88c9016e..db1c7ed3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; @@ -10,8 +11,10 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnEnableRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; +import org.bukkit.entity.Player; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.Plugin; @@ -27,17 +30,20 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; import java.util.List; public class PluginsInstallTask extends InstallTask { private static final Path PLUGIN_DIR; private static final PluginManager PLUGIN_MANAGER; + private static final CommandsPatcher COMMANDS_PATCHER; static { PLUGIN_DIR = TeamKunPluginManager.getPlugin().getDataFolder().toPath().getParent(); PLUGIN_MANAGER = Bukkit.getPluginManager(); + COMMANDS_PATCHER = new CommandsPatcher(); } private PluginsInstallState state; @@ -49,32 +55,53 @@ public PluginsInstallTask(@NotNull InstallProgress progress, @NotNull Install this.state = PluginsInstallState.INITIALIZED; } + private static void patchPluginCommands(List targets) + { + targets.forEach(plugin -> COMMANDS_PATCHER.patchCommand(plugin, false)); + + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + } + @Override public @NotNull PluginsInstallResult runTask(@NotNull PluginsInstallArgument arguments) { List dependencies = arguments.getDependencies(); - // Install dependencies - for (DependencyElement dependency : dependencies) - { - PluginDescriptionFile pluginDescription = dependency.getPluginDescription(); - Path path = dependency.getPluginPath(); + List installedPlugins = new ArrayList<>(); - PluginsInstallResult result = this.installOne(path, pluginDescription); - if (result != null) + // For commands patch + try + { + // Install dependencies + for (DependencyElement dependency : dependencies) + { + PluginDescriptionFile pluginDescription = dependency.getPluginDescription(); + Path path = dependency.getPluginPath(); + + PluginsInstallResult result = this.installOne(path, pluginDescription, installedPlugins); + if (result != null) // installOne returns null if installation is failed + return result; + } + + // Install plugin after dependencies installed + PluginsInstallResult result = + this.installOne(arguments.getPluginPath(), arguments.getPluginDescription(), installedPlugins); + if (result != null) // installOne returns null if installation is failed return result; + else + return new PluginsInstallResult(true, this.state, null); + } + finally + { + Runner.runLater(() -> { + patchPluginCommands(installedPlugins); + }, 1L); } - - // Install plugin after dependencies installed - PluginsInstallResult result = this.installOne(arguments.getPluginPath(), arguments.getPluginDescription()); - if (result != null) - return result; - else - return new PluginsInstallResult(true, this.state, null); } @Nullable - private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription) + private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription, + @NotNull List installedPlugins) { this.postSignal(new PluginInstallingSignal(path, pluginDescription)); @@ -130,6 +157,8 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr PLUGIN_MANAGER.enablePlugin(target); this.postSignal(new PluginOnEnableRunningSignal.Post(target)); + installedPlugins.add(target); + return null; // Success } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java index b3a862d1..03d31f3c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java @@ -201,7 +201,7 @@ public void unWrapCommand(String command) iBrigadierCommandDispatcher.getRoot().removeCommand(command); } - public void patchCommand(@NotNull Plugin plugin) + public void patchCommand(@NotNull Plugin plugin, boolean updatePlayer) { Map commandMap = this.getKnownCommands(); @@ -215,7 +215,13 @@ public void patchCommand(@NotNull Plugin plugin) this.syncCommandsCraftBukkit(); - Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + if (updatePlayer) + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + } + + public void patchCommand(@NotNull Plugin plugin) + { + this.patchCommand(plugin, true); } public void unPatchCommand(@NotNull Plugin plugin) From 035f7975c889b216b2bfc47eaf8ab67089882656 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:45:53 +0900 Subject: [PATCH 213/745] refactor: PluginOnEnableRunningSignal => PluginEnablingSignal --- .../installer/task/tasks/install/PluginsInstallTask.java | 6 +++--- ...OnEnableRunningSignal.java => PluginEnablingSignal.java} | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/{PluginOnEnableRunningSignal.java => PluginEnablingSignal.java} (72%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index db1c7ed3..eb3e4cba 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -6,9 +6,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginEnablingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginInstallingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginLoadSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnEnableRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; @@ -153,9 +153,9 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr // Enable plugin this.state = PluginsInstallState.PLUGIN_ENABLING; - this.postSignal(new PluginOnEnableRunningSignal.Pre(target)); + this.postSignal(new PluginEnablingSignal.Pre(target)); PLUGIN_MANAGER.enablePlugin(target); - this.postSignal(new PluginOnEnableRunningSignal.Post(target)); + this.postSignal(new PluginEnablingSignal.Post(target)); installedPlugins.add(target); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginEnablingSignal.java similarity index 72% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginEnablingSignal.java index 24d59883..e69a889b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnEnableRunningSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginEnablingSignal.java @@ -6,12 +6,12 @@ import org.jetbrains.annotations.NotNull; @Data -public class PluginOnEnableRunningSignal implements InstallerSignal +public class PluginEnablingSignal implements InstallerSignal { @NotNull private final Plugin plugin; - public static class Pre extends PluginOnEnableRunningSignal + public static class Pre extends PluginEnablingSignal { public Pre(@NotNull Plugin plugin) { @@ -19,7 +19,7 @@ public Pre(@NotNull Plugin plugin) } } - public static class Post extends PluginOnEnableRunningSignal + public static class Post extends PluginEnablingSignal { public Post(@NotNull Plugin plugin) { From b745c8b2794b1347ad5aef017047e37359af490e Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:47:48 +0900 Subject: [PATCH 214/745] feat: Uninstaller --- .../commands/CommandDebug.java | 2 + .../commands/debug/CommandUninstallDebug.java | 89 +++++++ .../impls/uninstall/PluginUninstaller.java | 169 +++++++++++++ .../impls/uninstall/UnInstallErrorCause.java | 8 + .../impls/uninstall/UnInstallTasks.java | 10 + .../signals/PluginIsDependencySignal.java | 30 +++ .../signals/SearchingPluginSignal.java | 12 + .../plugin/installer/task/TaskChain.java | 112 +++++++++ .../tasks/uninstall/UnInstallArgument.java | 15 ++ .../tasks/uninstall/UnInstallErrorCause.java | 11 + .../task/tasks/uninstall/UnInstallResult.java | 27 +++ .../task/tasks/uninstall/UnInstallState.java | 14 ++ .../task/tasks/uninstall/UnInstallTask.java | 223 ++++++++++++++++++ .../signals/PluginDisablingSignal.java | 29 +++ .../signals/PluginRegisteredRecipeSignal.java | 54 +++++ .../signals/PluginUnloadingSignal.java | 26 ++ .../plugin/loader/CommandsPatcher.java | 10 +- .../utils/ReversedCollector.java | 53 +++++ 18 files changed, 892 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java index d2294fb9..e7d618b1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java @@ -3,6 +3,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandInstallDebug; +import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandUninstallDebug; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -19,6 +20,7 @@ public class CommandDebug extends SubCommandWith { COMMANDS = new HashMap<>(); COMMANDS.put("installDebug", new CommandInstallDebug()); + COMMANDS.put("uninstallDebug", new CommandUninstallDebug()); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java new file mode 100644 index 00000000..1528ce90 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java @@ -0,0 +1,89 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.debug; + +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class CommandUninstallDebug extends CommandBase +{ + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 1)) + return; + + String query = args[0]; + + Runner.runAsync(() -> { + try + { + PluginUninstaller installer = new PluginUninstaller(new DebugSignalHandler(terminal)); + + InstallResult installResult = installer.execute(query); + + if (installResult instanceof InstallFailedInstallResult) + { + InstallFailedInstallResult failedInstallResult = + (InstallFailedInstallResult) installResult; + + terminal.error("Uninstall has failed for " + + failedInstallResult.getReason() + " in " + failedInstallResult.getProgress() + " of " + + failedInstallResult.getTaskStatus()); + } + + terminal.success("Uninstall succeed: "); + terminal.info("Installed: " + Arrays.toString(installResult.getInstalled())); + terminal.info("Pending: " + Arrays.toString(installResult.getPending())); + terminal.info("Removed: " + Arrays.toString(installResult.getRemoved())); + terminal.info("Upgraded: " + Arrays.toString(installResult.getUpgraded())); + } + catch (Exception e) + { + e.printStackTrace(); + terminal.error(e.getClass() + ": " + e.getMessage()); + } + }); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName).collect(Collectors.toList()); + } + + @Override + public @Nullable String getPermission() + { + return "kpm.debug.uninstall"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("アンインストールのデバッグコマンドです。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("pluginName", "PluginName") + }; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java new file mode 100644 index 00000000..de81cd08 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -0,0 +1,169 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; + +import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.SearchingPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallTask; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.utils.ReversedCollector; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class PluginUninstaller extends AbstractInstaller +{ + public PluginUninstaller(InstallerSignalHandler signalHandler) throws IOException + { + super(signalHandler); + } + + @Override + public InstallResult execute(@NotNull String query) + { + List plugins = new ArrayList<>(); + // region Search plugin + this.progress.setCurrentTask(UnInstallTasks.SEARCHING_PLUGIN); + + Plugin plugin = this.getPlugin(query); + if (plugin == null) + return this.error(UnInstallErrorCause.PLUGIN_NOT_FOUND); + + plugins.add(plugin); + + + // endregion + + // region Do assertions. + this.progress.setCurrentTask(UnInstallTasks.CHECKING_ENVIRONMENT); + + // region Check is plugin marked as ignored + if (this.isPluginIgnored(plugin.getName())) + { + IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(plugin.getDescription()); + this.postSignal(ignoredPluginSignal); + if (ignoredPluginSignal.isCancelInstall()) + return this.error(UnInstallErrorCause.PLUGIN_IGNORED); + } + + // endregion + + // region Check plugin are depended by other plugins + + List dependencies = this.getAllDependencies(plugin); + + if (!dependencies.isEmpty()) + { + PluginIsDependencySignal pluginIsDependencySignal = + new PluginIsDependencySignal(plugin.getName(), dependencies); + + this.postSignal(pluginIsDependencySignal); + + if (pluginIsDependencySignal.isForceUninstall()) + plugins.addAll(dependencies); + else + return this.error(UnInstallErrorCause.PLUGIN_IS_DEPENDENCY); + } + + // endregion + + // endregion + + // region Uninstall plugin + + // Before uninstall plugin, we need to compute the order of plugins to uninstall. + // Reuse DepenedsComputeOrderTask to compute the order, so we need to map List to List. + List computeOrderTarget = plugins.stream().parallel() + .map(pl -> { + PluginDescriptionFile descriptionFile = pl.getDescription(); + String name = descriptionFile.getName(); + Path path = PluginUtil.getFile(pl).toPath(); + + return new DependencyElement(name, path, descriptionFile); + }) + .collect(Collectors.toList()); + + // Create String-Plugin map to DependencyElement doesn't have Plugin instance. + Map namePluginMap = plugins.stream().parallel() + .collect(Collectors.toMap(Plugin::getName, pl -> pl)); + + UnInstallResult uninstallResult = (UnInstallResult) + this.submitter( + UnInstallTasks.COMPUTING_UNINSTALL_ORDER, + new DependsComputeOrderTask(this.progress, this.signalHandler) + ) + .then( + UnInstallTasks.UNINSTALLING_PLUGINS, + new UnInstallTask(this.progress, this.signalHandler) + ) + .bridgeArgument(computeResult -> { + List ordered = computeResult.getOrder(); + List orderedPlugins = ordered.stream() + .map(element -> namePluginMap.get(element.getPluginName())) + .collect(ReversedCollector.toList()); // Convert load order to unload order. + + return new UnInstallArgument(orderedPlugins); + }) + .submitAll(new DependsComputeOrderArgument(computeOrderTarget)); + + if (!uninstallResult.isSuccess()) + return this.handleTaskError(uninstallResult); + + // endregion + + return this.success(); + } + + private Plugin getPlugin(String query) + { + SearchingPluginSignal searchingPluginSignal = new SearchingPluginSignal(query); + this.postSignal(searchingPluginSignal); + query = searchingPluginSignal.getQuery(); // May be changed by signal handler + + Plugin plugin = Bukkit.getPluginManager().getPlugin(query); + + if (!PluginUtil.isPluginLoaded(plugin)) + return null; + + return plugin; + } + + private ArrayList getAllDependencies(Plugin target) + { + ArrayList plugins = new ArrayList<>(); + + DependencyTree.Info info = DependencyTree.getInfo(target.getName(), false); + if (info == null) + return new ArrayList<>(); + + for (DependencyTree.Info.Depend depend : info.rdepends) + { + Plugin dependPlugin = this.getPlugin(depend.depend); + if (dependPlugin != null) + { + plugins.add(dependPlugin); + plugins.addAll(this.getAllDependencies(dependPlugin)); + } + // if depend plugin not found, ignore it because it only exist in database. + // Doesn't exist in filesystem and server plugins. + } + + return plugins; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java new file mode 100644 index 00000000..d94e329e --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java @@ -0,0 +1,8 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; + +public enum UnInstallErrorCause +{ + PLUGIN_NOT_FOUND, + PLUGIN_IGNORED, + PLUGIN_IS_DEPENDENCY, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java new file mode 100644 index 00000000..11cd1f28 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; + +public enum UnInstallTasks +{ + SEARCHING_PLUGIN, + CHECKING_ENVIRONMENT, + + COMPUTING_UNINSTALL_ORDER, + UNINSTALLING_PLUGINS, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java new file mode 100644 index 00000000..790d414c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java @@ -0,0 +1,30 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@Data +public class PluginIsDependencySignal implements InstallerSignal +{ + @NotNull + private final String pluginName; + @NotNull + private final List dependedBy; + + /** + * Force uninstall plugin. + * If this turn to true, it will uninstall the plugin and all its dependencies. + */ + private boolean forceUninstall; + + public PluginIsDependencySignal(@NotNull String pluginName, @NotNull List dependedBy) + { + this.pluginName = pluginName; + this.dependedBy = dependedBy; + this.forceUninstall = false; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java new file mode 100644 index 00000000..0649b824 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +@Data +public class SearchingPluginSignal implements InstallerSignal +{ + @NotNull + private String query; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java new file mode 100644 index 00000000..88e85157 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java @@ -0,0 +1,112 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; + +import lombok.AccessLevel; +import lombok.Setter; +import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Function; + +public class TaskChain< + TA extends TaskArgument, + IS extends Enum, + R extends TaskResult, + PR extends TaskResult, + T extends InstallTask> +{ + @NotNull + private final T task; + + @NotNull + private final IS installerState; + + @NotNull + private final AbstractInstaller installer; + + @Nullable + @Setter(AccessLevel.NONE) + private TaskChain first; + + @Setter(AccessLevel.PACKAGE) + private TaskChain next; + + @Nullable + private Function argumentBuilder; + + public TaskChain(@NotNull T task, @NotNull IS installerState, @Nullable TaskChain first, + @NotNull AbstractInstaller installer) + { + this.task = task; + this.installerState = installerState; + this.first = first; + this.installer = installer; + } + + public TaskChain(@NotNull T task, @NotNull IS installerState, @NotNull AbstractInstaller installer) + { + this(task, installerState, null, installer); + this.first = this; + } + + public > TaskChain then(@NotNull IS installerState, + @NotNull InstallTask nextTask) + { + TaskChain nextChain = new TaskChain<>(nextTask, installerState, this.first, this.installer); + this.next = nextChain; + return nextChain; + } + + public TaskChain bridgeArgument(@NotNull Function argumentBuilder) + { + this.argumentBuilder = argumentBuilder; + return this; + } + + public @NotNull TaskResult submitFromThis(@NotNull TaskArgument argument) + { + try + { + this.installer.getProgress().setCurrentTask(this.installerState); + R result = this.task.runTask((TA) argument); + + if (result.isSuccess() && this.next != null) + return this.next.submitFromThis(result); + else + return result; + } + catch (ClassCastException e) + { + throw new IllegalArgumentException("Failed to cast task argument", e); + } + } + + public @NotNull TaskResult submitFromThis(@NotNull TaskResult taskResult) + { + if (this.argumentBuilder == null) + throw new IllegalStateException("No argument builder defined to build argument from parent result"); + + try + { + this.installer.getProgress().setCurrentTask(this.installerState); + R result = this.task.runTask(this.argumentBuilder.apply((PR) taskResult)); + + if (result.isSuccess() && this.next != null) + return this.next.submitFromThis(result); + else + return result; + } + catch (ClassCastException e) + { + throw new IllegalArgumentException("Failed to cast task result", e); + } + } + + public @NotNull TaskResult submitAll(@NotNull TaskArgument argument) + { + if (this.first == null) + throw new IllegalStateException("No task chain defined"); + return this.first.submitFromThis(argument); + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java new file mode 100644 index 00000000..1d2a5a3d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import org.bukkit.plugin.Plugin; + +import java.util.List; + +@Value +@EqualsAndHashCode(callSuper = false) +public class UnInstallArgument extends TaskArgument +{ + List plugins; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java new file mode 100644 index 00000000..1cb1520a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java @@ -0,0 +1,11 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; + +public enum UnInstallErrorCause +{ + SOME_UNINSTALL_FAILED, + + INTERNAL_UNINSTALL_OK, + + INTERNAL_PLUGIN_DISABLE_FAILED, + INTERNAL_CLASS_UNLOAD_FAILED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java new file mode 100644 index 00000000..4735324e --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java @@ -0,0 +1,27 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; + +public class UnInstallResult extends TaskResult +{ + @Getter + @NotNull + private final List uninstalledPlugins; + @Getter + @NotNull + private final Map errors; + + public UnInstallResult(boolean success, @NotNull UnInstallState state, @Nullable UnInstallErrorCause errorCause, @NotNull List uninstalledPlugins, @NotNull Map errors) + { + super(success, state, errorCause); + this.uninstalledPlugins = uninstalledPlugins; + this.errors = errors; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java new file mode 100644 index 00000000..9b804fed --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java @@ -0,0 +1,14 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; + +public enum UnInstallState +{ + INITIALIZED, + UNINSTALLING, + + RECIPES_UNREGISTERING, + COMMANDS_UNPATCHING, + PLUGIN_DISABLING, + + REMOVING_FROM_BUKKIT, + CLASSES_UNLOADING +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java new file mode 100644 index 00000000..4b1f5132 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -0,0 +1,223 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; + +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; +import org.bukkit.Bukkit; +import org.bukkit.Keyed; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Recipe; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.SimplePluginManager; +import org.bukkit.plugin.java.PluginClassLoader; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class UnInstallTask extends InstallTask +{ + private static final PluginManager PLUGIN_MANAGER; + private static final CommandsPatcher COMMANDS_PATCHER; + + private static final List PLUGINS; // Lorg/bukkit/plugin/SimplePluginManager/plugins; + private static final Map LOOKUP_NAMES; // Lorg/bukkit/plugin/SimplePluginManager/lookupNames; + private static final Field F_PLUGIN; // Lorg/bukkit/plugin/JavaPlugin; + private static final Field F_PLUGIN_INIT; // Lorg/bukkit/plugin/JavaPlugin; + + static + { + PLUGIN_MANAGER = Bukkit.getPluginManager(); + COMMANDS_PATCHER = new CommandsPatcher(); + + try + { + Field fPlugins = SimplePluginManager.class.getDeclaredField("plugins"); + fPlugins.setAccessible(true); + //noinspection unchecked + PLUGINS = (List) fPlugins.get(PLUGIN_MANAGER); + + Field fLookupNames = SimplePluginManager.class.getDeclaredField("lookupNames"); + fLookupNames.setAccessible(true); + //noinspection unchecked + LOOKUP_NAMES = (Map) fLookupNames.get(PLUGIN_MANAGER); + + F_PLUGIN = PluginClassLoader.class.getDeclaredField("plugin"); + F_PLUGIN.setAccessible(true); + + F_PLUGIN_INIT = PluginClassLoader.class.getDeclaredField("pluginInit"); + F_PLUGIN_INIT.setAccessible(true); + } + catch (NoSuchFieldException | IllegalAccessException e) + { + throw new RuntimeException(e); + } + } + + private UnInstallState taskState; + + public UnInstallTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + { + super(progress, signalHandler); + + taskState = UnInstallState.INITIALIZED; + } + + @Override + public @NotNull UnInstallResult runTask(@NotNull UnInstallArgument arguments) + { + List orderedUninstallTargets = arguments.getPlugins(); + + List uninstalledPlugins = new ArrayList<>(); + Map errors = new HashMap<>(); + + this.taskState = UnInstallState.UNINSTALLING; + + for (Plugin plugin : orderedUninstallTargets) + { + PluginDescriptionFile description = plugin.getDescription(); + UnInstallErrorCause errorCause = uninstallOnePlugin(plugin); + if (errorCause == UnInstallErrorCause.INTERNAL_UNINSTALL_OK) + uninstalledPlugins.add(description); + else + errors.put(errorCause, description); + } + + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + + boolean success = errors.isEmpty(); + + return new UnInstallResult(success, taskState, success ? null: UnInstallErrorCause.SOME_UNINSTALL_FAILED, + uninstalledPlugins, errors + ); + } + + private UnInstallErrorCause uninstallOnePlugin(@NotNull Plugin plugin) + { + this.taskState = UnInstallState.RECIPES_UNREGISTERING; + this.unregisterRecipes(plugin); + + this.taskState = UnInstallState.COMMANDS_UNPATCHING; + COMMANDS_PATCHER.unPatchCommand(plugin, false); + + this.taskState = UnInstallState.PLUGIN_DISABLING; + try + { + this.postSignal(new PluginDisablingSignal.Pre(plugin)); + PLUGIN_MANAGER.disablePlugin(plugin); + this.postSignal(new PluginDisablingSignal.Post(plugin)); + } + catch (Exception ex) + { + ex.printStackTrace(); + return UnInstallErrorCause.INTERNAL_PLUGIN_DISABLE_FAILED; + } + + this.taskState = UnInstallState.REMOVING_FROM_BUKKIT; + PLUGINS.remove(plugin); + LOOKUP_NAMES.remove(plugin.getName()); + + this.taskState = UnInstallState.CLASSES_UNLOADING; + @SuppressWarnings("StringOperationCanBeSimplified") // Backup Plugin name to unload classes + String pluginName = new String(plugin.getName()); + + this.postSignal(new PluginUnloadingSignal.Pre(plugin)); + + if (!this.unloadClasses(plugin)) + return UnInstallErrorCause.INTERNAL_CLASS_UNLOAD_FAILED; + + this.postSignal(new PluginUnloadingSignal.Post(pluginName)); + + return UnInstallErrorCause.INTERNAL_UNINSTALL_OK; + } + + private boolean unloadClasses(@NotNull Plugin plugin) + { + ClassLoader classLoader = plugin.getClass().getClassLoader(); + + if (!(classLoader instanceof URLClassLoader)) + return false; + + URLClassLoader urlClassLoader = (URLClassLoader) classLoader; + + try + { + F_PLUGIN.set(classLoader, null); + F_PLUGIN_INIT.set(classLoader, null); + + urlClassLoader.close(); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + TeamKunPluginManager.getPlugin().getLogger().warning("Unable to unload classes of plugin " + plugin.getName()); + return false; + } + catch (IOException e) + { + e.printStackTrace(); + TeamKunPluginManager.getPlugin().getLogger().warning("Unable to close class loader of plugin " + + plugin.getName()); + return false; + } + + System.gc(); + + return true; + } + + private void unregisterRecipes(@NotNull Plugin plugin) + { + PluginRegisteredRecipeSignal.Searching signal = new PluginRegisteredRecipeSignal.Searching(plugin); + this.postSignal(signal); + String[] targetNamespaces = signal.getTargetNamespaces(); + + Iterator recipeIterator = Bukkit.recipeIterator(); + while (recipeIterator.hasNext()) + { + Recipe recipe = recipeIterator.next(); + + if (this.isRecipeRemoveTarget(plugin, targetNamespaces, recipe)) + recipeIterator.remove(); + } + } + + private boolean isRecipeRemoveTarget(@NotNull Plugin plugin, @NotNull String[] targetNamespaces, @NotNull Recipe recipe) + { + if (!(recipe instanceof Keyed)) + return false; + + NamespacedKey recipeKey = ((Keyed) recipe).getKey(); + String recipeNamespace = recipeKey.getNamespace(); + + String foundSignature = Arrays.stream(targetNamespaces).parallel() + .filter(recipeNamespace::equalsIgnoreCase) + .findFirst().orElse(null); + boolean isTargetRecipe = foundSignature != null; + + if (!isTargetRecipe) + return false; + + PluginRegisteredRecipeSignal.FoundOne foundOneSignal = + new PluginRegisteredRecipeSignal.FoundOne(plugin, foundSignature, recipe); + this.postSignal(foundOneSignal); + + return foundOneSignal.isDoUnregister(); + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java new file mode 100644 index 00000000..d0f3a7fe --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java @@ -0,0 +1,29 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +@Data +public class PluginDisablingSignal implements InstallerSignal +{ + @NotNull + private final Plugin plugin; + + public static class Pre extends PluginDisablingSignal + { + public Pre(@NotNull Plugin plugin) + { + super(plugin); + } + } + + public static class Post extends PluginDisablingSignal + { + public Post(@NotNull Plugin plugin) + { + super(plugin); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java new file mode 100644 index 00000000..bda197cb --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java @@ -0,0 +1,54 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.inventory.Recipe; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.util.Locale; + +@Data +public class PluginRegisteredRecipeSignal implements InstallerSignal +{ + @NotNull + private final Plugin plugin; + + @Getter + @Setter + public static class FoundOne extends PluginRegisteredRecipeSignal + { + @NotNull + private final String signatureNamespace; + @NotNull + private final Recipe recipe; + + private boolean doUnregister; + + public FoundOne(@NotNull Plugin plugin, @NotNull String signatureNamespace, @NotNull Recipe recipe) + { + super(plugin); + this.signatureNamespace = signatureNamespace; + this.recipe = recipe; + + this.doUnregister = true; + } + } + + @Getter + @Setter + public static class Searching extends PluginRegisteredRecipeSignal + { + @NotNull + private String[] targetNamespaces; + + public Searching(@NotNull Plugin plugin) + { + super(plugin); + + this.targetNamespaces = new String[]{plugin.getName().toLowerCase(Locale.ROOT)}; + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java new file mode 100644 index 00000000..7707b340 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java @@ -0,0 +1,26 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +public class PluginUnloadingSignal implements InstallerSignal +{ + @Value + @EqualsAndHashCode(callSuper = false) + public static class Pre extends PluginUnloadingSignal + { + @NotNull + Plugin plugin; + } + + @Value + @EqualsAndHashCode(callSuper = false) + public static class Post extends PluginUnloadingSignal + { + @NotNull + String pluginName; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java index 03d31f3c..97e02447 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java @@ -224,7 +224,7 @@ public void patchCommand(@NotNull Plugin plugin) this.patchCommand(plugin, true); } - public void unPatchCommand(@NotNull Plugin plugin) + public void unPatchCommand(@NotNull Plugin plugin, boolean updatePlayer) { Map commandMap = this.getKnownCommands(); @@ -261,6 +261,12 @@ public void unPatchCommand(@NotNull Plugin plugin) this.syncCommandsCraftBukkit(); - Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + if (updatePlayer) + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); + } + + public void unPatchCommand(@NotNull Plugin plugin) + { + this.unPatchCommand(plugin, true); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java new file mode 100644 index 00000000..f6000790 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java @@ -0,0 +1,53 @@ +package net.kunmc.lab.teamkunpluginmanager.utils; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; + +public class ReversedCollector implements Collector, List> +{ + public static ReversedCollector toList() + { + return new ReversedCollector<>(); + } + + @Override + public Supplier> supplier() + { + return ArrayList::new; + } + + @Override + public BiConsumer, T> accumulator() + { + return (list, t) -> list.add(0, t); + } + + @Override + public BinaryOperator> combiner() + { + return (list1, list2) -> + { + list1.addAll(0, list2); + return list1; + }; + } + + @Override + public Function, List> finisher() + { + return list -> list; + } + + @Override + public Set characteristics() + { + return EnumSet.of(Characteristics.CONCURRENT); + } +} From 539db9e0a33291cc8fce3ab89a2bf92aff1d5434 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:56:10 +0900 Subject: [PATCH 215/745] fix: Fix removing plugin --- .../task/tasks/uninstall/UnInstallTask.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 4b1f5132..61645e3d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -1,6 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; @@ -8,6 +10,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; @@ -20,6 +23,7 @@ import org.bukkit.plugin.java.PluginClassLoader; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.net.URLClassLoader; @@ -98,6 +102,22 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull InstallerSig errors.put(errorCause, description); } + Runner.runLaterAsync(() -> { + orderedUninstallTargets.forEach(plugin -> { + File pluginFile = PluginUtil.getFile(plugin); + if (pluginFile.exists()) + pluginFile.delete(); + + DependencyTree.wipePlugin(plugin); + }); + }, 20L); + + orderedUninstallTargets.stream() + .map(Plugin::getDescription) + .forEach(UnInstallTask.this.progress::addRemoved); + + System.gc(); + Bukkit.getOnlinePlayers().forEach(Player::updateCommands); boolean success = errors.isEmpty(); @@ -176,8 +196,6 @@ private boolean unloadClasses(@NotNull Plugin plugin) return false; } - System.gc(); - return true; } From 3ab5957bcef8ef73f27a52e613e9a4ee194bd875 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:10:37 +0900 Subject: [PATCH 216/745] style: Suppress warning of ResultOfMethodCallIgnored --- .../plugin/installer/task/tasks/uninstall/UnInstallTask.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 61645e3d..c43ba1c6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -83,6 +83,7 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull InstallerSig } @Override + @SuppressWarnings("ResultOfMethodCallIgnored") public @NotNull UnInstallResult runTask(@NotNull UnInstallArgument arguments) { List orderedUninstallTargets = arguments.getPlugins(); From f1b298cee8acd26538a7ec204286df91ba394848 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:29:51 +0900 Subject: [PATCH 217/745] refactor: DependsLoadOrderComputedSignal to Pre/Post --- .../computer/DependsComputeOrderTask.java | 9 +++------ .../signals/DependsLoadOrderComputedSignal.java | 15 --------------- .../DependsLoadOrderComputingSignal.java | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 21 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index 8eb5cda4..e088b9f4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -4,7 +4,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; @@ -53,9 +52,7 @@ private static boolean isInstalled(String name) public @NotNull DependsComputeOrderResult runTask(@NotNull DependsComputeOrderArgument arguments) { this.state = DependsComputeOrderState.CREATING_DEPENDENCY_MAP; - this.postSignal(new DependsLoadOrderComputingSignal( - Collections.unmodifiableList(arguments.getCollectedDependencies()) - )); + this.postSignal(new DependsLoadOrderComputingSignal.Pre(arguments.getCollectedDependencies())); List plugins = new ArrayList<>(arguments.getCollectedDependencies()); @@ -174,8 +171,8 @@ else if (!contains(dependency, plugins)) result.addAll(last); - DependsLoadOrderComputedSignal dependsLoadOrderComputedSignal = - new DependsLoadOrderComputedSignal(result); + DependsLoadOrderComputingSignal.Post dependsLoadOrderComputedSignal = + new DependsLoadOrderComputingSignal.Post(result); this.postSignal(dependsLoadOrderComputedSignal); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputedSignal.java deleted file mode 100644 index 1673e4fe..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputedSignal.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals; - -import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; - -@Data -public class DependsLoadOrderComputedSignal implements InstallerSignal -{ - @NotNull - private final ArrayList dependencies; -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java index 983bd4bd..9ad7bf15 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; @Data @@ -12,4 +13,20 @@ public class DependsLoadOrderComputingSignal implements InstallerSignal { @NotNull private final List dependencies; + + public static class Pre extends DependsLoadOrderComputingSignal + { + public Pre(final List dependencies) + { + super(Collections.unmodifiableList(dependencies)); + } + } + + public static class Post extends DependsLoadOrderComputingSignal + { + public Post(final List dependencies) + { + super(dependencies); + } + } } From 9d543e6d23c7bcab60aac6336bdbb09e16c567f8 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:36:57 +0900 Subject: [PATCH 218/745] refactor: DownloadSignal --- .../task/tasks/download/DownloadTask.java | 4 ++-- .../download/signals/DownloadErrorSignal.java | 14 ++++++++++---- .../signals/DownloadProgressSignal.java | 16 +++++++++++----- .../download/signals/DownloadSignal.java | 12 ++++++++++++ .../signals/DownloadStartingSignal.java | 19 ++++++++++++------- .../signals/DownloadSucceedSignal.java | 15 ++++++++++----- 6 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java index b8ad765c..141b2124 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java @@ -91,14 +91,14 @@ else if (e.getMessage().startsWith("No response body was returned")) signalValue = e; } - DownloadErrorSignal error = new DownloadErrorSignal(cause, this.randomDownloadID, signalValue); + DownloadErrorSignal error = new DownloadErrorSignal(this.randomDownloadID, cause, signalValue); this.postSignal(error); return new DownloadResult(false, this.taskState, path, -1, this.randomDownloadID, cause); } catch (Exception e) { - this.postSignal(new DownloadErrorSignal(DownloadErrorCause.UNKNOWN_ERROR, this.randomDownloadID, e)); + this.postSignal(new DownloadErrorSignal(this.randomDownloadID, DownloadErrorCause.UNKNOWN_ERROR, e)); return new DownloadResult(false, this.taskState, path, -1, this.randomDownloadID, DownloadErrorCause.UNKNOWN_ERROR diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java index 377371db..e5872c6e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java @@ -1,18 +1,24 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadErrorCause; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @Value -public class DownloadErrorSignal implements InstallerSignal +@EqualsAndHashCode(callSuper = true) +public class DownloadErrorSignal extends DownloadSignal { @NotNull DownloadErrorCause cause; - @NotNull - String downloadId; @Nullable Object value; + + public DownloadErrorSignal(@NotNull String downloadId, @NotNull DownloadErrorCause cause, @Nullable Object value) + { + super(downloadId); + this.cause = cause; + this.value = value; + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java index 7348f66d..23cfb835 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java @@ -1,17 +1,23 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; @Value -public class DownloadProgressSignal implements InstallerSignal +@EqualsAndHashCode(callSuper = true) +public class DownloadProgressSignal extends DownloadSignal { - @NotNull - String downloadId; - long totalSize; long downloaded; double percentage; + + public DownloadProgressSignal(@NotNull String downloadId, long totalSize, long downloaded, double percentage) + { + super(downloadId); + this.totalSize = totalSize; + this.downloaded = downloaded; + this.percentage = percentage; + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java new file mode 100644 index 00000000..8a2b4a66 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +@Data +public class DownloadSignal implements InstallerSignal +{ + @NotNull + private final String downloadId; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java index fb7f42fa..b2b5a1e6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java @@ -1,19 +1,24 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; -import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; -@Data -public class DownloadStartingSignal implements InstallerSignal +@Getter +@Setter +public class DownloadStartingSignal extends DownloadSignal { - @NotNull - String downloadId; - @NotNull private Path downloadPath; @NotNull private String url; + + public DownloadStartingSignal(@NotNull String downloadId, @NotNull Path downloadPath, @NotNull String url) + { + super(downloadId); + this.downloadPath = downloadPath; + this.url = url; + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java index e2bec4b5..3e77f91c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java @@ -1,18 +1,23 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; @Value -public class DownloadSucceedSignal implements InstallerSignal +@EqualsAndHashCode(callSuper = true) +public class DownloadSucceedSignal extends DownloadSignal { - @NotNull - String downloadId; - @NotNull Path downloadPath; long totalSize; + + public DownloadSucceedSignal(@NotNull String downloadId, @NotNull Path downloadPath, long totalSize) + { + super(downloadId); + this.downloadPath = downloadPath; + this.totalSize = totalSize; + } } From b7b74158dab3bd78bfe568db9c4afd0bbe14234a Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 4 Sep 2022 07:29:14 +0900 Subject: [PATCH 219/745] refactor: Remove unused signal: DependsCacheSaveFailedSignal --- .../collector/signals/DependsCacheSaveFailedSignal.java | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCacheSaveFailedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCacheSaveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCacheSaveFailedSignal.java deleted file mode 100644 index ed5c0176..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCacheSaveFailedSignal.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; - -public class DependsCacheSaveFailedSignal implements InstallerSignal -{ -} From a6fdf3903fe42d00345de09ef3dae26efd052685 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 4 Sep 2022 23:09:48 +0900 Subject: [PATCH 220/745] refactor: Make DownloadSignal abstract --- .../installer/task/tasks/download/signals/DownloadSignal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java index 8a2b4a66..c55606f3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull; @Data -public class DownloadSignal implements InstallerSignal +public abstract class DownloadSignal implements InstallerSignal { @NotNull private final String downloadId; From ce9dd5bccb58f9180e475661fadbc5ac7c4188ff Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 4 Sep 2022 23:48:23 +0900 Subject: [PATCH 221/745] refactor: Make InstallTask#postSignal protected --- .../teamkunpluginmanager/plugin/installer/task/InstallTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java index db093c37..f0752061 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java @@ -16,7 +16,7 @@ public abstract class InstallTask Date: Sun, 4 Sep 2022 23:58:12 +0900 Subject: [PATCH 222/745] refactor: Remove unexpected getter of InstallProgress --- .../teamkunpluginmanager/plugin/installer/InstallProgress.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index c3f3740f..fd7a205a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; @@ -21,7 +22,9 @@ @Getter public class InstallProgress> { + @Getter(AccessLevel.NONE) private static final HashMap> PROGRESS_CACHES; + @Getter(AccessLevel.NONE) private static final Path CACHE_DIRECTORY; @Setter From 377fe233da2ecb40a96bf1b5d1dec7e133f2f8e3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 5 Sep 2022 01:04:39 +0900 Subject: [PATCH 223/745] docs: Javadoc of newly added installer public methods/classes/fields --- .../installer/InstallFailedInstallResult.java | 7 ++ .../plugin/installer/InstallProgress.java | 76 +++++++++++++++++-- .../plugin/installer/InstallResult.java | 56 ++++++++++++++ .../plugin/installer/InstallerSignal.java | 11 +++ .../installer/InstallerSignalHandler.java | 10 +++ .../impls/install/InstallErrorCause.java | 20 +++++ .../installer/impls/install/InstallTasks.java | 50 ++++++++++++ .../impls/install/PluginInstaller.java | 13 ++++ .../signals/AlreadyInstalledPluginSignal.java | 13 ++++ .../impls/uninstall/PluginUninstaller.java | 11 +++ .../impls/uninstall/UnInstallErrorCause.java | 14 ++++ .../impls/uninstall/UnInstallTasks.java | 16 ++++ .../signals/PluginIsDependencySignal.java | 8 +- .../signals/SearchingPluginSignal.java | 3 + .../signals/PluginModifiedSignal.java | 24 ++++++ .../assertion/IgnoredPluginSignal.java | 4 + .../installer/task/GeneralTaskErrorCause.java | 9 +++ .../plugin/installer/task/InstallTask.java | 18 +++++ .../plugin/installer/task/TaskArgument.java | 3 + .../plugin/installer/task/TaskChain.java | 59 ++++++++++++++ .../plugin/installer/task/TaskResult.java | 16 ++++ .../tasks/dependencies/DependencyElement.java | 12 +++ .../collector/DependsCollectArgument.java | 18 +++++ .../collector/DependsCollectErrorCause.java | 6 ++ .../collector/DependsCollectResult.java | 16 ++++ .../collector/DependsCollectState.java | 15 ++++ .../collector/DependsCollectStatus.java | 46 +++++++++++ .../collector/DependsCollectTask.java | 15 ++++ ...CollectDependencysDependsFailedSignal.java | 9 +++ .../DependencyCollectFailedSignalBase.java | 7 ++ .../DependencyDownloadFailedSignal.java | 3 + ...DependencyLoadDescriptionFailedSignal.java | 3 + .../signals/DependencyNameMismatchSignal.java | 19 +++-- .../DependencyResolveFailedSignal.java | 3 + .../signals/DependsCollectFailedSignal.java | 7 ++ .../signals/DependsEnumeratedSignal.java | 9 +++ .../computer/DependsComputeOrderArgument.java | 6 ++ .../DependsComputeOrderErrorCause.java | 3 + .../computer/DependsComputeOrderResult.java | 6 ++ .../computer/DependsComputeOrderState.java | 12 +++ .../computer/DependsComputeOrderTask.java | 5 +- .../DependsLoadOrderComputingSignal.java | 14 ++++ .../description/DescriptionLoadArgument.java | 6 ++ .../DescriptionLoadErrorCause.java | 13 +++- .../description/DescriptionLoadResult.java | 11 ++- .../description/DescriptionLoadState.java | 10 ++- .../description/DescriptionLoadTask.java | 3 + .../signals/LoadPluginDescriptionSignal.java | 7 ++ .../task/tasks/download/DownloadArgument.java | 9 +++ .../tasks/download/DownloadErrorCause.java | 16 +++- .../task/tasks/download/DownloadResult.java | 12 +++ .../task/tasks/download/DownloadState.java | 13 +++- .../task/tasks/download/DownloadTask.java | 4 + .../download/signals/DownloadErrorSignal.java | 12 +++ .../signals/DownloadProgressSignal.java | 13 ++++ .../download/signals/DownloadSignal.java | 6 ++ .../signals/DownloadStartingSignal.java | 9 +++ .../signals/DownloadSucceedSignal.java | 9 +++ .../tasks/install/PluginsInstallArgument.java | 12 +++ .../install/PluginsInstallErrorCause.java | 18 +++++ .../tasks/install/PluginsInstallResult.java | 6 ++ .../tasks/install/PluginsInstallState.java | 18 +++++ .../tasks/install/PluginsInstallTask.java | 3 + .../install/signals/PluginEnablingSignal.java | 14 ++++ .../signals/PluginInstallingSignal.java | 9 +++ .../install/signals/PluginLoadSignal.java | 20 +++++ .../signals/PluginOnLoadRunningSignal.java | 12 +++ .../signals/PluginRelocatingSignal.java | 10 +++ .../tasks/resolve/PluginResolveArgument.java | 6 ++ .../resolve/PluginResolveErrorCause.java | 10 ++- .../tasks/resolve/PluginResolveResult.java | 6 ++ .../tasks/resolve/PluginResolveState.java | 18 +++++ .../task/tasks/resolve/PluginResolveTask.java | 5 +- .../signals/MultiplePluginResolvedSignal.java | 14 ++++ .../signals/PluginResolveErrorSignal.java | 6 ++ .../PluginResolvedSuccessfulSignal.java | 7 ++ .../signals/PluginResolvingSignal.java | 11 ++- .../tasks/uninstall/UnInstallArgument.java | 6 ++ .../tasks/uninstall/UnInstallErrorCause.java | 15 ++++ .../task/tasks/uninstall/UnInstallResult.java | 9 +++ .../task/tasks/uninstall/UnInstallState.java | 24 ++++++ .../task/tasks/uninstall/UnInstallTask.java | 3 + .../signals/PluginDisablingSignal.java | 12 +++ .../signals/PluginRegisteredRecipeSignal.java | 26 +++++++ .../signals/PluginUnloadingSignal.java | 16 ++++ .../plugin/loader/CommandsPatcher.java | 43 ++++++++++- .../plugin/loader/PluginLoader.java | 12 ++- 87 files changed, 1176 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index 48f2316e..2d767b6a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -4,6 +4,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * インストールに失敗したことを表すインストール結果です。 + * + * @param

インストールの進捗状況の型 + * @param 失敗した理由の型 + * @param タスクの状態の型 + */ @Getter public class InstallFailedInstallResult

, T extends Enum, S extends Enum> extends InstallResult

diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index fd7a205a..70f2e241 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -19,6 +19,11 @@ import java.util.List; import java.util.UUID; +/** + * インストールの進捗状況を管理するクラスです。 + * + * @param インストーラの状態の型 + */ @Getter public class InstallProgress> { @@ -27,13 +32,26 @@ public class InstallProgress> @Getter(AccessLevel.NONE) private static final Path CACHE_DIRECTORY; - @Setter - private T currentTask; - + /** + * アップグレードされたプラグインの名前です。 + */ private final List upgraded; + /** + * 新規にインストールされたプラグインの名前です。 + */ private final List installed; + /** + * 削除されたプラグインの名前です。 + */ private final List removed; + /** + * 保留中としてマークされたプラグインの名前です。 + */ private final List pending; + /** + * インストールに使用される仮ディレクトリです。 + */ + private final Path installTempDir; static { @@ -52,11 +70,23 @@ public class InstallProgress> } } - private final Path installTempDir; - + /** + * インストールに割り当てられた一意のIDです。 + */ private final String installActionID; + /** + * {@link InstallerSignal} を受け取るためのリスナーです。 + */ private final InstallerSignalHandler signalHandler; + /** + * 依存関係の解決の状態を表します。 + */ private final DependsCollectStatus dependsCollectStatus; + /** + * 実行中のタスクを表します。 + */ + @Setter + private T currentTask; private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable String id) throws IOException, SecurityException { @@ -84,6 +114,16 @@ private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable PROGRESS_CACHES.put(this.getInstallActionID(), this); } + /** + * このインスタンスを取得します。 + * + * @param signalHandler インストールに使用する {@link InstallerSignalHandler} + * @param id インストールに割り当てる一意のID + * @param

インストールの進捗状況の型 + * @return インスタンス + * @throws IOException ディレクトリの作成に失敗した場合 + * @throws SecurityException ディレクトリの作成に失敗した場合 + */ public static

> InstallProgress

of(@NotNull InstallerSignalHandler signalHandler, @Nullable String id) throws IOException, SecurityException { @@ -101,6 +141,12 @@ private void removeFromAll(@NotNull String name) this.pending.remove(name); } + /** + * プラグインがアップグレードされたとしてマークします。 + * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#UPGRADE} の {@link PluginModifiedSignal} をスローします。 + * + * @param pluginDescription アップグレードされたプラグインの {@link PluginDescriptionFile} + */ public void addUpgraded(@NotNull PluginDescriptionFile pluginDescription) { this.removeFromAll(pluginDescription.getName()); @@ -112,6 +158,12 @@ public void addUpgraded(@NotNull PluginDescriptionFile pluginDescription) this.upgraded.add(pluginDescription.getName()); } + /** + * プラグインが新規にインストールされたとしてマークします。 + * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#ADD} の {@link PluginModifiedSignal} をスローします。 + * + * @param pluginDescription 新規にインストールされたプラグインの {@link PluginDescriptionFile} + */ public void addInstalled(@NotNull PluginDescriptionFile pluginDescription) { this.removeFromAll(pluginDescription.getName()); @@ -125,6 +177,12 @@ public void addInstalled(@NotNull PluginDescriptionFile pluginDescription) this.installed.add(pluginDescription.getName()); } + /** + * プラグインが削除されたとしてマークします。 + * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#REMOVE} の {@link PluginModifiedSignal} をスローします。 + * + * @param pluginDescription 削除されたプラグインの {@link PluginDescriptionFile} + */ public void addRemoved(@NotNull PluginDescriptionFile pluginDescription) { this.removeFromAll(pluginDescription.getName()); @@ -136,6 +194,11 @@ public void addRemoved(@NotNull PluginDescriptionFile pluginDescription) this.removed.add(pluginDescription.getName()); } + /** + * プラグインが保留されたとしてマークします。 + * + * @param pluginName 保留されたプラグインの名前 + */ public void addPending(@NotNull String pluginName) { this.removeFromAll(pluginName); @@ -143,6 +206,9 @@ public void addPending(@NotNull String pluginName) this.pending.add(pluginName); } + /** + * インストールが完了したとしてマークし、インストールに使用された仮ディレクトリを削除します。 + */ public void finish() { try diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java index 871601ed..c0060adc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -8,12 +8,23 @@ import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; +/** + * インストールの結果を表します。 + * + * @param

インストールの進捗状況の型 + */ public class InstallResult

> { private static final int MAX_RESULT_HOVER_ONE_LINE = 5; + /** + * インストールが成功したかどうかです。 + */ @Getter private final boolean success; + /** + * インストールの進捗状況です。 + */ @Getter private final InstallProgress

progress; @@ -42,46 +53,91 @@ private static TextComponent getResultStatusComponent(@NotNull String[] componen .hoverEvent(HoverEvent.showText(Component.text(hoverPrefix + "\n" + builder))); } + /** + * アップグレードされたプラグインの数を取得します。 + * + * @return アップグレードされたプラグインの数 + */ public int getUpgradedCount() { return progress.getUpgraded().size(); } + /** + * インストールされたプラグインの数を取得します。 + * + * @return インストールされたプラグインの数 + */ public int getInstalledCount() { return progress.getInstalled().size(); } + /** + * 削除されたプラグインの数を取得します。 + * + * @return 削除されたプラグインの数 + */ public int getRemovedCount() { return progress.getRemoved().size(); } + /** + * 保留中としてマークされたプラグインの数を取得します。 + * + * @return 保留中としてマークされたプラグインの数 + */ public int getPendingCount() { return progress.getPending().size(); } + /** + * アップグレードされたプラグインの名前を取得します。 + * + * @return アップグレードされたプラグインの名前 + */ public String[] getUpgraded() { return progress.getUpgraded().toArray(new String[0]); } + /** + * インストールされたプラグインの名前を取得します。 + * + * @return インストールされたプラグインの名前 + */ public String[] getInstalled() { return progress.getInstalled().toArray(new String[0]); } + /** + * 削除されたプラグインの名前を取得します。 + * + * @return 削除されたプラグインの名前 + */ public String[] getRemoved() { return progress.getRemoved().toArray(new String[0]); } + /** + * 保留中としてマークされたプラグインの名前を取得します。 + * + * @return 保留中としてマークされたプラグインの名前 + */ public String[] getPending() { return progress.getPending().toArray(new String[0]); } + /** + * インストールの結果をコンソールに出力します。 + * + * @param terminal 出力先のターミナル + */ public void printResultStatus(@NotNull Terminal terminal) { TextComponent component = Component.text("") diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java index e83263d8..7b46b313 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignal.java @@ -1,5 +1,16 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +/** + * インストーラまたはタスクからスローされるシグナルです。 + * シグナルは、主に次のことに使用されます: + *

+ *

+ * このシグナルは、フロントエンドとバックエンドの隔離のために作成されました。 + */ public interface InstallerSignal { } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java index 4b00e8e2..70002395 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java @@ -2,8 +2,18 @@ import org.jetbrains.annotations.NotNull; +/** + * {@link InstallerSignal} を受け取るハンドラーです。 + */ @FunctionalInterface public interface InstallerSignalHandler { + /** + * シグナルを受け取ります。 + * + * @param installProgress シグナルを受け取ったインストールの進捗状況 + * @param signal 受け取ったシグナル + * @param シグナルの型 + */ void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java index 308ffd23..4b042e73 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java @@ -1,15 +1,35 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; +/** + * インストールのエラーを表す列挙型です。 + */ public enum InstallErrorCause { // Tasks + /** + * タスクの実行中に例外が発生しました。 + */ TASK_EXCEPTION_OCCURRED, + /** + * タスクの実行に失敗しました。 + */ TASK_FAILED, // Environment errors + /** + * 変更しようとしているプラグインが、無視リストに登録されており、 + * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal} でも強制インストールが選択されませんでした。 + */ PLUGIN_IGNORED, + /** + * インストールしようとしているプラグインが、既にインストールされており、 + * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 + */ PLUGIN_ALREADY_INSTALLED, // Exceptions + /** + * 例外が発生しました。 + */ EXCEPTION_OCCURRED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java index f0f583f0..9b34552c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java @@ -1,16 +1,66 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; +/** + * インストールに必要なタスクをまとめた列挙型です。 + * デバッグ用に使用されることがあります。 + */ public enum InstallTasks { + /** + * インストールが開始されたことを示します。 + */ STARTED, + /** + * インストーラの初期化中であることを示します。 + */ INITIALIZING, + /** + * プラグイン・クエリの解決中であることを示します。 + * + * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask + */ RESOLVING_QUERY, + /** + * プラグインのダウンロード中であることを示します。 + * + * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask + */ DOWNLOADING, + /** + * プラグイン情報の読み込み中であることを示します。 + * + * @see org.bukkit.plugin.PluginDescriptionFile + * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadTask + */ LOADING_PLUGIN_DESCRIPTION, + /** + * 環境の状態を確認中であることを示します。 + * 例えば、既にインストールされているプラグインを新規にインストールしようとした場合や、 + * 無視リストに含まれているプラグインをインストールしようとしていないかどうかを確認します。 + */ CHECKING_ENVIRONMENT, + /** + * 古いプラグインの削除中であることを示します。 + * このタスクは必ずしも実行されるわけではなく、{@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal} で {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal#setReplacePlugin(boolean)} に {@code true} が設定されてた場合にのみ実行されます。 + */ REMOVING_OLD_PLUGIN, + /** + * 依存関係のインストール中であることを示します。 + * + * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectTask + */ COLLECTING_DEPENDENCIES, + /** + * プラグインの読み込み順序を計算中であることを示します。 + * + * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal + */ COMPUTING_LOAD_ORDER, + /** + * プラグインのインストール中であることを示します。 + * + * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask + */ INSTALLING_PLUGINS, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index 7e676120..5b739695 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -34,6 +34,19 @@ import java.nio.file.Path; import java.util.List; +/** + * プラグインを新規にインストールするインストーラーの実装です。 + * インストーラは主に以下の流れで動作します。 + *

    + *
  1. クエリを解決する({@link InstallTasks#RESOLVING_QUERY})。
  2. + *
  3. プラグインをダウンロードする({@link InstallTasks#DOWNLOADING})。
  4. + *
  5. プラグイン情報ファイルを読み込む({@link InstallTasks#LOADING_PLUGIN_DESCRIPTION})。
  6. + *
  7. 環境が適合しているかどうかをチェックする({@link InstallTasks#CHECKING_ENVIRONMENT})。
  8. + *
  9. 依存関係を解決する({@link InstallTasks#COLLECTING_DEPENDENCIES})。
  10. + *
  11. インストール順序を計算する({@link InstallTasks#COMPUTING_LOAD_ORDER})。
  12. + *
  13. 依存関係とプラグインをインストールする({@link InstallTasks#INSTALLING_PLUGINS})。
  14. + *
+ */ public class PluginInstaller extends AbstractInstaller { public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOException diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java index bedb5dd7..4597a7f6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java @@ -5,9 +5,16 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +/** + * プラグインが既にインストールされていることを示すシグナルです。 + * {@link AlreadyInstalledPluginSignal#setReplacePlugin(boolean)} を用いて、既存のプラグインを新規プラグインに置換するかどうかを設定できます。 + */ @Data public class AlreadyInstalledPluginSignal implements InstallerSignal { + /** + * インストールされたプラグインの種類 + */ @NotNull private final PluginDescriptionFile installedPlugin; @@ -16,6 +23,12 @@ public class AlreadyInstalledPluginSignal implements InstallerSignal private boolean replacePlugin; + /** + * コンストラクタです。 + * + * @param installedPlugin 既にインストールされているプラグインの {@link PluginDescriptionFile} + * @param installingPlugin インストールしようとしているプラグインの {@link PluginDescriptionFile} + */ public AlreadyInstalledPluginSignal(@NotNull PluginDescriptionFile installedPlugin, @NotNull PluginDescriptionFile installingPlugin) { this.installedPlugin = installedPlugin; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index de81cd08..7d06a939 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -27,6 +27,17 @@ import java.util.Map; import java.util.stream.Collectors; +/** + * プラグインをアンインストールするインストーラーの実装です。 + * インストーラは主に以下の流れで動作します。 + * + *
    + *
  1. {@link UnInstallTasks#SEARCHING_PLUGIN} - アンインストール対象のプラグインを検索する。
  2. + *
  3. {@link UnInstallTasks#CHECKING_ENVIRONMENT} - 環境が適合しているかどうかをチェックする。
  4. + *
  5. {@link UnInstallTasks#COMPUTING_UNINSTALL_ORDER} - アンインストールする順序を、依存関係を考慮して計算する。
  6. + *
  7. {@link UnInstallTasks#UNINSTALLING_PLUGINS} - プラグインをアンインストールする。
  8. + *
+ */ public class PluginUninstaller extends AbstractInstaller { public PluginUninstaller(InstallerSignalHandler signalHandler) throws IOException diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java index d94e329e..15ab7e69 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java @@ -1,8 +1,22 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; +/** + * アンインストールのエラーを表す列挙型です。 + */ public enum UnInstallErrorCause { + /** + * 指定されたプラグインが見つかりませんでした。 + */ PLUGIN_NOT_FOUND, + /** + * 指定されたプラグインが無視リストに登録されており、 + * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal} でも強制アンインストールが選択されませんでした。 + */ PLUGIN_IGNORED, + /** + * 指定されたプラグインが他のプラグインの依存関係に含まれており、 + * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal} でも強制アンインストールが選択されませんでした。 + */ PLUGIN_IS_DEPENDENCY, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java index 11cd1f28..8982fc07 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java @@ -1,10 +1,26 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; +/** + * アンインストールのタスクを表す列挙型です。 + */ public enum UnInstallTasks { + /** + * プラグインの検索中を示します。 + */ SEARCHING_PLUGIN, + /** + * 環境の状態の確認中を示します。 + * 例えば、プラグインが存在するかや、無視リストに登録されていないかなどを確認します。 + */ CHECKING_ENVIRONMENT, + /** + * アンインストール順序の計算中を示します。 + */ COMPUTING_UNINSTALL_ORDER, + /** + * プラグインをアンインストール中を示します。 + */ UNINSTALLING_PLUGINS, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java index 790d414c..67a80f03 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java @@ -7,6 +7,10 @@ import java.util.List; +/** + * アンインストールしようとしたプラグインが、他のプラグインの依存関係にあることを示すシグナルです。 + * {@link PluginIsDependencySignal#setForceUninstall(boolean)} (boolean)} を用いて、強制的にアンインストールするかどうかを設定できます。 + */ @Data public class PluginIsDependencySignal implements InstallerSignal { @@ -16,8 +20,8 @@ public class PluginIsDependencySignal implements InstallerSignal private final List dependedBy; /** - * Force uninstall plugin. - * If this turn to true, it will uninstall the plugin and all its dependencies. + * 強制的にアンインストールするかどうかを示すフラグです。 + * このフラグが {@code true} の場合、このプラグインの依存関係にあるプラグインも一緒にアンインストールされます。 */ private boolean forceUninstall; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java index 0649b824..ff92bd9e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java @@ -4,6 +4,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; +/** + * プラグインを検索中であることを示すシグナルです。 + */ @Data public class SearchingPluginSignal implements InstallerSignal { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java index 780ce2bb..5cdafc66 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java @@ -5,18 +5,42 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +/** + * サーバ上のプラグインが変更されたことを示すシグナルです。 + * 新規にインストールされた場合、削除された場合、更新された場合にスローされます。 + */ @Value public class PluginModifiedSignal implements InstallerSignal { + /** + * 変更され他プラグインの情報です。 + * + * @see PluginDescriptionFile + */ @NotNull PluginDescriptionFile pluginDescription; + /** + * 変更の種類です。 + */ @NotNull ModifyType modifyType; + /** + * 変更の種類を表す列挙型です。 + */ public enum ModifyType { + /** + * プラグインが新規にインストールされたことを示します。 + */ ADD, + /** + * プラグインが削除されたことを示します。 + */ REMOVE, + /** + * プラグインが更新されたことを示します。 + */ UPGRADE } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java index 5d65faeb..6381d064 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java @@ -5,6 +5,10 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +/** + * 指定されたプラグインが無視リストに登録されていることを示すシグナルです。 + * {@link IgnoredPluginSignal#setCancelInstall(boolean)} を変更することで、インストールのキャンセルを設定できます。 + */ @Data public class IgnoredPluginSignal implements InstallerSignal { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java index b55b90bf..68df8eaa 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java @@ -1,8 +1,17 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; +/** + * 一般的なエラーの原因を表します。 + */ public enum GeneralTaskErrorCause { // General internal errors + /** + * 予期しないタスクの返答があリました。 + */ ILLEGAL_INTERNAL_STATE, + /** + * {@link java.io.IOException} が発生しました。 + */ IO_EXCEPTION_OCCURRED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java index f0752061..312718cc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java @@ -6,14 +6,32 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import org.jetbrains.annotations.NotNull; +/** + * インストールに使用するタスクの基底クラスです。 + * + * @param
タスクの引数の型 + * @param タスクの結果の型 + */ @AllArgsConstructor public abstract class InstallTask, ? extends Enum>> { + /** + * インストールごとに生成される、インストール進捗状況です。 + */ @NotNull protected final InstallProgress progress; + /** + * タスクからスローされるシグナルを受け取るハンドラーです。 + */ @NotNull private final InstallerSignalHandler signalHandler; + /** + * タスクを実行します。 + * + * @param arguments タスクの引数です。 + * @return タスクの結果です。 + */ public abstract @NotNull R runTask(@NotNull A arguments); protected void postSignal(@NotNull InstallerSignal signal) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java index 7a3c716a..489496ef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java @@ -2,6 +2,9 @@ import lombok.Getter; +/** + * タスクの引数を表します。 + */ public abstract class TaskArgument { @Getter diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java index 88e85157..eeaa4067 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java @@ -8,6 +8,17 @@ import java.util.function.Function; +/** + * タスクを連続して実行するために使用される便利なユーティリティです。 + * 内部でインストーラの状態を変更しながら、タスクをステップバイステップで実行していきます。 + * また、前のタスクの結果を次のタスク用の引数に加工するメソッドをサポートします。 + * + * @param タスクの引数の型 + * @param 設定するインストーラの状態 + * @param タスクの結果の型 + * @param 親の{@link TaskChain} の結果の方 + * @param タスクの型 + */ public class TaskChain< TA extends TaskArgument, IS extends Enum, @@ -34,6 +45,14 @@ public class TaskChain< @Nullable private Function argumentBuilder; + /** + * {@link TaskChain} を生成します。 + * + * @param task タスク + * @param installerState 設定するインストーラの状態 + * @param first 最初の{@link TaskChain} + * @param installer インストーラ + */ public TaskChain(@NotNull T task, @NotNull IS installerState, @Nullable TaskChain first, @NotNull AbstractInstaller installer) { @@ -43,12 +62,28 @@ public TaskChain(@NotNull T task, @NotNull IS installerState, @Nullable TaskChai this.installer = installer; } + /** + * {@link TaskChain} を生成します。 + * + * @param task タスク + * @param installerState 設定するインストーラの状態 + * @param installer インストーラ + */ public TaskChain(@NotNull T task, @NotNull IS installerState, @NotNull AbstractInstaller installer) { this(task, installerState, null, installer); this.first = this; } + /** + * タスクをつなげます。 + * + * @param installerState 設定するインストーラの状態 + * @param nextTask 次のタスク + * @param 次のタスクの引数の型 + * @param 次のタスクの結果の型 + * @return 次の{@link TaskChain} + */ public > TaskChain then(@NotNull IS installerState, @NotNull InstallTask nextTask) { @@ -57,12 +92,24 @@ public TaskChain(@NotNull T task, @NotNull IS installerState, @NotNull AbstractI return nextChain; } + /** + * 前のタスクの {@link TaskResult} を引数にして、次のタスクの引数を生成する関数を設定します。 + * + * @param argumentBuilder 前のタスクの {@link TaskResult} を引数にして、次のタスクの引数を生成する関数 + * @return この{@link TaskChain} + */ public TaskChain bridgeArgument(@NotNull Function argumentBuilder) { this.argumentBuilder = argumentBuilder; return this; } + /** + * このタスクから登録されたタスクを実行していきます。 + * + * @param argument タスクの引数 + * @return タスクの結果 + */ public @NotNull TaskResult submitFromThis(@NotNull TaskArgument argument) { try @@ -81,6 +128,12 @@ public TaskChain bridgeArgument(@NotNull Function argu } } + /** + * このタスクから登録されたタスクを実行していきます。 + * + * @param taskResult 前のタスクの結果 + * @return タスクの結果 + */ public @NotNull TaskResult submitFromThis(@NotNull TaskResult taskResult) { if (this.argumentBuilder == null) @@ -102,6 +155,12 @@ public TaskChain bridgeArgument(@NotNull Function argu } } + /** + * 最初のタスクから登録されたタスクを実行していきます。 + * + * @param argument タスクの引数 + * @return タスクの結果 + */ public @NotNull TaskResult submitAll(@NotNull TaskArgument argument) { if (this.first == null) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java index 4547690b..63af1bea 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java @@ -5,14 +5,30 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * 実行したタスクの結果を表します。 + * + * @param タスクの状態の型 + * @param タスクのエラー原因の型 + */ @AllArgsConstructor @Getter public abstract class TaskResult, EC extends Enum> { + /** + * タスクが成功したかどうかです。 + */ private final boolean success; + /** + * タスクの状態です。 + */ @NotNull private final S state; + /** + * タスクのエラー原因です。 + * タスクが成功した場合は {@code null} です。 + */ @Nullable private final EC errorCause; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java index 1f252e7c..2201981c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java @@ -9,17 +9,29 @@ import java.nio.file.Path; +/** + * 依存関係 系のタスクで使用される、概念的な依存関係を表すクラスです。 + */ @Value @AllArgsConstructor public class DependencyElement { + /** + * 依存関係の名前です。 + */ @Expose @NotNull String pluginName; + /** + * 依存関係プラグインがあるのパスです。 + */ @Expose @NotNull Path pluginPath; + /** + * 依存関係のプラグイン情報ファイルです。 + */ @NotNull PluginDescriptionFile pluginDescription; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java index d2a00f9e..26db8790 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java @@ -12,12 +12,23 @@ import java.util.List; import java.util.stream.Collectors; +/** + * 依存関係の取得に必要な引数を表します。 + * + * @see DependsCollectTask + */ @Value @EqualsAndHashCode(callSuper = false) public class DependsCollectArgument extends TaskArgument { + /** + * 依存関係を取得する対象のプラグインのプラグイン情報ファイルです。 + */ @NotNull PluginDescriptionFile pluginDescription; + /** + * 既にサーバにインストールされているまたは既に取得済みの依存関係です。 + */ @NotNull List alreadyInstalledPlugins; @@ -41,6 +52,13 @@ public DependsCollectArgument(@NotNull PluginDescriptionFile pluginDescription, this.alreadyInstalledPlugins = alreadyInstalledPlugins; } + /** + * プラグイン情報ファイルから依存関係を取得します。 + * {@link #alreadyInstalledPlugins} には、サーバにインストールされているプラグインが自動で追加されます。 + * + * @param pluginDescription プラグイン情報ファイル + * @see org.bukkit.plugin.PluginManager#getPlugins() + */ public DependsCollectArgument(@NotNull PluginDescriptionFile pluginDescription) { this(pluginDescription, Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java index 048bf5c0..e6c398a2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java @@ -1,6 +1,12 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +/** + * 依存関係の取得に失敗した理由を表します。 + */ public enum DependsCollectErrorCause { + /** + * いくつかの依存関係の解決に失敗しました。 + */ SOME_DEPENDENCIES_COLLECT_FAILED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java index 325f3c90..8fa7875b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java @@ -9,16 +9,32 @@ import java.util.List; +/** + * 依存関係の解決結果を表します。 + */ @Value @EqualsAndHashCode(callSuper = true) public class DependsCollectResult extends TaskResult { + /** + * 依存関係解決対象のプラグインです。 + */ @NotNull String targetPlugin; + /** + * 依存関係の要素のリストです。解決に失敗した場合は空のリストです。 + * + * @see #isSuccess() + */ @NotNull List collectedPlugins; + /** + * 解決に失敗した依存関係の要素のリストです。解決に成功した場合は空のリストです。 + * + * @see #isSuccess() + */ @NotNull List collectFailedPlugins; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java index e89c0ba0..45a46167 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java @@ -1,11 +1,26 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +/** + * 依存関係取得の状態を表す列挙型です。 + */ public enum DependsCollectState { + /** + * 依存関係の取得が初期化されたことを示します。 + */ INITIALIZED, + /** + * 依存関係の解決中であることを示します。 + */ RESOLVING_DEPENDS, + /** + * 依存関係のダウンロード中であることを示します。 + */ DOWNLOADING_DEPENDS, + /** + * 依存関係の依存関係が検出された場合、再帰的に解決していることを示します。 + */ COLLECTING_DEPENDS_DEPENDS // Dependency's depends. } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index 1821228a..a292aca9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -16,6 +16,9 @@ import java.util.Objects; import java.util.stream.Collectors; +/** + * 依存関係解決の状態を表すクラスです。 + */ @Data @AllArgsConstructor public class DependsCollectStatus @@ -23,15 +26,26 @@ public class DependsCollectStatus private static final Gson gson = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .create(); + /** + * 割り当てられたインストールIDです。 + */ @NotNull private final String installId; @NotNull @Getter(AccessLevel.PRIVATE) private final HashMap enumeratedDependencies; + /** + * 依存関係解決の対象のプラグイン名です。 + */ @NotNull private String pluginName; + /** + * このクラスのインスタンスを生成します。 + * + * @param progress InstallProgress + */ public DependsCollectStatus(InstallProgress progress) { this.installId = progress.getInstallActionID(); @@ -39,28 +53,55 @@ public DependsCollectStatus(InstallProgress progress) this.pluginName = "undefined-" + this.installId; } + /** + * 検出された依存先プラグインを追加します。 + * + * @param dependencyName 検出されたプラグイン名 + */ public void addDependency(@NotNull String dependencyName) { if (!enumeratedDependencies.containsKey(dependencyName)) enumeratedDependencies.put(dependencyName, null); } + /** + * 指定された依存先プラグインが取得されたかどうかを返します。 + * + * @param dependencyName 依存関係名前 + * @return 取得されている場合はtrue、そうでない場合はfalse + */ public boolean isCollected(@NotNull String dependencyName) { return enumeratedDependencies.containsKey(dependencyName); } + /** + * 依存関係の解決にエラーが発生したかどうかを返します。 + * + * @return エラーが発生している場合はtrue、そうでない場合はfalse + */ public boolean isErrors() { return enumeratedDependencies.containsValue(null); } + /** + * 依存関係が解決されたときに呼び出します。 + * + * @param dependencyName 依存関係名 + * @param dependencyElement 依存関係要素 + */ public void onCollect(@NotNull String dependencyName, DependencyElement dependencyElement) { if (enumeratedDependencies.containsKey(dependencyName)) enumeratedDependencies.put(dependencyName, dependencyElement); } + /** + * 解決された依存関係をすべて取得します。 + * + * @return 依存関係要素のリスト + */ public List getCollectedDependencies() { return this.enumeratedDependencies.entrySet().stream().parallel() @@ -69,6 +110,11 @@ public List getCollectedDependencies() .collect(Collectors.toList()); } + /** + * 解決に失敗した依存関係をすべて取得します。 + * + * @return 依存関係要素のリスト + */ public List getCollectFailedDependencies() { return this.enumeratedDependencies.entrySet().stream().parallel() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 1c4892db..0c27413a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -33,6 +33,21 @@ import java.util.Objects; import java.util.stream.Collectors; +/** + * 依存関係解決タスクです。 + * このタスクは、以下のシグナルをスローします: + *
    + *
  • {@link DependsEnumeratedSignal}
  • + *
  • {@link PluginResolveTask} からスローされる可能性のあるシグナル
  • + *
  • {@link DownloadTask} からスローされる可能性のあるシグナル
  • + *
  • {@link DependencyLoadDescriptionFailedSignal}
  • + *
  • {@link DependencyNameMismatchSignal}
  • + *
  • {@link DependencyDownloadFailedSignal}
  • + *
  • {@link DependencyResolveFailedSignal}
  • + *
  • {@link DependencyCollectDependencysDependsFailedSignal}
  • + *
  • {@link DependsCollectFailedSignal}
  • + *
+ */ public class DependsCollectTask extends InstallTask { // TODO: きれいに private final InstallerSignalHandler signalHandler; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java index 752e25a7..e2e30a8b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java @@ -6,11 +6,20 @@ import java.util.List; +/** + * 依存関係の依存関係を取得する際に失敗したことを示すシグナルです。 + */ @Value public class DependencyCollectDependencysDependsFailedSignal implements InstallerSignal { + /** + * 対象のプラグインの名前です。 + */ @NotNull String pluginName; + /** + * 取得に失敗した依存関係の名前です。 + */ @NotNull List collectFailedDependencies; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java index 9585f6b1..b9003236 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java @@ -4,9 +4,16 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +/** + * 依存関係の取得に失敗したことを示すシグナルです。 + * このシグナルは基礎的なものであり、具体的な失敗の理由はサブクラスによって表現されます。 + */ @AllArgsConstructor @Getter public abstract class DependencyCollectFailedSignalBase implements InstallerSignal { + /** + * 取得に失敗した依存関係の名前です。 + */ private final String failedDependency; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java index 2f471b8a..e566ea34 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java @@ -1,5 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +/** + * 依存関係のダウンロードに失敗したことを示すシグナルです。 + */ public class DependencyDownloadFailedSignal extends DependencyCollectFailedSignalBase { public DependencyDownloadFailedSignal(String failedDependency) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java index 1e8145d0..eaebfa87 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java @@ -1,5 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +/** + * 依存関係のプラグイン情報ファイルの読み込みに失敗したことを示すシグナルです。 + */ public class DependencyLoadDescriptionFailedSignal extends DependencyCollectFailedSignalBase { public DependencyLoadDescriptionFailedSignal(String failedDependency) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java index dd569022..481edbf4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java @@ -1,7 +1,16 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +import lombok.Getter; + +/** + * 依存関係解決時に使用された名前と、プラグインが開示している名前が一致しなかったことを示すシグナルです。 + */ public class DependencyNameMismatchSignal extends DependencyCollectFailedSignalBase { + /** + * 期待されたプラグインの名前です。 + */ + @Getter private final String exceptedDependencyName; public DependencyNameMismatchSignal(String actualDependencyName, String exceptedDependencyName) @@ -10,11 +19,11 @@ public DependencyNameMismatchSignal(String actualDependencyName, String excepted this.exceptedDependencyName = exceptedDependencyName; } - public String getExceptedDependencyName() - { - return this.exceptedDependencyName; - } - + /** + * 実際の依存関係の名前を取得します。 + * + * @return 実際の依存関係の名前 + */ public String getActualDependencyName() { return getFailedDependency(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java index 2369b411..b3d890fc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java @@ -1,5 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +/** + * 依存関係の解決に失敗したことを示すシグナルです。 + */ public class DependencyResolveFailedSignal extends DependencyCollectFailedSignalBase { public DependencyResolveFailedSignal(String failedDependency) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java index 82f800bd..6bfc710c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java @@ -5,8 +5,15 @@ import java.util.List; +/** + * 依存関係の取得に失敗したことを示すシグナルです。 + * 注意:このシグナルは {@link DependencyCollectFailedSignalBase} とは違い個別には送信されず、依存関係の解決タスク終了後に一度送信されます。 + */ @Value public class DependsCollectFailedSignal implements InstallerSignal { + /** + * 取得に失敗した依存関係の名前です。 + */ List collectFailedPlugins; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java index 032120f5..edf8f39d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java @@ -6,10 +6,19 @@ import java.util.List; +/** + * 依存関係が列挙されたことを示すシグナルです。 + */ @AllArgsConstructor @Value public class DependsEnumeratedSignal implements InstallerSignal { + /** + * 列挙された依存関係。 + */ List dependencies; + /** + * 既にサーバーにインストールされている依存関係。 + */ List ignoredDependencies; // it means already installed or already collected } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java index 76c216c2..9e75b3db 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java @@ -9,9 +9,15 @@ import java.util.List; +/** + * 依存関係の読み込み順序を計算する際に使用される引数を表します。 + */ @AllArgsConstructor public class DependsComputeOrderArgument extends TaskArgument { + /** + * 計算対象の依存関係のリストです。 + */ @Getter private final List collectedDependencies; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java index 836e5217..cb613ea7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java @@ -1,5 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; +/** + * 依存関係の読み込み順序を計算する際に発生したエラーの原因を表します。 + */ public enum DependsComputeOrderErrorCause { } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java index bd9b6f99..2c1ac002 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java @@ -8,8 +8,14 @@ import java.util.List; +/** + * 依存関係の読み込み順序を計算した結果を表します。 + */ public class DependsComputeOrderResult extends TaskResult { + /** + * 計算された依存関係の読み込み順序リストです。 + */ @Getter @NotNull private final List order; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java index 51472993..826888a3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java @@ -1,9 +1,21 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; +/** + * 依存関係の読み込み順序計算の状態を表す列挙型です。 + */ public enum DependsComputeOrderState { + /** + * 依存関係の読み込み順序計算の初期化が完了したことを示します。 + */ INITIALIZED, + /** + * 依存関係マップの構築中であることを示します。 + */ CREATING_DEPENDENCY_MAP, + /** + * 依存関係の読み込み順序の計算中であることを示します。 + */ COMPUTING_DEPENDENCY_LOAD_ORDER } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index e088b9f4..e05b84e7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -18,7 +18,10 @@ import java.util.Map; /** - * This class is inspired by the class {@link org.bukkit.plugin.SimplePluginManager#loadPlugins(File, List)} + * 依存関係の読み込み順序を計算するタスクです。 + * This class is inspired by the class. {@link org.bukkit.plugin.SimplePluginManager#loadPlugins(File, List)} + * + * @see org.bukkit.plugin.SimplePluginManager#loadPlugins(File, List) */ public class DependsComputeOrderTask extends InstallTask { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java index 9ad7bf15..97a65ecc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java @@ -8,12 +8,22 @@ import java.util.Collections; import java.util.List; +/** + * 依存関係の読み込み順序を計算する際に発生するシグナルを表します。 + */ @Data public class DependsLoadOrderComputingSignal implements InstallerSignal { + /** + * 指定された依存関係のリストです。 + */ @NotNull private final List dependencies; + /** + * 順序の計算前に発生するシグナルです。 + * 注意: {@link #getDependencies()} から取得される依存関係リストは、{@link Collections#unmodifiableList(List)} でラップされています。 + */ public static class Pre extends DependsLoadOrderComputingSignal { public Pre(final List dependencies) @@ -22,6 +32,10 @@ public Pre(final List dependencies) } } + /** + * 順序の計算に成功したことを示すシグナルです。 + * 計算結果を書き換えることで、読み込み順序を変更できます。 + */ public static class Post extends DependsLoadOrderComputingSignal { public Post(final List dependencies) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java index 2dc51700..2e07fa48 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java @@ -8,10 +8,16 @@ import java.nio.file.Path; +/** + * プラグイン情報ファイルを読み込む際に使用される引数を表します。 + */ @Value @EqualsAndHashCode(callSuper = false) public class DescriptionLoadArgument extends TaskArgument { + /** + * プラグイン情報ファイルのパスです。 + */ @NotNull Path pluginFile; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java index 7c21f986..cf070347 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java @@ -1,9 +1,20 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; - +/** + * プラグイン情報ファイルの読み込みに失敗した際のエラーの原因を表します。 + */ public enum DescriptionLoadErrorCause { + /** + * 指定されたファイルがプラグインではないか、 plugin.yml が存在しません。 + */ NOT_A_PLUGIN, + /** + * 不正なプラグイン情報ファイルです。 + */ INVALID_DESCRIPTION, + /** + * {@link java.io.IOException} が発生しました。 + */ IO_EXCEPTION } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java index fdc0cca8..efd4ad96 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java @@ -8,11 +8,20 @@ import java.nio.file.Path; -@Getter +/** + * プラグイン情報ファイルの読み込み結果を表します。 + */ +@Getter // TODO: make @Value public class DescriptionLoadResult extends TaskResult { + /** + * プラグインファイルの場所です。 + */ @NotNull private final Path pluginFile; + /** + * 読み込まれた、プラグイン情報ファイルの概念的なオブジェクトです。 + */ @Nullable private final PluginDescriptionFile description; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java index c8abb31a..39840bdf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java @@ -1,9 +1,17 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; - +/** + * プラグイン情報ファイルの読み込みの状態を表します。 + */ public enum DescriptionLoadState { + /** + * プラグイン情報ファイルの読み込みが初期化されたことを示します。 + */ INITIALIZED, + /** + * プラグイン情報ファイルの読み込み中であることを示します。 + */ LOADING_PLUGIN_DESCRIPTION } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java index 064e61ce..f5a56f7e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java @@ -12,6 +12,9 @@ import java.io.IOException; import java.nio.file.Path; +/** + * プラグイン情報ファイルの読み込みを行うタスクです。 + */ public class DescriptionLoadTask extends InstallTask { private DescriptionLoadState taskState; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java index 3b711b15..02d2949c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java @@ -7,10 +7,17 @@ import java.nio.file.Path; +/** + * プラグイン情報ファイルを読み込むときに発生するシグナルです。 + */ @Data @AllArgsConstructor public class LoadPluginDescriptionSignal implements InstallerSignal { + /** + * プラグイン情報ファイルのパスです。 + * これを変更すると、読み込まれるプラグインを変更できます。 + */ @NotNull private Path pluginFile; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java index de1aeed2..a9bf1d55 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java @@ -9,13 +9,22 @@ import java.nio.file.Path; +/** + * ダウンロードの引数です。 + */ @Value @EqualsAndHashCode(callSuper = false) public class DownloadArgument extends TaskArgument { + /** + * ダウンロードするURLです。 + */ @NotNull String url; + /** + * ダウンロード先のパスです。 + */ @Nullable Path path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java index dffe331e..4d3ca47f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java @@ -1,10 +1,24 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; - +/** + * ダウンロードに失敗した際のエラーの原因を表します。 + */ public enum DownloadErrorCause { + /** + * サーバから、無効なレスポンスを受け取りました。 + */ ILLEGAL_HTTP_RESPONSE, + /** + * Body が空でした。 + */ NO_BODY_IN_RESPONSE, + /** + * {@link java.io.IOException} が発生しました。 + */ IO_EXCEPTION, + /** + * 不明なエラーが発生しました。 + */ UNKNOWN_ERROR } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java index 5347a6c5..06a5591e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java @@ -7,13 +7,25 @@ import java.nio.file.Path; +/** + * ダウンロードの結果を表すクラスです。 + */ @Getter public class DownloadResult extends TaskResult { + /** + * ダウンロード先のファイルのパスです。 + */ @Nullable private final Path path; + /** + * ダウンロードしたファイルのサイズです。 + */ private final long totalSize; + /** + * ダウンロードごとに発行される一意なIDです。 + */ @NotNull private final String downloadID; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadState.java index 8859b8a9..c8521075 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadState.java @@ -1,10 +1,21 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; - +/** + * ダウンロードの状態を表します。 + */ public enum DownloadState { + /** + * ダウンロードが初期化されたことを示します。 + */ INITIALIZED, + /** + * ダウンロードが開始中であることを示します。 + */ START_DOWNLOADING, + /** + * ダウンロード中であることを示します。 + */ DOWNLOADING, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java index 141b2124..bd79aedd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java @@ -16,6 +16,10 @@ import java.nio.file.Path; import java.util.UUID; +/** + * ファイルをダウンロードするタスクです。 + * プラグイン以外のファイルにも使用できます。 + */ public class DownloadTask extends InstallTask { private final String randomDownloadID; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java index e5872c6e..85e5a2bf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java @@ -6,12 +6,24 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * ダウンロードに失敗したことを示すシグナルです。 + */ @Value @EqualsAndHashCode(callSuper = true) public class DownloadErrorSignal extends DownloadSignal { + /** + * 失敗した理由です。 + */ @NotNull DownloadErrorCause cause; + /** + * 失敗した理由の詳細です。 + * 失敗した原因が、 + * {@link DownloadErrorCause#ILLEGAL_HTTP_RESPONSE} 出会った場合は、{@code 404 Not Found} のような{@link String}が、 + * {@link DownloadErrorCause#IO_EXCEPTION} 出会った場合は {@link Exception}が格納されます。 + */ @Nullable Object value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java index 23cfb835..4278bef1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java @@ -4,13 +4,26 @@ import lombok.Value; import org.jetbrains.annotations.NotNull; +/** + * ダウンロードの進捗を表すシグナルです。 + */ @Value @EqualsAndHashCode(callSuper = true) public class DownloadProgressSignal extends DownloadSignal { + /** + * ダウンロードしようとしているファイルのサイズです。 + */ long totalSize; + /** + * ダウンロードしたファイルのサイズです。 + */ long downloaded; + /** + * ダウンロードの進捗を表す値で、 {@code 0.0} から {@code 1.0} の間の値です。 + * {@code 0.5}は、ダウンロードが半分完了したことを表します。 + */ double percentage; public DownloadProgressSignal(@NotNull String downloadId, long totalSize, long downloaded, double percentage) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java index c55606f3..d7756845 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java @@ -4,9 +4,15 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; +/** + * ダウンロード時に発生するシグナルを表す、抽象クラスです。 + */ @Data public abstract class DownloadSignal implements InstallerSignal { + /** + * ダウンロードごとに発行される一意のIDです。 + */ @NotNull private final String downloadId; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java index b2b5a1e6..d567f05e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java @@ -6,12 +6,21 @@ import java.nio.file.Path; +/** + * ダウンロードの開始中であることを示すシグナルです。 + */ @Getter @Setter public class DownloadStartingSignal extends DownloadSignal { + /** + * ダウンロード先のパスです。 + */ @NotNull private Path downloadPath; + /** + * ダウンロードを行うURLです。 + */ @NotNull private String url; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java index 3e77f91c..c4bd54af 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java @@ -6,12 +6,21 @@ import java.nio.file.Path; +/** + * ダウンロードが完了したことを示すシグナルです。 + */ @Value @EqualsAndHashCode(callSuper = true) public class DownloadSucceedSignal extends DownloadSignal { + /** + * ダウンロードしたファイルのパスです。 + */ @NotNull Path downloadPath; + /** + * ダウンロードしたファイルのサイズです。 + */ long totalSize; public DownloadSucceedSignal(@NotNull String downloadId, @NotNull Path downloadPath, long totalSize) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java index 569188c1..a98cad97 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java @@ -10,15 +10,27 @@ import java.nio.file.Path; import java.util.List; +/** + * プラグインのインストール時に渡される引数です。 + */ @Value @EqualsAndHashCode(callSuper = false) public class PluginsInstallArgument extends TaskArgument { + /** + * プラグインのファイルのパスです。 + */ @NotNull Path pluginPath; + /** + * プラグインのプラグイン情報ファイルです。 + */ @NotNull PluginDescriptionFile pluginDescription; + /** + * 依存関係の要素です。 + */ @NotNull List dependencies; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java index c8fa8b79..aa2a7962 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java @@ -1,11 +1,29 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +/** + * プラグインのインストール時に発生したエラーの原因を表します。 + */ public enum PluginsInstallErrorCause { + /** + * プラグインの再配置に失敗しました。 + */ RELOCATE_FAILED, + /** + * 無効なプラグインが指定されました。 + */ INVALID_PLUGIN, + /** + * 無効なプラグイン情報ファイルが指定されました。 + */ INVALID_PLUGIN_DESCRIPTION, + /** + * {@link java.io.IOException} が発生しました。 + */ IO_EXCEPTION_OCCURRED, + /** + * 不明な例外が発生しました。 + */ EXCEPTION_OCCURRED } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java index abb711c4..fe464043 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java @@ -5,8 +5,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * プラグインのインストール結果を表すクラスです。 + */ public class PluginsInstallResult extends TaskResult { + /** + * インストールに失敗した場合、そのプラグインの名前が格納されます。 + */ @Getter @Nullable private final String failedPluginName; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java index 30e2d1e3..e1dd6519 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java @@ -1,11 +1,29 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +/** + * プラグインのインストールの状態を表します。 + */ public enum PluginsInstallState { + /** + * プラグインのインストールが初期化されたことを示します。 + */ INITIALIZED, + /** + * プラグインの再配置中であることを示します。 + */ PLUGIN_RELOCATING, + /** + * プラグインの読み込み中であることを示します。 + */ PLUGIN_LOADING, + /** + * プラグインの{@link org.bukkit.plugin.Plugin#onLoad()} の実行中であることを示します。 + */ ONLOAD_RUNNING, + /** + * プラグインの有効化中であることを示します。 + */ PLUGIN_ENABLING, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index eb3e4cba..b4b36c4b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -33,6 +33,9 @@ import java.util.ArrayList; import java.util.List; +/** + * プラグインをインストールするタスクです。 + */ public class PluginsInstallTask extends InstallTask { private static final Path PLUGIN_DIR; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginEnablingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginEnablingSignal.java index e69a889b..c94d6ccf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginEnablingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginEnablingSignal.java @@ -5,12 +5,23 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +/** + * プラグインの有効化中であることを示すシグナルです。 + * {@link org.bukkit.plugin.java.JavaPlugin#onEnable()} の呼び出しの前後にスローされます。 + * このシグナルより先に {@link PluginOnLoadRunningSignal} が呼ばれます。 + */ @Data public class PluginEnablingSignal implements InstallerSignal { + /** + * 対象のプラグインです。 + */ @NotNull private final Plugin plugin; + /** + * 有効化を行う前に送信されるシグナルです。 + */ public static class Pre extends PluginEnablingSignal { public Pre(@NotNull Plugin plugin) @@ -19,6 +30,9 @@ public Pre(@NotNull Plugin plugin) } } + /** + * 有効化を行った後に送信されるシグナルです。 + */ public static class Post extends PluginEnablingSignal { public Post(@NotNull Plugin plugin) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginInstallingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginInstallingSignal.java index 2c18a952..1e16914e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginInstallingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginInstallingSignal.java @@ -7,11 +7,20 @@ import java.nio.file.Path; +/** + * プラグインのインストール中であることを示すシグナルです。 + */ @Value public class PluginInstallingSignal implements InstallerSignal { + /** + * 対象のプラグインのパスです。 + */ @NotNull Path path; + /** + * 対象のプラグインの プラグイン情報ファイルです。 + */ @NotNull PluginDescriptionFile pluginDescription; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java index e303ba88..48b25985 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginLoadSignal.java @@ -9,14 +9,28 @@ import java.nio.file.Path; +/** + * プラグインの読み込み中であることを示すシグナルです。 + * {@link org.bukkit.plugin.PluginManager#loadPlugin(java.io.File)} の呼び出しの前後にスローされます。 + */ @Data public class PluginLoadSignal implements InstallerSignal { + /** + * 対象のプラグインのパスです。 + */ @NotNull private final Path pluginPath; + /** + * 対象のプラグインのプラグイン情報ファイルです。 + */ @NotNull private final PluginDescriptionFile pluginDescription; + /** + * 読み込みを行う前に送信されるシグナルです。 + * 注意:読み込みを行う前なので、 {@link Plugin} の取得はできません。 + */ public static class Pre extends PluginLoadSignal { public Pre(@NotNull Path pluginPath, @NotNull PluginDescriptionFile pluginDescription) @@ -25,8 +39,14 @@ public Pre(@NotNull Path pluginPath, @NotNull PluginDescriptionFile pluginDescri } } + /** + * 読み込みを行った後に送信されるシグナルです。 + */ public static class Post extends PluginLoadSignal { + /** + * 読み込まれたプラグインです。 + */ @NotNull @Getter private final Plugin plugin; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java index d7591754..9e989702 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java @@ -5,12 +5,21 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +/** + * プラグインの {@link Plugin#onLoad()} の実行の前後にスローされるシグナルです。 + */ @Data public class PluginOnLoadRunningSignal implements InstallerSignal { + /** + * 対象のプラグインです。 + */ @NotNull private final Plugin plugin; + /** + * {@link Plugin#onLoad()} の実行を行う前に送信されるシグナルです。 + */ public static class Pre extends PluginOnLoadRunningSignal { public Pre(@NotNull Plugin plugin) @@ -19,6 +28,9 @@ public Pre(@NotNull Plugin plugin) } } + /** + * {@link Plugin#onLoad()} の実行を行った後に送信されるシグナルです。 + */ public static class Post extends PluginOnLoadRunningSignal { public Post(@NotNull Plugin plugin) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginRelocatingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginRelocatingSignal.java index 310130b8..217e0fef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginRelocatingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/signals/PluginRelocatingSignal.java @@ -6,11 +6,21 @@ import java.nio.file.Path; +/** + * プラグインを、ダウンロードの仮ディレクトリからプラグインディレクトリに移動する際に送信されるシグナルです。 + */ @Data public class PluginRelocatingSignal implements InstallerSignal { + /** + * プラグインのパスです。 + */ @NotNull private final Path source; + /** + * 移動先のパスです。 + * デフォルトは {@code plugins/} です。 + */ @NotNull private Path target; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveArgument.java index 69f55369..0772a926 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveArgument.java @@ -5,10 +5,16 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; +/** + * プラグインの解決を行うタスクの引数です。 + */ @Data @EqualsAndHashCode(callSuper = false) public class PluginResolveArgument extends TaskArgument { + /** + * 解決する際に使用されるクエリです。 + */ @NotNull String query; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java index 7b995a48..5ee254ff 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java @@ -1,8 +1,16 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; - +/** + * プラグインの解決に失敗した理由を表します。 + */ public enum PluginResolveErrorCause { + /** + * 予期しない内部エラーが発生したことを示します。 + */ ILLEGAL_INTERNAL_STATE, + /** + * {@link net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult} が サーバまたはプラグインリゾルバから返されたことを示します。 + */ GOT_ERROR_RESULT } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java index fff78416..d7aff9b8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java @@ -6,8 +6,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * プラグインの解決を行うタスクの結果です。 + */ public class PluginResolveResult extends TaskResult { + /** + * 解決されたプラグインの解決結果です。 + */ @Getter @Nullable private final SuccessResult resolveResult; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveState.java index 588c1d1f..7de9f41a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveState.java @@ -1,13 +1,31 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; +/** + * プラグインの解決の状態を表します。 + */ public enum PluginResolveState { + /** + * プラグインの解決が初期化されたことを示します。 + */ INITIALIZED, + /** + * プラグインの解決が開始されたことを示します。 + */ PRE_RESOLVING, + /** + * プラグインの解決が完了したことを示します。 + */ PRE_RESOLVE_FINISHED, + /** + * 複数結果があった場合、どれを選択するかの選択中であることを示します。 + */ MULTI_RESOLVING, + /** + * プラグインの解決が完了したことを示します。 + */ RESOLVE_FINISHED } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java index 47daa27e..ec7cf892 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java @@ -15,6 +15,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * プラグインの解決を行うタスクです。 + */ public class PluginResolveTask extends InstallTask { private static final PluginResolver PLUGIN_RESOLVER; @@ -61,7 +64,7 @@ public PluginResolveTask(@NotNull InstallProgress progress, @NotNull Installe String query = arguments.getQuery(); this.taskState = PluginResolveState.PRE_RESOLVING; - this.postSignal(new PluginResolvingSignal(query, PLUGIN_RESOLVER)); + this.postSignal(new PluginResolvingSignal(PLUGIN_RESOLVER, query)); ResolveResult queryResolveResult = PLUGIN_RESOLVER.resolve(query); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java index d1db511a..2187546e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java @@ -7,15 +7,29 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * 複数のプラグインが解決されたことを示すシグナルです。 + */ @Data public class MultiplePluginResolvedSignal implements InstallerSignal { + /** + * 解決する際に使用されたクエリです。 + */ @NotNull private final String query; + /** + * 解決された複数のプラグインの結果です。 + */ @NotNull private final MultiResult results; + /** + * 明示的に指定するプラグインの解決結果です。 + * これに{@link net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult}を格納すると、使用するプラグインを一意に特定できます. + * {@code null} の場合は、自動的に選択されます。 + */ @Nullable private ResolveResult specifiedResult; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java index c5d38317..6f28fca8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java @@ -5,9 +5,15 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +/** + * プラグインの解決に失敗したことを示すシグナルです。 + */ @Data public class PluginResolveErrorSignal implements InstallerSignal { + /** + * 失敗したプラグインの解決結果です。 + */ @NonNull private final ErrorResult error; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java index eabf1a5f..bb57de73 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java @@ -5,9 +5,16 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; +/** + * プラグインが正常に解決されたことを示すシグナルです。 + */ @Data public class PluginResolvedSuccessfulSignal implements InstallerSignal { + /** + * 解決する際に使用されたクエリです。 + * 値を変更すると、解決されたプラグインが変更されます。 + */ @NotNull private SuccessResult resolvedPlugin; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java index 7ef46aa1..ee8eee01 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java @@ -5,10 +5,19 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +/** + * プラグインの解決中であることを示すシグナルです。 + */ @Data @AllArgsConstructor public class PluginResolvingSignal implements InstallerSignal { - private String query; + /** + * 解決に使用されるプラグインリゾルバです。 + */ private final PluginResolver resolver; + /** + * 解決する際に使用されるクエリです。 + */ + private String query; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java index 1d2a5a3d..5cb99449 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallArgument.java @@ -7,9 +7,15 @@ import java.util.List; +/** + * プラグインのアンインストールを行うタスクの引数です。 + */ @Value @EqualsAndHashCode(callSuper = false) public class UnInstallArgument extends TaskArgument { + /** + * アンインストールされるプラグインです。 + */ List plugins; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java index 1cb1520a..7d9b9a7d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallErrorCause.java @@ -1,11 +1,26 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; +/** + * アンインストールに失敗した理由を表します。 + */ public enum UnInstallErrorCause { + /** + * いくつかのプラグインのアンインストールに失敗しました。 + */ SOME_UNINSTALL_FAILED, + /** + * 内部:1つのプラグインのアンインストールに成功しました。 + */ INTERNAL_UNINSTALL_OK, + /** + * 内部:1つのプラグインの無効化に失敗しました。 + */ INTERNAL_PLUGIN_DISABLE_FAILED, + /** + * 内部:1つのプラグインのクラスのアンロードに失敗しました。 + */ INTERNAL_CLASS_UNLOAD_FAILED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java index 4735324e..b34248b0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallResult.java @@ -9,11 +9,20 @@ import java.util.List; import java.util.Map; +/** + * プラグインのアンインストールを行うタスクの結果です。 + */ public class UnInstallResult extends TaskResult { + /** + * アンインストールされたプラグインのプラグイン情報ファイルです。 + */ @Getter @NotNull private final List uninstalledPlugins; + /** + * アンインストールに失敗した理由です。 + */ @Getter @NotNull private final Map errors; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java index 9b804fed..b7aa2731 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallState.java @@ -1,14 +1,38 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; +/** + * アンインストールの状態を表します。 + */ public enum UnInstallState { + /** + * アンインストールが初期化されたことを示します。 + */ INITIALIZED, + /** + * アンインストールが開始されたことを示します。 + */ UNINSTALLING, + /** + * レシピの登録解除中であることを示します。 + */ RECIPES_UNREGISTERING, + /** + * コマンドのアンパッチ中であることを示します。 + */ COMMANDS_UNPATCHING, + /** + * プラグインの無効化中であることを示します。 + */ PLUGIN_DISABLING, + /** + * Bukkit からプラグインをアンロード中であることを示します。 + */ REMOVING_FROM_BUKKIT, + /** + * クラスのアンロード中であることを示します。 + */ CLASSES_UNLOADING } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index c43ba1c6..5b879291 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -34,6 +34,9 @@ import java.util.List; import java.util.Map; +/** + * プラグインをアンインストールするタスクです。 + */ public class UnInstallTask extends InstallTask { private static final PluginManager PLUGIN_MANAGER; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java index d0f3a7fe..26eca0d5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java @@ -5,12 +5,21 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +/** + * プラグインの無効化の前後にスローされるシグナルです。 + */ @Data public class PluginDisablingSignal implements InstallerSignal { + /** + * 無効化されるプラグインです。 + */ @NotNull private final Plugin plugin; + /** + * 無効化の前にスローされるシグナルです。 + */ public static class Pre extends PluginDisablingSignal { public Pre(@NotNull Plugin plugin) @@ -19,6 +28,9 @@ public Pre(@NotNull Plugin plugin) } } + /** + * 無効化の後にスローされるシグナルです。 + */ public static class Post extends PluginDisablingSignal { public Post(@NotNull Plugin plugin) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java index bda197cb..a3e5183f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java @@ -10,21 +10,40 @@ import java.util.Locale; +/** + * プラグインが登録したレシピについてのシグナルです。 + */ @Data public class PluginRegisteredRecipeSignal implements InstallerSignal { + /** + * レシピを登録したプラグインです。 + */ @NotNull private final Plugin plugin; + /** + * 登録されたレシピが1つ見つかった場合にスローされるシグナルです。 + */ @Getter @Setter public static class FoundOne extends PluginRegisteredRecipeSignal { + /** + * 使用されたシグニチャです。 + */ @NotNull private final String signatureNamespace; + /** + * 見つかったレシピです。 + */ @NotNull private final Recipe recipe; + /** + * 登録解除するかどうかを決めるフラグです。 + * デフォルトでは {@code true} です。 + */ private boolean doUnregister; public FoundOne(@NotNull Plugin plugin, @NotNull String signatureNamespace, @NotNull Recipe recipe) @@ -37,10 +56,17 @@ public FoundOne(@NotNull Plugin plugin, @NotNull String signatureNamespace, @Not } } + /** + * プラグインのレシピを検索する前にスローされるシグナルです。 + */ @Getter @Setter public static class Searching extends PluginRegisteredRecipeSignal { + /** + * 使用するシグニチャです。 + * デフォルトでは, プラグインの名前(Lower case)が使用されます。 + */ @NotNull private String[] targetNamespaces; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java index 7707b340..4ab9e605 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java @@ -6,20 +6,36 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +/** + * プラグインのアンロードの前後にスローされるシグナルです。 + */ public class PluginUnloadingSignal implements InstallerSignal { + /** + * アンロードの前にスローされるシグナルです。 + */ @Value @EqualsAndHashCode(callSuper = false) public static class Pre extends PluginUnloadingSignal { + /** + * アンロードされるプラグインです。 + */ @NotNull Plugin plugin; } + /** + * アンロードの後にスローされるシグナルです。 + */ @Value @EqualsAndHashCode(callSuper = false) public static class Post extends PluginUnloadingSignal { + /** + * アンロードされるプラグインの名前です。 + * 注意:アンロード後なので、{@link Plugin}のインスタンスは取得できません(VMから削除されています)。 + */ @NotNull String pluginName; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java index 97e02447..fa76d691 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/CommandsPatcher.java @@ -19,7 +19,7 @@ import java.util.Map; /** - * Bukkitのコマンドをラップするクラス。 + * Bukkitのコマンドをパッチするクラスです。 */ public class CommandsPatcher { @@ -154,6 +154,11 @@ private void initReflections() } } + /** + * CommandMapを取得します。 + * + * @return CommandMap + */ public CommandMap getCommandMap() { try @@ -166,11 +171,22 @@ public CommandMap getCommandMap() } } + /** + * 知られているコマンドを取得します。 + * + * @return 知られているコマンド + */ public Map getKnownCommands() { return this.getCommandMap().getKnownCommands(); } + /** + * コマンドをラップします。 + * + * @param command ラップするコマンド + * @param alias コマンドのエイリアス + */ public void wrapCommand(Command command, String alias) { try @@ -184,6 +200,9 @@ public void wrapCommand(Command command, String alias) } } + /** + * CraftServerのsyncCommandsを呼び出す。 + */ public void syncCommandsCraftBukkit() { try @@ -201,6 +220,12 @@ public void unWrapCommand(String command) iBrigadierCommandDispatcher.getRoot().removeCommand(command); } + /** + * コマンドをパッチします。 + * + * @param plugin プラグイン + * @param updatePlayer プレイヤーにコマンドの変更を通知するか({@link Player#updateCommands()}) + */ public void patchCommand(@NotNull Plugin plugin, boolean updatePlayer) { Map commandMap = this.getKnownCommands(); @@ -219,11 +244,22 @@ public void patchCommand(@NotNull Plugin plugin, boolean updatePlayer) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); } + /** + * コマンドをパッチします。 + * + * @param plugin パッチするプラグイン + */ public void patchCommand(@NotNull Plugin plugin) { this.patchCommand(plugin, true); } + /** + * コマンドをアンパッチします。 + * + * @param plugin アンパッチするプラグイン + * @param updatePlayer プレイヤーにコマンドの変更を通知するか({@link Player#updateCommands()}) + */ public void unPatchCommand(@NotNull Plugin plugin, boolean updatePlayer) { Map commandMap = this.getKnownCommands(); @@ -265,6 +301,11 @@ public void unPatchCommand(@NotNull Plugin plugin, boolean updatePlayer) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); } + /** + * コマンドをアンパッチします。 + * + * @param plugin プラグイン + */ public void unPatchCommand(@NotNull Plugin plugin) { this.unPatchCommand(plugin, true); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java index d5d8198e..7e15d48e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java @@ -96,7 +96,7 @@ private void initReflections() } /** - * プラグインを読み込みます. + * プラグインを読み込みます。 * * @param pluginPath プラグインのパス * @return プラグインの読み込み結果 @@ -146,6 +146,11 @@ public PluginLoadResult loadPlugin(@NotNull Path pluginPath) return PluginLoadResult.OK; } + /** + * プラグインをアンロードします。 + * + * @param plugin アンロードするプラグイン + */ public void unloadPlugin(@NotNull Plugin plugin) { this.getPluginRecipes(plugin.getName()) @@ -268,6 +273,11 @@ private List getPluginRecipes(String pluginName) return result; } + /** + * プラグインを再読み込みします。 + * + * @param plugin 再読み込みするプラグイン + */ public void reloadPlugin(Plugin plugin) { Path pluginPath = PluginUtil.getFile(plugin).toPath(); From f208fd784d079582b21242d8bc49a55e6e77b9c3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 5 Sep 2022 01:07:40 +0900 Subject: [PATCH 224/745] refactor: Remove unused method(chained Argument) as safety --- .../plugin/installer/task/TaskArgument.java | 17 ----------------- .../collector/DependsCollectArgument.java | 14 -------------- .../computer/DependsComputeOrderArgument.java | 9 --------- .../description/DescriptionLoadArgument.java | 11 ----------- .../task/tasks/download/DownloadArgument.java | 11 ----------- 5 files changed, 62 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java index 489496ef..f3b3adc2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java @@ -1,25 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; -import lombok.Getter; - /** * タスクの引数を表します。 */ public abstract class TaskArgument { - @Getter - private final boolean chain; - - public TaskArgument(TaskResult previousTaskResult) - { - this.chain = true; - if (!previousTaskResult.isSuccess()) - throw new IllegalStateException("Previous must be successful"); - - } - - public TaskArgument() - { - this.chain = false; - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java index 26db8790..1ad87412 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java @@ -3,7 +3,6 @@ import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadResult; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -32,19 +31,6 @@ public class DependsCollectArgument extends TaskArgument @NotNull List alreadyInstalledPlugins; - public DependsCollectArgument(@NotNull DescriptionLoadResult descriptionLoadResult) - { - super(descriptionLoadResult); - - if (descriptionLoadResult.getDescription() == null) - throw new IllegalStateException("descriptionLoadResult.description is null"); - this.pluginDescription = descriptionLoadResult.getDescription(); - - this.alreadyInstalledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() - .map(plugin -> plugin.getDescription().getName()) - .collect(Collectors.toList()); - } - public DependsCollectArgument(@NotNull PluginDescriptionFile pluginDescription, @NotNull List alreadyInstalledPlugins) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java index 9e75b3db..3364a9c3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java @@ -4,8 +4,6 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectResult; -import org.jetbrains.annotations.NotNull; import java.util.List; @@ -20,11 +18,4 @@ public class DependsComputeOrderArgument extends TaskArgument */ @Getter private final List collectedDependencies; - - public DependsComputeOrderArgument(@NotNull DependsCollectResult previousTaskResult) - { - super(previousTaskResult); - - this.collectedDependencies = previousTaskResult.getCollectedPlugins(); - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java index 2e07fa48..b7390bf3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java @@ -3,7 +3,6 @@ import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; @@ -25,14 +24,4 @@ public DescriptionLoadArgument(@NotNull Path pluginFile) { this.pluginFile = pluginFile; } - - public DescriptionLoadArgument(DownloadResult previousTaskResult) - { - super(previousTaskResult); - - if (previousTaskResult.getPath() == null) - throw new IllegalArgumentException("DownloadResult.path is null"); - - this.pluginFile = previousTaskResult.getPath(); - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java index a9bf1d55..77eab308 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java @@ -3,7 +3,6 @@ import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,14 +39,4 @@ public DownloadArgument(@NotNull String url) this.path = null; } - public DownloadArgument(@NotNull PluginResolveResult pluginResolveResult) - { - super(pluginResolveResult); - - if (pluginResolveResult.getResolveResult() == null) - throw new IllegalArgumentException("Plugin Resolving must be successful"); - - this.url = pluginResolveResult.getResolveResult().getDownloadUrl(); - this.path = null; - } } From 983a289c7a7880fd500df967c8d683a1a1190a6d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 5 Sep 2022 01:08:54 +0900 Subject: [PATCH 225/745] refactor: Remove unused GSON reference --- .../tasks/dependencies/collector/DependsCollectStatus.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index a292aca9..ddb9548c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -1,7 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; @@ -23,9 +21,6 @@ @AllArgsConstructor public class DependsCollectStatus { - private static final Gson gson = new GsonBuilder() - .excludeFieldsWithoutExposeAnnotation() - .create(); /** * 割り当てられたインストールIDです。 */ From 19169a2edea832ff71ecfe4c94aefd042e4eebb3 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Mon, 5 Sep 2022 01:10:12 +0900 Subject: [PATCH 226/745] refactor: Remove verbose method of DependsCollectResult --- .../dependencies/collector/DependsCollectResult.java | 9 ++------- .../tasks/dependencies/collector/DependsCollectTask.java | 5 ++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java index 8fa7875b..388fb8fa 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java @@ -38,19 +38,14 @@ public class DependsCollectResult extends TaskResult collectFailedPlugins; - public DependsCollectResult(boolean success, @NotNull DependsCollectState taskState, + public DependsCollectResult(@NotNull DependsCollectState taskState, @Nullable DependsCollectErrorCause errorCause, @NotNull String targetPlugin, @NotNull List collectedPlugins, @NotNull List collectFailedPlugins) { - super(success, taskState, errorCause); + super(!collectedPlugins.isEmpty(), taskState, errorCause); this.targetPlugin = targetPlugin; this.collectedPlugins = collectedPlugins; this.collectFailedPlugins = collectFailedPlugins; } - - public boolean hasErrors() - { - return !collectFailedPlugins.isEmpty(); - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 0c27413a..5a41c1d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -142,9 +142,8 @@ public DependsCollectTask(@NotNull InstallProgress progress, @NotNull Install if (!success) this.postSignal(new DependsCollectFailedSignal(collectFailedDependencies)); - return new DependsCollectResult( - success, this.taskState, errorCause, - pluginName, this.status.getCollectedDependencies(), collectFailedDependencies + return new DependsCollectResult(this.taskState, errorCause, pluginName, + this.status.getCollectedDependencies(), collectFailedDependencies ); } From badd55190f02e90ac82573785df6cdc06ed3cad6 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 06:55:26 +0900 Subject: [PATCH 227/745] refactor: resolver => plugin.resolver --- .../TeamKunPluginManager.java | 14 +++++++------- .../commands/CommandResolve.java | 16 ++++++++-------- .../teamkunpluginmanager/plugin/Installer.java | 8 ++++---- .../collector/DependsCollectTask.java | 4 ++-- .../tasks/resolve/PluginResolveErrorCause.java | 4 +++- .../task/tasks/resolve/PluginResolveResult.java | 2 +- .../task/tasks/resolve/PluginResolveTask.java | 10 +++++----- .../signals/MultiplePluginResolvedSignal.java | 7 ++++--- .../signals/PluginResolveErrorSignal.java | 2 +- .../signals/PluginResolvedSuccessfulSignal.java | 2 +- .../resolve/signals/PluginResolvingSignal.java | 2 +- .../{ => plugin}/resolver/PluginResolver.java | 12 ++++++------ .../{ => plugin}/resolver/QueryContext.java | 2 +- .../resolver/impl/BruteforceGitHubResolver.java | 12 ++++++------ .../resolver/impl/CurseBukkitResolver.java | 12 ++++++------ .../resolver/impl/CurseBukkitSuccessResult.java | 6 +++--- .../resolver/impl/GitHubSuccessResult.java | 8 ++++---- .../resolver/impl/GitHubURLResolver.java | 14 +++++++------- .../resolver/impl/KnownPluginsResolver.java | 14 +++++++------- .../resolver/impl/OmittedGitHubResolver.java | 12 ++++++------ .../resolver/impl/SpigotMCResolver.java | 12 ++++++------ .../resolver/impl/SpigotMCSuccessResult.java | 10 +++++----- .../resolver/interfaces/BaseResolver.java | 10 +++++----- .../resolver/interfaces/URLResolver.java | 8 ++++---- .../resolver/result/ErrorResult.java | 4 ++-- .../resolver/result/MarketplaceResult.java | 2 +- .../resolver/result/MultiResult.java | 4 ++-- .../resolver/result/PipeResult.java | 6 +++--- .../resolver/result/ResolveResult.java | 4 ++-- .../resolver/result/SuccessResult.java | 4 ++-- .../resolver/result/VersionedResult.java | 2 +- .../resolver/PluginResolverTest.java | 17 +++++++++-------- 32 files changed, 125 insertions(+), 121 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/PluginResolver.java (91%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/QueryContext.java (96%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/BruteforceGitHubResolver.java (81%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/CurseBukkitResolver.java (92%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/CurseBukkitSuccessResult.java (90%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/GitHubSuccessResult.java (84%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/GitHubURLResolver.java (92%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/KnownPluginsResolver.java (61%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/OmittedGitHubResolver.java (62%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/SpigotMCResolver.java (91%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/impl/SpigotMCSuccessResult.java (72%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/interfaces/BaseResolver.java (78%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/interfaces/URLResolver.java (93%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/result/ErrorResult.java (94%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/result/MarketplaceResult.java (88%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/result/MultiResult.java (65%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/result/PipeResult.java (60%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/result/ResolveResult.java (87%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/result/SuccessResult.java (89%) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/{ => plugin}/resolver/result/VersionedResult.java (79%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 682d7f90..15b82efd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -21,13 +21,13 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.BruteforceGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.KnownPluginsResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.BruteforceGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubURLResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.KnownPluginsResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Session; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java index 93b9e78c..b686c33e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java @@ -3,14 +3,14 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import net.kyori.adventure.text.TextComponent; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 52a0cca5..a6f906d5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -10,10 +10,10 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.HashLib; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 5a41c1d8..a3362959 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -17,8 +17,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java index 5ee254ff..7932022b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java @@ -1,5 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; + /** * プラグインの解決に失敗した理由を表します。 */ @@ -10,7 +12,7 @@ public enum PluginResolveErrorCause */ ILLEGAL_INTERNAL_STATE, /** - * {@link net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult} が サーバまたはプラグインリゾルバから返されたことを示します。 + * {@link ErrorResult} が サーバまたはプラグインリゾルバから返されたことを示します。 */ GOT_ERROR_RESULT } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java index d7aff9b8..7fcadd50 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveResult.java @@ -2,7 +2,7 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java index ec7cf892..52315368 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java @@ -7,11 +7,11 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolvingSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java index 2187546e..9e542bb3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java @@ -2,8 +2,9 @@ import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +28,7 @@ public class MultiplePluginResolvedSignal implements InstallerSignal /** * 明示的に指定するプラグインの解決結果です。 - * これに{@link net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult}を格納すると、使用するプラグインを一意に特定できます. + * これに{@link SuccessResult}を格納すると、使用するプラグインを一意に特定できます. * {@code null} の場合は、自動的に選択されます。 */ @Nullable diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java index 6f28fca8..960445d5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java @@ -3,7 +3,7 @@ import lombok.Data; import lombok.NonNull; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; /** * プラグインの解決に失敗したことを示すシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java index bb57de73..4fb3d274 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java @@ -2,7 +2,7 @@ import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java index ee8eee01..2f6e7d3c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/PluginResolvingSignal.java @@ -3,7 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; /** * プラグインの解決中であることを示すシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/PluginResolver.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/PluginResolver.java index 92fcefe3..51b41a06 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/PluginResolver.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.PipeResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.PipeResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import java.net.MalformedURLException; import java.net.URL; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/QueryContext.java similarity index 96% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/QueryContext.java index bfe4ba2e..2db0b023 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/QueryContext.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/BruteforceGitHubResolver.java similarity index 81% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/BruteforceGitHubResolver.java index 5a01e594..a4d29b5c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/BruteforceGitHubResolver.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import lombok.AllArgsConstructor; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitResolver.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitResolver.java index 6e4cd265..17c53121 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitResolver.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitSuccessResult.java similarity index 90% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitSuccessResult.java index 2c06971d..9fd44b6e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitSuccessResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubSuccessResult.java similarity index 84% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubSuccessResult.java index 49de5960..c85ff416 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubSuccessResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java index b428b095..5f4b0137 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java similarity index 61% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java index 4057e0d8..2bf2e813 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; public class KnownPluginsResolver implements BaseResolver { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/OmittedGitHubResolver.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/OmittedGitHubResolver.java index b884553f..0d44673a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/OmittedGitHubResolver.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.PipeResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.PipeResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import org.apache.commons.lang.StringUtils; public class OmittedGitHubResolver implements BaseResolver diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCResolver.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCResolver.java index c9c22cb4..c0a584c1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCResolver.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCSuccessResult.java similarity index 72% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCSuccessResult.java index fa3125a8..736b50d7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCSuccessResult.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.VersionedResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.VersionedResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/BaseResolver.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/BaseResolver.java index 8bb5ef8a..c4b0ec8d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/BaseResolver.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; /** * プラグインリゾルバのインターフェース diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/URLResolver.java similarity index 93% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/URLResolver.java index 6827ca6b..01c1afce 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/URLResolver.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import java.net.MalformedURLException; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ErrorResult.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ErrorResult.java index 7f750a6a..9b5a9334 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ErrorResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; import lombok.EqualsAndHashCode; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MarketplaceResult.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MarketplaceResult.java index 1f52af46..173b6b5f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MarketplaceResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; /** * 紹介文付きのリソースの解決結果を格納。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MultiResult.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MultiResult.java index bcad38e3..471db22c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MultiResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; /** * 解決結果が複数ある場合に返されるクラス。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/PipeResult.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/PipeResult.java index 8c70e55a..81018427 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/PipeResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ResolveResult.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ResolveResult.java index 9bc2eaa7..e741a2bd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ResolveResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; /** * プラグイン解決結果のインタフェース diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/SuccessResult.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/SuccessResult.java index 37c8d044..22f6270f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/SuccessResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/VersionedResult.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/VersionedResult.java index 5f50f1c9..0b254023 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/VersionedResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; import java.util.List; diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java index 39bd609a..f6b0427c 100644 --- a/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java +++ b/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java @@ -1,13 +1,14 @@ package net.kunmc.lab.teamkunpluginmanager.resolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubURLResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; import org.junit.Ignore; import org.junit.Test; From 099fb315dea4f7dbbf4cebdd96c75dece741686f Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 08:46:15 +0900 Subject: [PATCH 228/745] feat: SignalHandleManager --- .../commands/debug/CommandInstallDebug.java | 2 +- .../commands/debug/CommandUninstallDebug.java | 2 +- .../commands/debug/DebugSignalHandler.java | 17 +++- .../plugin/AbstractInstaller.java | 8 +- .../plugin/installer/InstallProgress.java | 9 +- .../installer/InstallerSignalHandler.java | 19 ----- .../impls/install/PluginInstaller.java | 4 +- .../impls/uninstall/PluginUninstaller.java | 4 +- .../plugin/installer/task/InstallTask.java | 4 +- .../collector/DependsCollectTask.java | 6 +- .../computer/DependsComputeOrderTask.java | 4 +- .../description/DescriptionLoadTask.java | 4 +- .../task/tasks/download/DownloadTask.java | 4 +- .../tasks/install/PluginsInstallTask.java | 4 +- .../task/tasks/resolve/PluginResolveTask.java | 4 +- .../task/tasks/uninstall/UnInstallTask.java | 4 +- .../plugin/signal/SignalHandleManager.java | 82 +++++++++++++++++++ .../plugin/signal/SignalHandler.java | 16 ++++ .../plugin/signal/SignalHandlerList.java | 78 ++++++++++++++++++ 19 files changed, 221 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java index 793fe7bb..429a13a8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java @@ -29,7 +29,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, Runner.runAsync(() -> { try { - PluginInstaller installer = new PluginInstaller(new DebugSignalHandler(terminal)); + PluginInstaller installer = new PluginInstaller(DebugSignalHandler.toManager(terminal)); InstallResult installResult = installer.execute(query); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java index 1528ce90..77301c9f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java @@ -32,7 +32,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, Runner.runAsync(() -> { try { - PluginUninstaller installer = new PluginUninstaller(new DebugSignalHandler(terminal)); + PluginUninstaller installer = new PluginUninstaller(DebugSignalHandler.toManager(terminal)); InstallResult installResult = installer.execute(query); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 097d284f..029ff38a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -6,10 +6,11 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -22,7 +23,7 @@ import java.util.Map; @AllArgsConstructor -public class DebugSignalHandler implements InstallerSignalHandler +public class DebugSignalHandler { private static final int MAX_INDENT = 5; @@ -234,8 +235,16 @@ private static void varDump(Object o, Terminal terminal) varDump(o, terminal, 0, false); } - @Override - public void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal) + public static SignalHandleManager toManager(Terminal terminal) + { + SignalHandleManager signalHandleManager = new SignalHandleManager(); + signalHandleManager.register(new DebugSignalHandler(terminal)); + + return signalHandleManager; + } + + @SignalHandler + public void handleAll(@NotNull InstallProgress installProgress, InstallerSignal signal) { if (!(signal instanceof DownloadProgressSignal)) printSignal(signal, terminal); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index 2e163ba4..e6a058a9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -6,24 +6,24 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.GeneralTaskErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskChain; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; -public abstract class AbstractInstaller, P extends Enum

> +public abstract class AbstractInstaller, P extends Enum

> // TODO: Eなんこれ? { @Getter protected final InstallProgress

progress; - protected final InstallerSignalHandler signalHandler; + protected final SignalHandleManager signalHandler; - public AbstractInstaller(InstallerSignalHandler signalHandler) throws IOException + public AbstractInstaller(SignalHandleManager signalHandler) throws IOException { this.progress = InstallProgress.of(signalHandler, null); this.signalHandler = signalHandler; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 70f2e241..061e6273 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -6,6 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectStatus; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.apache.commons.io.FileUtils; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -77,7 +78,7 @@ public class InstallProgress> /** * {@link InstallerSignal} を受け取るためのリスナーです。 */ - private final InstallerSignalHandler signalHandler; + private final SignalHandleManager signalHandler; /** * 依存関係の解決の状態を表します。 */ @@ -88,7 +89,7 @@ public class InstallProgress> @Setter private T currentTask; - private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable String id) throws IOException, SecurityException + private InstallProgress(@NotNull SignalHandleManager signalHandler, @Nullable String id) throws IOException, SecurityException { this.signalHandler = signalHandler; @@ -117,14 +118,14 @@ private InstallProgress(@NotNull InstallerSignalHandler signalHandler, @Nullable /** * このインスタンスを取得します。 * - * @param signalHandler インストールに使用する {@link InstallerSignalHandler} + * @param signalHandler インストールに使用する {@link SignalHandleManager} * @param id インストールに割り当てる一意のID * @param

インストールの進捗状況の型 * @return インスタンス * @throws IOException ディレクトリの作成に失敗した場合 * @throws SecurityException ディレクトリの作成に失敗した場合 */ - public static

> InstallProgress

of(@NotNull InstallerSignalHandler signalHandler, + public static

> InstallProgress

+ *     public void methodName({@link InstallProgress<>}, {@link InstallerSignal})
+ * 
+ */ +public class SignalHandleManager +{ + private final List> handlerLists; + + public SignalHandleManager() + { + handlerLists = new ArrayList<>(); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + private static void invokeHandler(@NotNull InstallProgress installProgress, SignalHandlerList handler, + InstallerSignal signal) + { + if (handler.isSignalType(signal.getClass())) + handler.onSignal(installProgress, signal); + } + + @SuppressWarnings("unchecked") + private static List> enumerateHandlers(Object object) + { + return Arrays.stream(object.getClass().getMethods()).parallel() + .filter(method -> method.isAnnotationPresent(SignalHandler.class)) + .filter(method -> method.getParameterCount() == 2) + .map(method -> method.getParameterTypes()[1]) + .filter(InstallerSignal.class::isAssignableFrom) + .map(clazz -> (Class) clazz) + .collect(Collectors.toList()); + } + + /** + * ハンドラを登録します。 + * + * @param object ハンドラを持つオブジェクト + */ + public void register(Object object) + { + List> handleTargetClasses = enumerateHandlers(object); + + for (SignalHandlerList handlerList : handlerLists) + { + handlerList.bakeAll(object); + handleTargetClasses.removeIf(handlerList::isSignalType); + } + + for (Class handleTargetClass : handleTargetClasses) + { + SignalHandlerList handlerList = new SignalHandlerList<>(handleTargetClass); + handlerLists.add(handlerList); + handlerList.bakeAll(object); + } + } + + /** + * シグナルを受け取り、処理を行います。 + * + * @param installProgress インストールの進捗 + * @param signal シグナル + */ + public void handleSignal(@NotNull InstallProgress installProgress, InstallerSignal signal) + { + for (SignalHandlerList handlerList : handlerLists) + invokeHandler(installProgress, handlerList, signal); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandler.java new file mode 100644 index 00000000..b7a07c86 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandler.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.signal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * シグナルを受け取るメソッドに付与するアノテーションです。 + * このアノテーションが付与されたメソッドは、シグナルを受け取ることができます。 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface SignalHandler +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java new file mode 100644 index 00000000..3dac71e4 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java @@ -0,0 +1,78 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.signal; + +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +class SignalHandlerList +{ + @NotNull + private final Class signalType; + + @NotNull + private final List> handlers; + + SignalHandlerList(@NotNull Class signalType) + { + this.signalType = signalType; + + this.handlers = new ArrayList<>(); + } + + private boolean isBaked(Method method) + { + return handlers.stream().parallel() + .map(Pair::getRight) + .anyMatch(method::equals); + } + + public void bakeAll(Object object) + { + synchronized (handlers) + { + Arrays.stream(object.getClass().getMethods()).parallel() + .filter(method -> method.isAnnotationPresent(SignalHandler.class)) + .filter(method -> !this.isBaked(method)) + .filter(method -> method.getParameterCount() == 2) + .filter(method -> signalType.isAssignableFrom(method.getParameterTypes()[1])) + .forEach(method -> { + method.setAccessible(true); + + if (Modifier.isStatic(method.getModifiers())) + handlers.add(new Pair<>(null, method)); + else + handlers.add(new Pair<>(object, method)); + }); + } + } + + void onSignal(InstallProgress installProgress, T signal) + { + synchronized (handlers) + { + handlers.forEach(pair -> { + try + { + pair.getRight().invoke(pair.getLeft(), installProgress, signal); + } + catch (Exception e) + { + e.printStackTrace(); + } + }); + } + } + + boolean isSignalType(Class type) + { + return signalType.isAssignableFrom(type); + } +} From 791998feea8f2d96f4fd40e66387557b5e100c17 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 14:44:06 +0900 Subject: [PATCH 229/745] feat: Create base of head --- .../TeamKunPluginManager.java | 3 + .../plugin/AbstractInstaller.java | 6 +- .../installer/InstallFailedInstallResult.java | 4 +- .../plugin/installer/InstallManager.java | 83 +++++++++++++++++++ .../plugin/installer/InstallProgress.java | 36 ++++++-- .../plugin/signal/SignalHandleManager.java | 18 +++- 6 files changed, 135 insertions(+), 15 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 15b82efd..682e02f0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -20,6 +20,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallManager; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.BruteforceGitHubResolver; @@ -50,6 +51,7 @@ public final class TeamKunPluginManager extends JavaPlugin private Session session; private PluginResolver resolver; private CommandManager commandManager; + private InstallManager installManager; private static void setupDependencyTree(TeamKunPluginManager plugin) { @@ -131,6 +133,7 @@ public void onEnable() pluginConfig = getConfig(); resolver = new PluginResolver(); commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); + installManager = new InstallManager(this); new PluginLoader(); // Initialize plugin loader registerCommands(commandManager); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index e6a058a9..deda7c56 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -17,15 +17,15 @@ import java.io.File; import java.io.IOException; -public abstract class AbstractInstaller, P extends Enum

> // TODO: Eなんこれ? +public abstract class AbstractInstaller, P extends Enum

> { @Getter - protected final InstallProgress

progress; + protected final InstallProgress> progress; protected final SignalHandleManager signalHandler; public AbstractInstaller(SignalHandleManager signalHandler) throws IOException { - this.progress = InstallProgress.of(signalHandler, null); + this.progress = InstallProgress.of(this, signalHandler, null); this.signalHandler = signalHandler; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index 2d767b6a..a49d589e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -20,14 +20,14 @@ public class InstallFailedInstallResult

, T extends Enum, S @Nullable private final S taskStatus; - public InstallFailedInstallResult(@NotNull InstallProgress

progress, @NotNull T reason, @NotNull S taskStatus) + public InstallFailedInstallResult(@NotNull InstallProgress progress, @NotNull T reason, @NotNull S taskStatus) { super(false, progress); this.reason = reason; this.taskStatus = taskStatus; } - public InstallFailedInstallResult(InstallProgress

progress, @NotNull T reason) + public InstallFailedInstallResult(InstallProgress progress, @NotNull T reason) { super(false, progress); this.reason = reason; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java new file mode 100644 index 00000000..43217c7e --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -0,0 +1,83 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; + +/** + * プラグインのインストールを管理するクラスです。 + */ +public class InstallManager +{ + private final TeamKunPluginManager pluginManager; + private final SignalHandleManager signalHandleManager; + + private InstallProgress runningInstall; + + public InstallManager(@NotNull TeamKunPluginManager pluginManager) + { + this.pluginManager = pluginManager; + this.signalHandleManager = new SignalHandleManager(); + + this.runningInstall = null; + } + + /** + * インストールが進行中かどうかを返します。 + * + * @return インストールが進行中かどうか + */ + public boolean isRunning() + { + if (runningInstall == null) + return false; + + if (runningInstall.isFinished()) + { + runningInstall = null; + return false; + } + + return true; + } + + /** + * インストールを実行します。 + * + * @param query インストールするプラグインのクエリ + * @throws IllegalStateException インストールが進行中の場合 + * @throws IOException 予期しない例外が発生した場合 + */ + public void runInstall(@NotNull String query) throws IllegalStateException, IOException + { + if (isRunning()) + throw new IllegalStateException("他のインストールが実行中です。"); + + PluginInstaller installer = new PluginInstaller(signalHandleManager); + runningInstall = installer.getProgress(); + + installer.execute(query); + } + + /** + * アンインストールを実行します。 + * + * @param query アンインストールするプラグインのクエリ + * @throws IllegalStateException インストールが進行中の場合 + * @throws IOException 予期しない例外が発生した場合 + */ + public void runUninstall(@NotNull String query) throws IllegalStateException, IOException + { + if (isRunning()) + throw new IllegalStateException("他のインストールが実行中です。"); + + PluginUninstaller uninstaller = new PluginUninstaller(signalHandleManager); + runningInstall = uninstaller.getProgress(); + + uninstaller.execute(query); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 061e6273..4d600caf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectStatus; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; @@ -26,13 +27,18 @@ * @param インストーラの状態の型 */ @Getter -public class InstallProgress> +public class InstallProgress, I extends AbstractInstaller> { @Getter(AccessLevel.NONE) - private static final HashMap> PROGRESS_CACHES; + private static final HashMap> PROGRESS_CACHES; @Getter(AccessLevel.NONE) private static final Path CACHE_DIRECTORY; + /** + * インストーラです。 + */ + private final I installer; + /** * アップグレードされたプラグインの名前です。 */ @@ -89,8 +95,17 @@ public class InstallProgress> @Setter private T currentTask; - private InstallProgress(@NotNull SignalHandleManager signalHandler, @Nullable String id) throws IOException, SecurityException + /** + * インストールが終了したかどうかを表します。 + */ + private boolean finished; + + private InstallProgress(@NotNull I installer, + @NotNull SignalHandleManager signalHandler, + @Nullable String id) + throws IOException, SecurityException { + this.installer = installer; this.signalHandler = signalHandler; this.upgraded = new ArrayList<>(); @@ -112,6 +127,8 @@ private InstallProgress(@NotNull SignalHandleManager signalHandler, @Nullable St this.dependsCollectStatus = new DependsCollectStatus(this); + this.finished = false; + PROGRESS_CACHES.put(this.getInstallActionID(), this); } @@ -125,13 +142,16 @@ private InstallProgress(@NotNull SignalHandleManager signalHandler, @Nullable St * @throws IOException ディレクトリの作成に失敗した場合 * @throws SecurityException ディレクトリの作成に失敗した場合 */ - public static

> InstallProgress

of(@NotNull SignalHandleManager signalHandler, - @Nullable String id) throws IOException, SecurityException + public static

, PI extends AbstractInstaller> InstallProgress of( + @NotNull PI installer, + @NotNull SignalHandleManager signalHandler, + @Nullable String id) + throws IOException, SecurityException { if (id == null) - return new InstallProgress<>(signalHandler, null); + return new InstallProgress<>(installer, signalHandler, null); else - return (InstallProgress

) PROGRESS_CACHES.get(id); + return (InstallProgress) PROGRESS_CACHES.get(id); } private void removeFromAll(@NotNull String name) @@ -222,5 +242,7 @@ public void finish() } PROGRESS_CACHES.remove(this.getInstallActionID()); + + this.finished = true; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java index 982215f4..c9bf130a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java @@ -18,7 +18,7 @@ */ public class SignalHandleManager { - private final List> handlerLists; + private final ArrayList> handlerLists; public SignalHandleManager() { @@ -26,7 +26,7 @@ public SignalHandleManager() } @SuppressWarnings({"rawtypes", "unchecked"}) - private static void invokeHandler(@NotNull InstallProgress installProgress, SignalHandlerList handler, + private static void invokeHandler(@NotNull InstallProgress installProgress, SignalHandlerList handler, InstallerSignal signal) { if (handler.isSignalType(signal.getClass())) @@ -74,9 +74,21 @@ public void register(Object object) * @param installProgress インストールの進捗 * @param signal シグナル */ - public void handleSignal(@NotNull InstallProgress installProgress, InstallerSignal signal) + public void handleSignal(@NotNull InstallProgress installProgress, InstallerSignal signal) { for (SignalHandlerList handlerList : handlerLists) invokeHandler(installProgress, handlerList, signal); } + + /** + * このインスタンスをコピーします。 + * + * @return コピーされたインスタンス + */ + public SignalHandleManager copy() + { + SignalHandleManager manager = new SignalHandleManager(); + manager.handlerLists.addAll(handlerLists); + return manager; + } } From 934a278bc4c2e41a50b6091dba625550b403c9ee Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 14:48:21 +0900 Subject: [PATCH 230/745] fix: Condition checking --- .../teamkunpluginmanager/plugin/installer/InstallManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index 43217c7e..dc3abfde 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -49,13 +49,15 @@ public boolean isRunning() * インストールを実行します。 * * @param query インストールするプラグインのクエリ - * @throws IllegalStateException インストールが進行中の場合 + * @throws IllegalStateException インストールが進行中の場合または GitHub にログインしていない場合 * @throws IOException 予期しない例外が発生した場合 */ public void runInstall(@NotNull String query) throws IllegalStateException, IOException { if (isRunning()) throw new IllegalStateException("他のインストールが実行中です。"); + if (!this.pluginManager.isTokenAvailable()) + throw new IllegalStateException("GitHubにログインしていません。"); PluginInstaller installer = new PluginInstaller(signalHandleManager); runningInstall = installer.getProgress(); From 9d9e1dc1877002477e9edeaa67683ba5c107c10d Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 15:00:53 +0900 Subject: [PATCH 231/745] feat: Smart task fail handling: TaskFailedException --- .../installer/InstallSignalHandler.java | 15 +++++++++ .../plugin/AbstractInstaller.java | 17 ++++++++-- .../plugin/installer/InstallManager.java | 4 +-- .../impls/install/PluginInstaller.java | 12 ++----- .../impls/uninstall/PluginUninstaller.java | 7 ++-- .../plugin/installer/task/TaskChain.java | 20 +++++++++--- .../installer/task/TaskFailedException.java | 32 +++++++++++++++++++ 7 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskFailedException.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java new file mode 100644 index 00000000..ee5acd9d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.installer; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; + +public class InstallSignalHandler +{ + private final Terminal terminal; + + public InstallSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index deda7c56..7156fc66 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -10,6 +10,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskChain; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; @@ -34,7 +35,19 @@ protected void postSignal(@NotNull InstallerSignal signal) this.signalHandler.handleSignal(this.progress, signal); } - public abstract InstallResult

execute(@NotNull String query) throws IOException; + protected abstract InstallResult

execute(@NotNull String query) throws IOException, TaskFailedException; + + public InstallResult

run(@NotNull String query) throws IOException + { + try + { + return this.execute(query); + } + catch (TaskFailedException e) + { + return this.handleTaskError(e.getResult()); + } + } @NotNull protected InstallResult

success() @@ -56,7 +69,7 @@ public , S extends Enum> InstallFailedInstallResult handleTaskError(@NotNull TaskResult result) + private InstallResult

handleTaskError(@NotNull TaskResult result) { if (result.getErrorCause() != null) return this.error(result.getErrorCause(), result.getState()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index dc3abfde..801cc733 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -62,7 +62,7 @@ public void runInstall(@NotNull String query) throws IllegalStateException, IOEx PluginInstaller installer = new PluginInstaller(signalHandleManager); runningInstall = installer.getProgress(); - installer.execute(query); + installer.run(query); } /** @@ -80,6 +80,6 @@ public void runUninstall(@NotNull String query) throws IllegalStateException, IO PluginUninstaller uninstaller = new PluginUninstaller(signalHandleManager); runningInstall = uninstaller.getProgress(); - uninstaller.execute(query); + uninstaller.run(query); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index d4cf5c19..fa7217f0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectArgument; @@ -56,7 +57,7 @@ public PluginInstaller(@NotNull SignalHandleManager signalHandler) throws IOExce @Override @SuppressWarnings("rawtypes") - public InstallResult execute(@NotNull String query) + public InstallResult execute(@NotNull String query) throws TaskFailedException { Path pluginFilePath; PluginDescriptionFile pluginDescription; @@ -81,9 +82,6 @@ public InstallResult execute(@NotNull String query) }) .submitAll(new PluginResolveArgument(query)); - if (!pluginDescriptionResult.isSuccess()) - return handleTaskError(pluginDescriptionResult); - DescriptionLoadResult descriptionLoadResult = (DescriptionLoadResult) pluginDescriptionResult; pluginFilePath = descriptionLoadResult.getPluginFile(); @@ -145,9 +143,6 @@ public InstallResult execute(@NotNull String query) .bridgeArgument(result -> new DependsComputeOrderArgument(result.getCollectedPlugins())) .submitAll(new DependsCollectArgument(pluginDescription)); - if (!dependsComputeOrderResult.isSuccess()) - return handleTaskError(dependsComputeOrderResult); - dependenciesLoadOrder = ((DependsComputeOrderResult) dependsComputeOrderResult).getOrder(); // endregion @@ -157,9 +152,6 @@ public InstallResult execute(@NotNull String query) this.submitter(InstallTasks.INSTALLING_PLUGINS, new PluginsInstallTask(progress, signalHandler)) .submitAll(new PluginsInstallArgument( pluginFilePath, pluginDescription, dependenciesLoadOrder)); - - if (!pluginsInstallResult.isSuccess()) - return handleTaskError(pluginDescriptionResult); // endregion if (replacePlugin) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index 3632ef81..f0d6ee41 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -6,6 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.SearchingPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; @@ -46,7 +47,7 @@ public PluginUninstaller(SignalHandleManager signalHandler) throws IOException } @Override - public InstallResult execute(@NotNull String query) + public InstallResult execute(@NotNull String query) throws TaskFailedException { List plugins = new ArrayList<>(); // region Search plugin @@ -132,10 +133,6 @@ public InstallResult execute(@NotNull String query) return new UnInstallArgument(orderedPlugins); }) .submitAll(new DependsComputeOrderArgument(computeOrderTarget)); - - if (!uninstallResult.isSuccess()) - return this.handleTaskError(uninstallResult); - // endregion return this.success(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java index eeaa4067..64c0609b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java @@ -109,15 +109,19 @@ public TaskChain bridgeArgument(@NotNull Function argu * * @param argument タスクの引数 * @return タスクの結果 + * @throws TaskFailedException タスクの実行に失敗した場合 */ - public @NotNull TaskResult submitFromThis(@NotNull TaskArgument argument) + public @NotNull TaskResult submitFromThis(@NotNull TaskArgument argument) throws TaskFailedException { try { this.installer.getProgress().setCurrentTask(this.installerState); R result = this.task.runTask((TA) argument); - if (result.isSuccess() && this.next != null) + if (!result.isSuccess()) + throw new TaskFailedException(result); + + if (this.next != null) return this.next.submitFromThis(result); else return result; @@ -133,8 +137,9 @@ public TaskChain bridgeArgument(@NotNull Function argu * * @param taskResult 前のタスクの結果 * @return タスクの結果 + * @throws TaskFailedException タスクの実行に失敗した場合 */ - public @NotNull TaskResult submitFromThis(@NotNull TaskResult taskResult) + public @NotNull TaskResult submitFromThis(@NotNull TaskResult taskResult) throws TaskFailedException { if (this.argumentBuilder == null) throw new IllegalStateException("No argument builder defined to build argument from parent result"); @@ -144,7 +149,10 @@ public TaskChain bridgeArgument(@NotNull Function argu this.installer.getProgress().setCurrentTask(this.installerState); R result = this.task.runTask(this.argumentBuilder.apply((PR) taskResult)); - if (result.isSuccess() && this.next != null) + if (!result.isSuccess()) + throw new TaskFailedException(result); + + if (this.next != null) return this.next.submitFromThis(result); else return result; @@ -160,8 +168,10 @@ public TaskChain bridgeArgument(@NotNull Function argu * * @param argument タスクの引数 * @return タスクの結果 + * @throws TaskFailedException タスクの実行に失敗した場合 + * @throws IllegalStateException タスクチェーンが設定されていない場合 */ - public @NotNull TaskResult submitAll(@NotNull TaskArgument argument) + public @NotNull TaskResult submitAll(@NotNull TaskArgument argument) throws TaskFailedException, IllegalStateException { if (this.first == null) throw new IllegalStateException("No task chain defined"); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskFailedException.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskFailedException.java new file mode 100644 index 00000000..849f03c1 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskFailedException.java @@ -0,0 +1,32 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; + +import lombok.Getter; + +public class TaskFailedException extends Exception +{ + @Getter + private final TaskResult result; + + public TaskFailedException(TaskResult result) + { + this.result = result; + } + + public TaskFailedException(String message, TaskResult result) + { + super(message); + this.result = result; + } + + public TaskFailedException(String message, Throwable cause, TaskResult result) + { + super(message, cause); + this.result = result; + } + + public TaskFailedException(Throwable cause, TaskResult result) + { + super(cause); + this.result = result; + } +} From 9122ddaf6ffdbe1a6f924b38cfecf1073ca2af42 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 15:07:16 +0900 Subject: [PATCH 232/745] refactor: Remove verbose task submitting --- .../impls/install/PluginInstaller.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index fa7217f0..50cec0f1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -7,11 +7,9 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadResult; @@ -33,7 +31,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.util.List; /** * プラグインを新規にインストールするインストーラーの実装です。 @@ -135,23 +132,16 @@ public InstallResult execute(@NotNull String query) throws TaskFai this.progress.addPending(pluginDescription.getName()); - List dependenciesLoadOrder; // region Do collect dependencies, compute dependencies load order and install them. - TaskResult dependsComputeOrderResult = + TaskResult installResult = this.submitter(InstallTasks.COLLECTING_DEPENDENCIES, new DependsCollectTask(progress, signalHandler)) .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(progress, signalHandler)) .bridgeArgument(result -> new DependsComputeOrderArgument(result.getCollectedPlugins())) + .then(InstallTasks.INSTALLING_PLUGINS, new PluginsInstallTask(progress, signalHandler)) + .bridgeArgument(result -> new PluginsInstallArgument( + pluginFilePath, pluginDescription, result.getOrder() + )) .submitAll(new DependsCollectArgument(pluginDescription)); - - dependenciesLoadOrder = ((DependsComputeOrderResult) dependsComputeOrderResult).getOrder(); - // endregion - - // region Install plugins. - - TaskResult pluginsInstallResult = - this.submitter(InstallTasks.INSTALLING_PLUGINS, new PluginsInstallTask(progress, signalHandler)) - .submitAll(new PluginsInstallArgument( - pluginFilePath, pluginDescription, dependenciesLoadOrder)); // endregion if (replacePlugin) From a290a99a55b45f36dc24e6b31e6018af1fe414e2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 15:10:14 +0900 Subject: [PATCH 233/745] fix: Degrade of refactoring InstallProgress --- .../commands/debug/DebugSignalHandler.java | 2 +- .../teamkunpluginmanager/plugin/installer/InstallResult.java | 4 ++-- .../plugin/installer/task/InstallTask.java | 2 +- .../tasks/dependencies/collector/DependsCollectStatus.java | 2 +- .../task/tasks/dependencies/collector/DependsCollectTask.java | 2 +- .../tasks/dependencies/computer/DependsComputeOrderTask.java | 2 +- .../installer/task/tasks/description/DescriptionLoadTask.java | 2 +- .../plugin/installer/task/tasks/download/DownloadTask.java | 2 +- .../installer/task/tasks/install/PluginsInstallTask.java | 2 +- .../installer/task/tasks/resolve/PluginResolveTask.java | 2 +- .../plugin/installer/task/tasks/uninstall/UnInstallTask.java | 2 +- .../teamkunpluginmanager/plugin/signal/SignalHandlerList.java | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 029ff38a..91da7495 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -244,7 +244,7 @@ public static SignalHandleManager toManager(Terminal terminal) } @SignalHandler - public void handleAll(@NotNull InstallProgress installProgress, InstallerSignal signal) + public void handleAll(@NotNull InstallProgress installProgress, InstallerSignal signal) { if (!(signal instanceof DownloadProgressSignal)) printSignal(signal, terminal); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java index c0060adc..f240ed90 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java @@ -26,9 +26,9 @@ public class InstallResult

> * インストールの進捗状況です。 */ @Getter - private final InstallProgress

progress; + private final InstallProgress progress; - public InstallResult(boolean success, InstallProgress

progress) + public InstallResult(boolean success, InstallProgress progress) { progress.finish(); this.success = success; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java index 25ca8494..25a4d0f4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java @@ -19,7 +19,7 @@ public abstract class InstallTask progress; + protected final InstallProgress progress; /** * タスクからスローされるシグナルを受け取るハンドラーです。 */ diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index ddb9548c..637892ab 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -41,7 +41,7 @@ public class DependsCollectStatus * * @param progress InstallProgress */ - public DependsCollectStatus(InstallProgress progress) + public DependsCollectStatus(InstallProgress progress) { this.installId = progress.getInstallActionID(); this.enumeratedDependencies = new HashMap<>(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 0be1fac8..d4b31191 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -55,7 +55,7 @@ public class DependsCollectTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public DependsCollectTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index 43be1dd3..cd13a82b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -27,7 +27,7 @@ public class DependsComputeOrderTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public DependsComputeOrderTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java index 77ccff69..0a0e0543 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java @@ -19,7 +19,7 @@ public class DescriptionLoadTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public DescriptionLoadTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); this.taskState = DescriptionLoadState.INITIALIZED; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java index 9930a512..dd9108ed 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java @@ -26,7 +26,7 @@ public class DownloadTask extends InstallTask private DownloadState taskState; - public DownloadTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + public DownloadTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index be51e362..a6f365d0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -51,7 +51,7 @@ public class PluginsInstallTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public PluginsInstallTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java index c9338138..ee945aee 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java @@ -29,7 +29,7 @@ public class PluginResolveTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public PluginResolveTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 5a65179d..c69cca0e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -78,7 +78,7 @@ public class UnInstallTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java index 3dac71e4..e49c036a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java @@ -54,7 +54,7 @@ public void bakeAll(Object object) } } - void onSignal(InstallProgress installProgress, T signal) + void onSignal(InstallProgress installProgress, T signal) { synchronized (handlers) { From b8347be9c3c46d13f879e2902be20e694ebbdfe6 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 20:31:47 +0900 Subject: [PATCH 234/745] feat: Cancel in PluginResolveTask --- .../task/tasks/resolve/PluginResolveErrorCause.java | 6 +++++- .../installer/task/tasks/resolve/PluginResolveTask.java | 8 ++++++++ .../resolve/signals/MultiplePluginResolvedSignal.java | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java index 7932022b..fd42845d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveErrorCause.java @@ -14,5 +14,9 @@ public enum PluginResolveErrorCause /** * {@link ErrorResult} が サーバまたはプラグインリゾルバから返されたことを示します。 */ - GOT_ERROR_RESULT + GOT_ERROR_RESULT, + /** + * ユーザがキャンセルしたことを示します。 + */ + CANCELLED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java index ee945aee..16b615fe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java @@ -44,6 +44,9 @@ public PluginResolveTask(@NotNull InstallProgress progress, @NotNull Signa MultiplePluginResolvedSignal signal = new MultiplePluginResolvedSignal(query, results); this.postSignal(signal); + if (signal.isCancel()) + return null; + if (signal.getSpecifiedResult() != null) return signal.getSpecifiedResult(); // Plugin actually resolved by SignalHandler. @@ -84,6 +87,11 @@ else if (queryResolveResult instanceof MultiResult) MultiResult multiResult = (MultiResult) queryResolveResult; ResolveResult actualResolveResult = resolveMultipleResults(arguments.getQuery(), multiResult); + if (actualResolveResult == null) + return new PluginResolveResult(false, this.taskState, + PluginResolveErrorCause.CANCELLED, null + ); + if (actualResolveResult instanceof ErrorResult) { // MultiResult has been resolved, but the actual result is an error diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java index 9e542bb3..de95b8ca 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java @@ -33,4 +33,9 @@ public class MultiplePluginResolvedSignal implements InstallerSignal */ @Nullable private ResolveResult specifiedResult; + + /** + * インストールをキャンセルするかどうかを示すフラグです。 + */ + private boolean cancel; } From 29baaeb118c121df647e6bc49a876cdb48950d56 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sat, 10 Sep 2022 21:39:26 +0900 Subject: [PATCH 235/745] feat: URL in DownloadProgressSignal --- .../installer/task/tasks/download/DownloadTask.java | 5 +++-- .../tasks/download/signals/DownloadProgressSignal.java | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java index dd9108ed..830616c8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java @@ -35,12 +35,13 @@ public DownloadTask(@NotNull InstallProgress progress, @NotNull SignalHand this.taskState = DownloadState.INITIALIZED; } - private void onDownload(DownloadProgress downloadProgress) + private void onDownload(DownloadProgress downloadProgress, String url) { this.taskState = DownloadState.DOWNLOADING; this.postSignal(new DownloadProgressSignal( this.randomDownloadID, + url, downloadProgress.getTotalSize(), downloadProgress.getDownloaded(), downloadProgress.getPercentage() @@ -68,7 +69,7 @@ private void onDownload(DownloadProgress downloadProgress) try { - long size = Requests.downloadFile(RequestMethod.GET, url, path, this::onDownload); + long size = Requests.downloadFile(RequestMethod.GET, url, path, progress -> onDownload(progress, url)); this.postSignal(new DownloadSucceedSignal(this.randomDownloadID, path, size)); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java index 4278bef1..c61124b3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java @@ -11,6 +11,12 @@ @EqualsAndHashCode(callSuper = true) public class DownloadProgressSignal extends DownloadSignal { + /** + * ダウンロードしようとしているファイルのURLです。 + */ + @NotNull + String url; + /** * ダウンロードしようとしているファイルのサイズです。 */ @@ -26,9 +32,10 @@ public class DownloadProgressSignal extends DownloadSignal */ double percentage; - public DownloadProgressSignal(@NotNull String downloadId, long totalSize, long downloaded, double percentage) + public DownloadProgressSignal(@NotNull String downloadId, String url, long totalSize, long downloaded, double percentage) { super(downloadId); + this.url = url; this.totalSize = totalSize; this.downloaded = downloaded; this.percentage = percentage; From c48b9a0cb06cc0b688b1a6cf3daf501184b389a5 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 11 Sep 2022 07:19:35 +0900 Subject: [PATCH 236/745] feat: URL in DownloadResult/Task --- .../task/tasks/download/DownloadResult.java | 13 ++++++++++--- .../installer/task/tasks/download/DownloadTask.java | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java index 06a5591e..a31fd6e9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java @@ -13,6 +13,12 @@ @Getter public class DownloadResult extends TaskResult { + /** + * ダウンロード元のURLです。 + */ + @NotNull + private final String url; + /** * ダウンロード先のファイルのパスです。 */ @@ -29,18 +35,19 @@ public class DownloadResult extends TaskResult Date: Sun, 11 Sep 2022 07:21:40 +0900 Subject: [PATCH 237/745] feat: URL in DependencyDownloadFailedSignal --- .../dependencies/collector/DependsCollectTask.java | 3 ++- .../signals/DependencyDownloadFailedSignal.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index d4b31191..5fdb16b6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -231,7 +231,8 @@ private HashMap downloadDepends(@NotNull HashMap !entry.getValue().isSuccess()) - .forEach(entry -> this.postSignal(new DependencyDownloadFailedSignal(entry.getKey()))); + .forEach(entry -> this.postSignal( + new DependencyDownloadFailedSignal(entry.getKey(), entry.getValue().getUrl()))); return new HashMap<>(downloadResults); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java index e566ea34..fc05751b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java @@ -1,12 +1,24 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + /** * 依存関係のダウンロードに失敗したことを示すシグナルです。 */ public class DependencyDownloadFailedSignal extends DependencyCollectFailedSignalBase { - public DependencyDownloadFailedSignal(String failedDependency) + /** + * ダウンロード元のURLです。 + */ + @NotNull + @Getter + private final String url; + + public DependencyDownloadFailedSignal(@NotNull String failedDependency, @NotNull String url) { super(failedDependency); + + this.url = url; } } From 51e08cf86d0ab8fa126ba7b88fb2175f33586d94 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 11 Sep 2022 07:28:13 +0900 Subject: [PATCH 238/745] feat: URL in DownloadErrorSignal --- .../installer/task/tasks/download/DownloadTask.java | 6 ++++-- .../task/tasks/download/signals/DownloadErrorSignal.java | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java index ff45bc20..08b0a38d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java @@ -96,14 +96,16 @@ else if (e.getMessage().startsWith("No response body was returned")) signalValue = e; } - DownloadErrorSignal error = new DownloadErrorSignal(this.randomDownloadID, cause, signalValue); + DownloadErrorSignal error = new DownloadErrorSignal(this.randomDownloadID, url, cause, signalValue); this.postSignal(error); return new DownloadResult(false, this.taskState, url, path, -1, this.randomDownloadID, cause); } catch (Exception e) { - this.postSignal(new DownloadErrorSignal(this.randomDownloadID, DownloadErrorCause.UNKNOWN_ERROR, e)); + this.postSignal(new DownloadErrorSignal(this.randomDownloadID, url, + DownloadErrorCause.UNKNOWN_ERROR, e + )); return new DownloadResult(false, this.taskState, url, path, -1, this.randomDownloadID, DownloadErrorCause.UNKNOWN_ERROR diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java index 85e5a2bf..521af476 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java @@ -13,6 +13,12 @@ @EqualsAndHashCode(callSuper = true) public class DownloadErrorSignal extends DownloadSignal { + /** + * 失敗したURLです。 + */ + @NotNull + String url; + /** * 失敗した理由です。 */ @@ -27,9 +33,10 @@ public class DownloadErrorSignal extends DownloadSignal @Nullable Object value; - public DownloadErrorSignal(@NotNull String downloadId, @NotNull DownloadErrorCause cause, @Nullable Object value) + public DownloadErrorSignal(@NotNull String downloadId, @NotNull String url, @NotNull DownloadErrorCause cause, @Nullable Object value) { super(downloadId); + this.url = url; this.cause = cause; this.value = value; } From 0bef8a50dcff5152c4f02faaf4ea6ddced1f42e2 Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 11 Sep 2022 08:42:06 +0900 Subject: [PATCH 239/745] feat: DependsDownloadFinishedSignal --- .../collector/DependsCollectTask.java | 7 ++++++- .../DependsDownloadFinishedSignal.java | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 5fdb16b6..6b7664f4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -9,6 +9,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsCollectFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsDownloadFinishedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; @@ -234,7 +235,11 @@ private HashMap downloadDepends(@NotNull HashMap this.postSignal( new DependencyDownloadFailedSignal(entry.getKey(), entry.getValue().getUrl()))); - return new HashMap<>(downloadResults); + HashMap downloadResultsCopy = new HashMap<>(downloadResults); + + this.postSignal(new DependsDownloadFinishedSignal((HashMap) downloadResults)); + + return new HashMap<>(downloadResultsCopy); } private PluginResolveResult passResolver(@NotNull String dependency) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java new file mode 100644 index 00000000..c5da0319 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java @@ -0,0 +1,21 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; + +/** + * 依存関係のダウンロードがすべて完了したことを示すシグナルです。 + */ +@Value +public class DependsDownloadFinishedSignal implements InstallerSignal +{ + /** + * ダウンロード結果です。 + */ + @NotNull + HashMap downloads; +} From 4f74caf72eea8987a1c6135ffaf074b3831e833b Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 11 Sep 2022 09:11:44 +0900 Subject: [PATCH 240/745] refactor: InstallerSignal => plugin.signal.Signal --- .../commands/debug/DebugSignalHandler.java | 8 +++--- .../plugin/AbstractInstaller.java | 4 +-- .../plugin/installer/InstallProgress.java | 3 ++- .../signals/AlreadyInstalledPluginSignal.java | 4 +-- .../signals/PluginIsDependencySignal.java | 4 +-- .../signals/SearchingPluginSignal.java | 4 +-- .../signals/PluginModifiedSignal.java | 4 +-- .../assertion/IgnoredPluginSignal.java | 4 +-- .../plugin/installer/task/InstallTask.java | 4 +-- ...CollectDependencysDependsFailedSignal.java | 4 +-- .../DependencyCollectFailedSignalBase.java | 4 +-- .../signals/DependsCollectFailedSignal.java | 4 +-- .../DependsDownloadFinishedSignal.java | 4 +-- .../signals/DependsEnumeratedSignal.java | 4 +-- .../DependsLoadOrderComputingSignal.java | 4 +-- .../signals/LoadPluginDescriptionSignal.java | 4 +-- .../download/signals/DownloadSignal.java | 4 +-- .../install/signals/PluginEnablingSignal.java | 4 +-- .../signals/PluginInstallingSignal.java | 4 +-- .../install/signals/PluginLoadSignal.java | 4 +-- .../signals/PluginOnLoadRunningSignal.java | 4 +-- .../signals/PluginRelocatingSignal.java | 4 +-- .../signals/MultiplePluginResolvedSignal.java | 4 +-- .../signals/PluginResolveErrorSignal.java | 4 +-- .../PluginResolvedSuccessfulSignal.java | 4 +-- .../signals/PluginResolvingSignal.java | 4 +-- .../signals/PluginDisablingSignal.java | 4 +-- .../signals/PluginRegisteredRecipeSignal.java | 4 +-- .../signals/PluginUnloadingSignal.java | 4 +-- .../Signal.java} | 6 ++--- .../plugin/signal/SignalHandleManager.java | 25 +++++++++---------- .../plugin/signal/SignalHandlerList.java | 3 +-- .../utils/PluginUtil.java | 5 ++++ 33 files changed, 81 insertions(+), 77 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/{installer/InstallerSignal.java => signal/Signal.java} (74%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 91da7495..c3edfc35 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -5,10 +5,10 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; import org.apache.commons.lang.ArrayUtils; @@ -29,7 +29,7 @@ public class DebugSignalHandler private final Terminal terminal; - private static void handleInputSignals(T signal, Terminal terminal) + private static void handleInputSignals(T signal, Terminal terminal) { try { @@ -54,7 +54,7 @@ else if (signal instanceof IgnoredPluginSignal) } } - private static void printSignal(T signal, Terminal terminal) + private static void printSignal(T signal, Terminal terminal) { terminal.writeLine("===================="); terminal.info("On Signal: " + signal.getClass().getSimpleName()); @@ -244,7 +244,7 @@ public static SignalHandleManager toManager(Terminal terminal) } @SignalHandler - public void handleAll(@NotNull InstallProgress installProgress, InstallerSignal signal) + public void handleAll(@NotNull InstallProgress installProgress, Signal signal) { if (!(signal instanceof DownloadProgressSignal)) printSignal(signal, terminal); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index 7156fc66..4272c0d9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -5,13 +5,13 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.GeneralTaskErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskChain; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; @@ -30,7 +30,7 @@ public AbstractInstaller(SignalHandleManager signalHandler) throws IOException this.signalHandler = signalHandler; } - protected void postSignal(@NotNull InstallerSignal signal) + protected void postSignal(@NotNull Signal signal) { this.signalHandler.handleSignal(this.progress, signal); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 4d600caf..d99f7f07 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -7,6 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectStatus; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.apache.commons.io.FileUtils; import org.bukkit.plugin.PluginDescriptionFile; @@ -82,7 +83,7 @@ public class InstallProgress, I extends AbstractInstaller *

  • インストールの進捗状況のリアルタイム通知
  • @@ -11,6 +11,6 @@ *

    * このシグナルは、フロントエンドとバックエンドの隔離のために作成されました。 */ -public interface InstallerSignal +public interface Signal { } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java index c9bf130a..d282b127 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.signal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -13,12 +12,12 @@ * シグナルを受け取り、処理を行うクラスです。 * シグナルは、{@link SignalHandler}アノテーションを付与したメソッドによって処理され、以下のシグニチャを持つ必要があります。 *

    - *     public void methodName({@link InstallProgress<>}, {@link InstallerSignal})
    + *     public void methodName({@link InstallProgress<>}, {@link Signal})
      * 
    */ public class SignalHandleManager { - private final ArrayList> handlerLists; + private final ArrayList> handlerLists; public SignalHandleManager() { @@ -27,21 +26,21 @@ public SignalHandleManager() @SuppressWarnings({"rawtypes", "unchecked"}) private static void invokeHandler(@NotNull InstallProgress installProgress, SignalHandlerList handler, - InstallerSignal signal) + Signal signal) { if (handler.isSignalType(signal.getClass())) handler.onSignal(installProgress, signal); } @SuppressWarnings("unchecked") - private static List> enumerateHandlers(Object object) + private static List> enumerateHandlers(Object object) { return Arrays.stream(object.getClass().getMethods()).parallel() .filter(method -> method.isAnnotationPresent(SignalHandler.class)) .filter(method -> method.getParameterCount() == 2) .map(method -> method.getParameterTypes()[1]) - .filter(InstallerSignal.class::isAssignableFrom) - .map(clazz -> (Class) clazz) + .filter(Signal.class::isAssignableFrom) + .map(clazz -> (Class) clazz) .collect(Collectors.toList()); } @@ -52,17 +51,17 @@ private static List> enumerateHandlers(Object o */ public void register(Object object) { - List> handleTargetClasses = enumerateHandlers(object); + List> handleTargetClasses = enumerateHandlers(object); - for (SignalHandlerList handlerList : handlerLists) + for (SignalHandlerList handlerList : handlerLists) { handlerList.bakeAll(object); handleTargetClasses.removeIf(handlerList::isSignalType); } - for (Class handleTargetClass : handleTargetClasses) + for (Class handleTargetClass : handleTargetClasses) { - SignalHandlerList handlerList = new SignalHandlerList<>(handleTargetClass); + SignalHandlerList handlerList = new SignalHandlerList<>(handleTargetClass); handlerLists.add(handlerList); handlerList.bakeAll(object); } @@ -74,9 +73,9 @@ public void register(Object object) * @param installProgress インストールの進捗 * @param signal シグナル */ - public void handleSignal(@NotNull InstallProgress installProgress, InstallerSignal signal) + public void handleSignal(@NotNull InstallProgress installProgress, Signal signal) { - for (SignalHandlerList handlerList : handlerLists) + for (SignalHandlerList handlerList : handlerLists) invokeHandler(installProgress, handlerList, signal); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java index e49c036a..f8d59af3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java @@ -2,7 +2,6 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,7 +11,7 @@ import java.util.Arrays; import java.util.List; -class SignalHandlerList +class SignalHandlerList { @NotNull private final Class signalType; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index 10723b66..ff490bce 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -46,6 +46,11 @@ public class PluginUtil // TODO: Rewrite this class } } + public static String getPluginString(PluginDescriptionFile description) + { + return String.format("%s (%s)", description.getName(), description.getVersion()); + } + @SuppressWarnings("unchecked") public static Map ms2Map(MemorySection ms) { From abf0e1695b2fa474d2a3ce5d181d069c6a71fc2c Mon Sep 17 00:00:00 2001 From: Peyang <42040068+peyang-Celeron@users.noreply.github.com> Date: Sun, 11 Sep 2022 09:28:14 +0900 Subject: [PATCH 241/745] feat: Handler of installer --- .../installer/InstallSignalHandler.java | 15 --- .../commands/signal/HeadSignalHandlers.java | 64 +++++++++++ .../common/CheckEnvSignalHandler.java | 83 ++++++++++++++ .../handlers/common/ModifySignalHandler.java | 45 ++++++++ .../intall/DependenciesSignalHandler.java | 60 ++++++++++ .../intall/DownloadingSignalHandler.java | 107 ++++++++++++++++++ .../intall/InstallerSignalHandler.java | 53 +++++++++ .../intall/ResolverSignalHandler.java | 99 ++++++++++++++++ .../plugin/installer/InstallManager.java | 10 +- 9 files changed, 519 insertions(+), 17 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java deleted file mode 100644 index ee5acd9d..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/installer/InstallSignalHandler.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.installer; - -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; - -public class InstallSignalHandler -{ - private final Terminal terminal; - - public InstallSignalHandler(Terminal terminal) - { - this.terminal = terminal; - } - - -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java new file mode 100644 index 00000000..8366df2c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -0,0 +1,64 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.CheckEnvSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.ModifySignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DependenciesSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DownloadingSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.ResolverSignalHandler; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * シグナルを受け取り, 処理を行うクラス をまとめるためのユーティリティクラスです. + */ +public class HeadSignalHandlers +{ + private static List createHandlersList(List base, Object... handlers) + { + List list = new ArrayList<>(base); + list.addAll(Arrays.asList(handlers)); + return list; + } + + private static List createHandlersList(Object... handlers) + { + return Arrays.asList(handlers); + } + + /** + * 共通ハンドラを返します. + * + * @param terminal ターミナル + * @return 共通ハンドラ + */ + public static List getCommonHandlers(@NotNull Terminal terminal) + { + return createHandlersList( + new CheckEnvSignalHandler(terminal), + new ModifySignalHandler(terminal) + ); + } + + /** + * インストールに使用するハンドラを返します. + * + * @param terminal ターミナル + * @return インストールに使用するハンドラ + */ + public static List getInstallHandlers(@NotNull Terminal terminal) + { + return createHandlersList( + getCommonHandlers(terminal), + new ResolverSignalHandler(terminal), + new DownloadingSignalHandler(terminal), + new CheckEnvSignalHandler(terminal), + new DependenciesSignalHandler(terminal), + new InstallerSignalHandler(terminal) + ); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java new file mode 100644 index 00000000..5bb87a87 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java @@ -0,0 +1,83 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.ChatColor; +import org.bukkit.plugin.PluginDescriptionFile; + +/** + * プラグインのインストール環境をチェックするハンドラです. + */ +public class CheckEnvSignalHandler +{ + private final Terminal terminal; + + public CheckEnvSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onPluginIsIgnored(IgnoredPluginSignal signal) + { + terminal.warn(PluginUtil.getPluginString(signal.getPluginDescription()) + + " は ignore としてマークされていますが強制的にインストールが可能です。"); + + terminal.writeLine(ChatColor.DARK_RED + "W: 強制的なインストールは予期しない問題を引き起こす可能性があります。"); + + try + { + QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?") + .waitAndGetResult(); + + boolean continueInstall = result.test(QuestionAttribute.YES); + + signal.setCancelInstall(!continueInstall); + } + catch (InterruptedException ex) + { + ex.printStackTrace(); + } + } + + private void printKeyValue(String key, String value) + { + terminal.writeLine(ChatColor.DARK_GREEN + key + ChatColor.WHITE + ": " + ChatColor.GREEN + value); + } + + private void printPluginInfo(PluginDescriptionFile descriptionFile) + { + printKeyValue("バージョン", descriptionFile.getVersion()); + printKeyValue("作者", String.join(", ", descriptionFile.getAuthors())); + printKeyValue("コマンド", String.join(", ", descriptionFile.getCommands().keySet())); + } + + @SignalHandler + public void onPluginIsDuplicated(AlreadyInstalledPluginSignal signal) + { + terminal.warn(signal.getInstalledPlugin().getName() + " は既にインストールされています。"); + terminal.writeLine(ChatColor.BLUE + "== 既にインストールされているプラグイン =="); + printPluginInfo(signal.getInstalledPlugin()); + terminal.writeLine(ChatColor.BLUE + "== インストールしようとしているプラグイン =="); + printPluginInfo(signal.getInstallingPlugin()); + + try + { + QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?") + .waitAndGetResult(); + + boolean continueInstall = result.test(QuestionAttribute.YES); + + signal.setReplacePlugin(continueInstall); + } + catch (InterruptedException ex) + { + ex.printStackTrace(); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java new file mode 100644 index 00000000..70924dfe --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java @@ -0,0 +1,45 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.ChatColor; + +/** + * プラグインの変更のシグナルをハンドルするハンドラです. + */ +public class ModifySignalHandler +{ + private final Terminal terminal; + + public ModifySignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onPluginModify(PluginModifiedSignal signal) + { + String pluginStr = PluginUtil.getPluginString(signal.getPluginDescription()); + String printMessage; + + switch (signal.getModifyType()) + { + case ADD: + printMessage = ChatColor.GREEN + "+ " + pluginStr; + break; + case REMOVE: + printMessage = ChatColor.RED + "- " + pluginStr; + break; + case UPGRADE: + printMessage = ChatColor.YELLOW + "* " + pluginStr; + break; + default: + printMessage = ChatColor.GRAY + "?" + pluginStr; + break; + } + + terminal.writeLine(printMessage); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java new file mode 100644 index 00000000..fbefce66 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java @@ -0,0 +1,60 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import org.bukkit.ChatColor; + +/** + * 依存関係のシグナルを処理するハンドラです. + */ +public class DependenciesSignalHandler +{ + private final Terminal terminal; + + public DependenciesSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + // Ignore DependsEnumeratedSignal + // Ignore other resolves + // Ignore other downloads + // Ignore DependencyDownloadFailedSignal + // Ignore DependsLoadOrderComputingSignal.Pre + + @SignalHandler + public void onDependencyResolveFailed(DependencyResolveFailedSignal signal) + { + terminal.error("依存関係の解決に失敗しました: " + signal.getFailedDependency()); + } + + @SignalHandler + public void onDepsDepsFailed(DependencyCollectDependencysDependsFailedSignal signal) + { + signal.getCollectFailedDependencies().forEach(dependency -> + terminal.error("依存関係の取得に失敗しました: " + dependency)); + } + + @SignalHandler + public void onDependencyLoadDescriptionFailed(DependencyLoadDescriptionFailedSignal signal) + { + terminal.error("依存関係の読み取りに失敗しました: " + signal.getFailedDependency()); + } + + @SignalHandler + public void onDependencyNameMismatch(DependencyNameMismatchSignal signal) + { + terminal.error("依存関係の整合性が確認できませんでした: " + signal.getFailedDependency()); + } + + @SignalHandler + public void onDependencyTreeBuilt(DependsLoadOrderComputingSignal.Pre signal) + { + terminal.writeLine(ChatColor.GREEN + "依存関係ツリーを構築中 ..."); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java new file mode 100644 index 00000000..8022e31c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java @@ -0,0 +1,107 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsDownloadFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.ChatColor; + +/** + * ダウンロードのシグナルを処理するハンドラです. + */ +public class DownloadingSignalHandler +{ + private final Terminal terminal; + private String currentDownload; + + // Ignore DownloadStartingSignal + private long downloads; + private long downloadTotalSize; + private long downloadStarted; + private Progressbar downloadProgressBar; + private boolean mainDescriptionLoaded; + + public DownloadingSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + private void startDownloads(String id) + { + this.currentDownload = id; + this.downloads = 0; + this.downloadTotalSize = 0; + this.downloadStarted = System.currentTimeMillis(); + this.downloadProgressBar = terminal.createProgressbar("ダウンロード"); + this.downloadProgressBar.setProgressMax(100); + } + + private void addDownloadArtifact(String url, long size) + { + this.downloadTotalSize += size; + terminal.writeLine(ChatColor.GREEN + "取得:" + ++downloads + " " + url + " [" + PluginUtil.getFileSizeString(size) + "]"); + } + + private void endDownloads() + { + long elapsedMillis = System.currentTimeMillis() - this.downloadStarted; + long elapsedSec = elapsedMillis / 1000; + long bytesPerSec = this.downloadTotalSize / elapsedSec; + terminal.writeLine( + ChatColor.GREEN + PluginUtil.getFileSizeString(this.downloadTotalSize) + " を " + + ChatColor.YELLOW + elapsedSec + "秒" + + ChatColor.GREEN + "で取得しました (" + + ChatColor.YELLOW + PluginUtil.getFileSizeString(bytesPerSec) + "/s)" + ); + + this.currentDownload = null; + } + + @SignalHandler + public void onDownloadingSignal(DownloadProgressSignal signal) + { + if (currentDownload == null) + { + this.startDownloads(signal.getDownloadId()); + this.addDownloadArtifact(signal.getUrl(), signal.getTotalSize()); + } + + if (!currentDownload.equals(signal.getDownloadId())) + this.addDownloadArtifact(signal.getUrl(), signal.getTotalSize()); + + double percent = (double) signal.getDownloaded() / signal.getTotalSize(); + this.downloadProgressBar.setProgress((int) (percent * 100)); // max 100 + } + + @SignalHandler + public void onDownloadsEnd(LoadPluginDescriptionSignal signal) + { + // Typically, this signal is called after all downloads are finished. + // But, first time, this signal is called after one download to resolve dependencies. + // So, we need to handle first time only. + + if (mainDescriptionLoaded) + return; + + mainDescriptionLoaded = true; + this.endDownloads(); + } + + @SignalHandler + public void onDownloadsEnd(DependsDownloadFinishedSignal signal) + { + this.endDownloads(); + } + + @SignalHandler + public void onDownloadFailed(DownloadErrorSignal signal) + { + terminal.writeLine(String.format(ChatColor.RED + "失敗:%d %s: %s(%s)", + this.downloads, signal.getUrl(), signal.getCause(), signal.getValue() + )); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java new file mode 100644 index 00000000..040ff872 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java @@ -0,0 +1,53 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginEnablingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginInstallingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginLoadSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.ChatColor; + +/** + * インストーラのシグナルをハンドルするハンドラです. + */ +public class InstallerSignalHandler +{ + private final Terminal terminal; + + public InstallerSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + // Ignore PluginOnLoadRunningSignal + + @SignalHandler + public void onPluginInstallStart(PluginInstallingSignal signal) + { + terminal.writeLine(ChatColor.GREEN + signal.getPluginDescription().getName() + " をインストールする準備をしています ..."); + } + + @SignalHandler + public void onPluginRelocating(PluginRelocatingSignal signal) + { + String src = ".../" + signal.getSource().getFileName(); + String dest = ".../" + signal.getTarget().getFileName(); + terminal.writeLine(ChatColor.GREEN + src + " を " + dest + " に再配置しています ..."); + } + + @SignalHandler + public void onPluginLoadPre(PluginLoadSignal.Pre signal) + { + terminal.writeLine(ChatColor.GREEN + + PluginUtil.getPluginString(signal.getPluginDescription()) + " を読み込んでいます ..."); + } + + @SignalHandler + public void onPluginLoading(PluginEnablingSignal signal) + { + terminal.writeLine(ChatColor.GREEN + + PluginUtil.getPluginString(signal.getPlugin().getDescription()) + " のトリガを処理しています ..."); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java new file mode 100644 index 00000000..fee4b2af --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java @@ -0,0 +1,99 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolvingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import org.bukkit.ChatColor; + +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; + +/** + * 依存関係リゾルバのシグナルを処理するハンドラです. + */ +public class ResolverSignalHandler +{ + private final Terminal terminal; + + public ResolverSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onPluginResolving(PluginResolvingSignal signal) + { + terminal.writeLine(ChatColor.GREEN + "プラグインを解決しています ..."); + } + + @SignalHandler + public void onPluginResolveError(PluginResolveErrorSignal signal) + { + terminal.error(signal.getError().getCause().getMessage()); + terminal.error("プラグインの解決に失敗しました。"); + } + + @SignalHandler + public void onPluginsResolve(MultiplePluginResolvedSignal signal) + { + terminal.warn("複数のプラグインが見つかりました。"); + + AtomicLong index = new AtomicLong(0); + + Map keywordToResolveResult = Arrays.stream(signal.getResults().getResults()) + .filter(r -> r instanceof SuccessResult) + .map(r -> (SuccessResult) r) + .collect(Collectors.toMap(r -> String.valueOf(index.getAndIncrement()), r -> r)); + Map keywordToTitle = keywordToResolveResult.entrySet().stream() + .map(e -> new AbstractMap.SimpleEntry<>( + e.getKey(), + e.getValue().getFileName() + "(" + e.getValue().getVersion() + ")" + ) + ) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + keywordToTitle.put("a", "自動で最適なプラグインを選択する"); + + try + { + QuestionResult result = terminal.getInput().showQuestion( + "使用するプラグインを選択してください", + new AttributeChoice(keywordToTitle), + QuestionAttribute.CANCELLABLE + ).waitAndGetResult(); + + if (result.test(QuestionAttribute.CANCELLABLE)) + { + terminal.error(ChatColor.RED + "インストールをキャンセルしました。"); + signal.setCancel(true); + return; + } + else if (result.getRawAnswer().equalsIgnoreCase("a")) + return; + + SuccessResult selected = keywordToResolveResult.get(result.getRawAnswer()); + + if (selected == null) + { + terminal.error("不明な回答が選択されました。"); + signal.setCancel(true); + return; + } + + terminal.writeLine(ChatColor.GREEN + selected.getFileName() + "(" + selected.getVersion() + ") が解決されました。"); + signal.setSpecifiedResult(selected); + } + catch (InterruptedException ex) + { + ex.printStackTrace(); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index 801cc733..0da0b33b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -1,6 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.HeadSignalHandlers; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; @@ -48,17 +50,21 @@ public boolean isRunning() /** * インストールを実行します。 * - * @param query インストールするプラグインのクエリ + * @param terminal ターミナル + * @param query インストールするプラグインのクエリ * @throws IllegalStateException インストールが進行中の場合または GitHub にログインしていない場合 * @throws IOException 予期しない例外が発生した場合 */ - public void runInstall(@NotNull String query) throws IllegalStateException, IOException + public void runInstall(@NotNull Terminal terminal, @NotNull String query) throws IllegalStateException, IOException { if (isRunning()) throw new IllegalStateException("他のインストールが実行中です。"); if (!this.pluginManager.isTokenAvailable()) throw new IllegalStateException("GitHubにログインしていません。"); + SignalHandleManager copiedHandleManager = signalHandleManager.copy(); + HeadSignalHandlers.getInstallHandlers(terminal).forEach(copiedHandleManager::register); + PluginInstaller installer = new PluginInstaller(signalHandleManager); runningInstall = installer.getProgress(); From 92e83a538b8e7dba282704812b4cafdf792f07aa Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 18:43:04 +0900 Subject: [PATCH 242/745] feat: InstallFinishedSignalHandler --- .../commands/signal/HeadSignalHandlers.java | 4 +- .../common/InstallFinishedSignalHandler.java | 58 +++++++++++++++++++ .../plugin/AbstractInstaller.java | 16 ++++- .../signals/InstallFinishedSignal.java | 17 ++++++ 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/InstallFinishedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index 8366df2c..4807f191 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -2,6 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.CheckEnvSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.ModifySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DependenciesSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DownloadingSignalHandler; @@ -40,7 +41,8 @@ public static List getCommonHandlers(@NotNull Terminal terminal) { return createHandlersList( new CheckEnvSignalHandler(terminal), - new ModifySignalHandler(terminal) + new ModifySignalHandler(terminal), + new InstallFinishedSignalHandler(terminal) ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java new file mode 100644 index 00000000..f7d01aea --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java @@ -0,0 +1,58 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import org.bukkit.ChatColor; + +public class InstallFinishedSignalHandler +{ + private static final String statsFormat = + ChatColor.GREEN + "%d 追加 " + ChatColor.RED + "%d 削除 " + ChatColor.YELLOW + "%d 変更 " + ChatColor.GRAY + "%d 保留"; + + private final Terminal terminal; + + public InstallFinishedSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onFinished(InstallFinishedSignal finished) + { + if (finished.getResult() instanceof InstallFailedInstallResult) + onFail((InstallFailedInstallResult) finished.getResult()); + else + onSuccess(finished.getResult()); + } + + private void printResultStatistics(InstallResult result) + { + terminal.writeLine(String.format( + statsFormat, + result.getInstalledCount(), + result.getRemovedCount(), + result.getUpgradedCount(), + result.getPendingCount() + )); + } + + private void onSuccess(InstallResult result) + { + printResultStatistics(result); + terminal.success("インストールが正常に完了しました。"); + } + + private void onFail(InstallFailedInstallResult result) + { + printResultStatistics(result); + + Enum progress = result.getProgress().getCurrentTask(); + Enum reason = result.getReason(); + Enum taskStatus = result.getTaskStatus(); + + terminal.error("インストールは " + progress + " 時に " + reason + " により失敗しました(" + taskStatus + ")"); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java index 4272c0d9..e4879a3b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.GeneralTaskErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; @@ -52,19 +53,28 @@ public InstallResult

    run(@NotNull String query) throws IOException @NotNull protected InstallResult

    success() { - return new InstallResult<>(true, this.progress); + InstallResult

    result = new InstallResult<>(true, this.progress); + this.postSignal(new InstallFinishedSignal(result)); + + return result; } public > InstallFailedInstallResult error(@NotNull T reason) { // TODO: Implement debug mode - return new InstallFailedInstallResult<>(this.progress, reason); + InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, reason); + this.postSignal(new InstallFinishedSignal(result)); + + return result; } public , S extends Enum> InstallFailedInstallResult error( @NotNull T reason, @NotNull S taskStatus) { // TODO: Implement debug mode - return new InstallFailedInstallResult<>(this.progress, reason, taskStatus); + InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, reason, taskStatus); + this.postSignal(new InstallFinishedSignal(result)); + + return result; } @NotNull diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/InstallFinishedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/InstallFinishedSignal.java new file mode 100644 index 00000000..766e55ff --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/InstallFinishedSignal.java @@ -0,0 +1,17 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +/** + * インストールが完了したことを表すシグナルです。 + */ +@Value +public class InstallFinishedSignal implements Signal +{ + /** + * インストール結果 + */ + InstallResult result; +} From 95a486c511d7725d0bdb8015f64e258fed2cf866 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 18:49:43 +0900 Subject: [PATCH 243/745] feat: Apply install --- .../commands/CommandInstall.java | 31 +++---------------- .../plugin/installer/InstallManager.java | 30 +++++++++++++----- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index c323b191..a171e32a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -4,9 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; import net.kyori.adventure.text.TextComponent; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -18,35 +16,14 @@ public class CommandInstall extends CommandBase @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (indicateArgsLengthInvalid(terminal, args, 1, 2)) // TODO: Set max to 1 cuz arg of $-CF-$ will be removed. + if (indicateArgsLengthInvalid(terminal, args, 1)) return; - TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - - if (!kpmInstance.isTokenAvailable()) - { // TODO: Set level to warn - terminal.error("トークンが設定されていません!"); - terminal.info("/kpm register でトークンを発行することができます!"); - kpmInstance.getSession().unlock(); - return; - } + String query = args[0]; - if (args.length == 1 && args[0].equals("$-CF$")) // TODO: Remove this and refactor to new Question system. - { - terminal.success(ChatColor.GREEN + "実行中のインストールをキャンセルしました。"); - return; - } - - if (!kpmInstance.getSession().lock()) - { - terminal.error("TeamKunPluginManagerが多重起動しています。"); - return; - } + TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> { - Installer.install(terminal, args[0], false, false, false, false); - kpmInstance.getSession().unlock(); - }); + Runner.runAsync(() -> kpmInstance.getInstallManager().runInstall(terminal, query)); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index 0da0b33b..c9bf0e30 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -52,23 +52,37 @@ public boolean isRunning() * * @param terminal ターミナル * @param query インストールするプラグインのクエリ - * @throws IllegalStateException インストールが進行中の場合または GitHub にログインしていない場合 - * @throws IOException 予期しない例外が発生した場合 */ - public void runInstall(@NotNull Terminal terminal, @NotNull String query) throws IllegalStateException, IOException + public void runInstall(@NotNull Terminal terminal, @NotNull String query) { if (isRunning()) - throw new IllegalStateException("他のインストールが実行中です。"); + { + terminal.error("他のインストーラが起動しています。"); + return; + } if (!this.pluginManager.isTokenAvailable()) - throw new IllegalStateException("GitHubにログインしていません。"); + { + terminal.error("GitHub にログインされていません。"); + terminal.info("/kpm register でログインしてください。"); + return; + } SignalHandleManager copiedHandleManager = signalHandleManager.copy(); HeadSignalHandlers.getInstallHandlers(terminal).forEach(copiedHandleManager::register); - PluginInstaller installer = new PluginInstaller(signalHandleManager); - runningInstall = installer.getProgress(); + PluginInstaller installer; + try + { + installer = new PluginInstaller(signalHandleManager); + runningInstall = installer.getProgress(); - installer.run(query); + installer.run(query); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました。"); + } } /** From 7e96215cbece04784024300c3c929fe9fd6f4719 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 18:58:22 +0900 Subject: [PATCH 244/745] fix: Invalid predicate of enumerate signal handlers --- .../plugin/signal/SignalHandleManager.java | 4 ++-- .../teamkunpluginmanager/plugin/signal/SignalHandlerList.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java index d282b127..2046c365 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java @@ -37,8 +37,8 @@ private static List> enumerateHandlers(Object object) { return Arrays.stream(object.getClass().getMethods()).parallel() .filter(method -> method.isAnnotationPresent(SignalHandler.class)) - .filter(method -> method.getParameterCount() == 2) - .map(method -> method.getParameterTypes()[1]) + .filter(method -> method.getParameterCount() == 1) + .map(method -> method.getParameterTypes()[0]) .filter(Signal.class::isAssignableFrom) .map(clazz -> (Class) clazz) .collect(Collectors.toList()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java index f8d59af3..a6d26730 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java @@ -40,8 +40,8 @@ public void bakeAll(Object object) Arrays.stream(object.getClass().getMethods()).parallel() .filter(method -> method.isAnnotationPresent(SignalHandler.class)) .filter(method -> !this.isBaked(method)) - .filter(method -> method.getParameterCount() == 2) - .filter(method -> signalType.isAssignableFrom(method.getParameterTypes()[1])) + .filter(method -> method.getParameterCount() == 1) + .filter(method -> signalType.isAssignableFrom(method.getParameterTypes()[0])) .forEach(method -> { method.setAccessible(true); From 062a01f4d4fa548e90b3fd3f841f20cc000079e4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 19:11:42 +0900 Subject: [PATCH 245/745] fix: Invalid manager passing --- .../teamkunpluginmanager/plugin/installer/InstallManager.java | 2 +- .../teamkunpluginmanager/plugin/signal/SignalHandlerList.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index c9bf0e30..d703c497 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -73,7 +73,7 @@ public void runInstall(@NotNull Terminal terminal, @NotNull String query) PluginInstaller installer; try { - installer = new PluginInstaller(signalHandleManager); + installer = new PluginInstaller(copiedHandleManager); runningInstall = installer.getProgress(); installer.run(query); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java index a6d26730..a8ada001 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java @@ -60,7 +60,7 @@ void onSignal(InstallProgress installProgress, T signal) handlers.forEach(pair -> { try { - pair.getRight().invoke(pair.getLeft(), installProgress, signal); + pair.getRight().invoke(pair.getLeft(), signal); } catch (Exception e) { From 8337a200eb90f53e13c68d0c510cde325e438c47 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 19:30:04 +0900 Subject: [PATCH 246/745] fix: ZerodivException --- .../handlers/common/InstallFinishedSignalHandler.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java index f7d01aea..c8864d60 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java @@ -53,6 +53,14 @@ private void onFail(InstallFailedInstallResult result) Enum reason = result.getReason(); Enum taskStatus = result.getTaskStatus(); - terminal.error("インストールは " + progress + " 時に " + reason + " により失敗しました(" + taskStatus + ")"); + + String errorMessage = "インストールは %s(%s) 時に %s により失敗しました。"; + + terminal.error(String.format( + errorMessage, + progress, + taskStatus, + reason + )); } } From 5c34915fee836a30d118944ae17793d2ae30f6b8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 19:33:20 +0900 Subject: [PATCH 247/745] fix: ZerodivException --- .../signal/handlers/intall/DownloadingSignalHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java index 8022e31c..df68bdbe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java @@ -50,12 +50,15 @@ private void endDownloads() { long elapsedMillis = System.currentTimeMillis() - this.downloadStarted; long elapsedSec = elapsedMillis / 1000; + if (elapsedSec == 0) + elapsedSec = 1; long bytesPerSec = this.downloadTotalSize / elapsedSec; terminal.writeLine( ChatColor.GREEN + PluginUtil.getFileSizeString(this.downloadTotalSize) + " を " + ChatColor.YELLOW + elapsedSec + "秒" + ChatColor.GREEN + "で取得しました (" + - ChatColor.YELLOW + PluginUtil.getFileSizeString(bytesPerSec) + "/s)" + ChatColor.YELLOW + PluginUtil.getFileSizeString(bytesPerSec) + "/s" + + ChatColor.GREEN + ")" ); this.currentDownload = null; From 3924f76127f07a30cd3a513d4b46e7e30a5b5391 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 19:47:53 +0900 Subject: [PATCH 248/745] fix: Download signal multi --- .../intall/DownloadingSignalHandler.java | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java index df68bdbe..e964cd8c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java @@ -2,10 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsDownloadFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadErrorSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadSucceedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; @@ -19,11 +18,9 @@ public class DownloadingSignalHandler private String currentDownload; // Ignore DownloadStartingSignal - private long downloads; private long downloadTotalSize; private long downloadStarted; private Progressbar downloadProgressBar; - private boolean mainDescriptionLoaded; public DownloadingSignalHandler(Terminal terminal) { @@ -33,7 +30,6 @@ public DownloadingSignalHandler(Terminal terminal) private void startDownloads(String id) { this.currentDownload = id; - this.downloads = 0; this.downloadTotalSize = 0; this.downloadStarted = System.currentTimeMillis(); this.downloadProgressBar = terminal.createProgressbar("ダウンロード"); @@ -43,7 +39,7 @@ private void startDownloads(String id) private void addDownloadArtifact(String url, long size) { this.downloadTotalSize += size; - terminal.writeLine(ChatColor.GREEN + "取得:" + ++downloads + " " + url + " [" + PluginUtil.getFileSizeString(size) + "]"); + terminal.writeLine(ChatColor.GREEN + "取得 " + url + " [" + PluginUtil.getFileSizeString(size) + "]"); } private void endDownloads() @@ -73,38 +69,21 @@ public void onDownloadingSignal(DownloadProgressSignal signal) this.addDownloadArtifact(signal.getUrl(), signal.getTotalSize()); } - if (!currentDownload.equals(signal.getDownloadId())) - this.addDownloadArtifact(signal.getUrl(), signal.getTotalSize()); - double percent = (double) signal.getDownloaded() / signal.getTotalSize(); this.downloadProgressBar.setProgress((int) (percent * 100)); // max 100 } @SignalHandler - public void onDownloadsEnd(LoadPluginDescriptionSignal signal) + public void onDownloadFailed(DownloadErrorSignal signal) { - // Typically, this signal is called after all downloads are finished. - // But, first time, this signal is called after one download to resolve dependencies. - // So, we need to handle first time only. - - if (mainDescriptionLoaded) - return; - - mainDescriptionLoaded = true; - this.endDownloads(); + terminal.writeLine(String.format(ChatColor.RED + "失敗 %s: %s(%s)", + signal.getUrl(), signal.getCause(), signal.getValue() + )); } @SignalHandler - public void onDownloadsEnd(DependsDownloadFinishedSignal signal) + public void onDownloadFinished(DownloadSucceedSignal signal) { this.endDownloads(); } - - @SignalHandler - public void onDownloadFailed(DownloadErrorSignal signal) - { - terminal.writeLine(String.format(ChatColor.RED + "失敗:%d %s: %s(%s)", - this.downloads, signal.getUrl(), signal.getCause(), signal.getValue() - )); - } } From 1ab21d36174a61d2ebbfd65d1ba7b09ccad5357a Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 19:49:56 +0900 Subject: [PATCH 249/745] feat: More info in dependency mismatch --- .../signal/handlers/intall/DependenciesSignalHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java index fbefce66..43487fae 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java @@ -50,6 +50,7 @@ public void onDependencyLoadDescriptionFailed(DependencyLoadDescriptionFailedSig public void onDependencyNameMismatch(DependencyNameMismatchSignal signal) { terminal.error("依存関係の整合性が確認できませんでした: " + signal.getFailedDependency()); + terminal.info("他のバージョンのプラグインを使用することで解決できる可能性があります。"); } @SignalHandler From 2709650449cc629807e0a36d6101c443830d6972 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 19:55:20 +0900 Subject: [PATCH 250/745] fix: Unexpected behavioro of Stream#parallel --- .../task/tasks/dependencies/collector/DependsCollectTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 6b7664f4..fcb187a1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -107,7 +107,7 @@ public DependsCollectTask(@NotNull InstallProgress progress, @NotNull Sign // Remove failed dependencies from load description results dependsDescriptions.entrySet().removeIf(entry -> entry.getValue() == null); - dependsDescriptions.entrySet().stream().parallel() + dependsDescriptions.entrySet().stream() .filter(entry -> Objects.nonNull(entry.getValue())) .filter(entry -> downloadResults.containsKey(entry.getKey())) .forEach(entry -> { From dd9520341dedec92f297e0bd5359a686b07d1456 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 21:25:02 +0900 Subject: [PATCH 251/745] fix: Invalid condition check of collecting failed dependency --- .../task/tasks/dependencies/collector/DependsCollectResult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java index 388fb8fa..6a3305ab 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java @@ -43,7 +43,7 @@ public DependsCollectResult(@NotNull DependsCollectState taskState, @NotNull List collectedPlugins, @NotNull List collectFailedPlugins) { - super(!collectedPlugins.isEmpty(), taskState, errorCause); + super(collectFailedPlugins.isEmpty(), taskState, errorCause); this.targetPlugin = targetPlugin; this.collectedPlugins = collectedPlugins; this.collectFailedPlugins = collectFailedPlugins; From 7c14660b84686486e5e68be5a320966586b31e0a Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 11 Sep 2022 21:28:53 +0900 Subject: [PATCH 252/745] fix: Duplicate message --- .../commands/signal/handlers/intall/InstallerSignalHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java index 040ff872..6722c96c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java @@ -45,7 +45,7 @@ public void onPluginLoadPre(PluginLoadSignal.Pre signal) } @SignalHandler - public void onPluginLoading(PluginEnablingSignal signal) + public void onPluginLoading(PluginEnablingSignal.Pre signal) { terminal.writeLine(ChatColor.GREEN + PluginUtil.getPluginString(signal.getPlugin().getDescription()) + " のトリガを処理しています ..."); From bd4b6b1b78a463b2677cfd661baf53c0f44159f0 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 20:25:32 +0900 Subject: [PATCH 253/745] refactor: Refactor #printResultStatistics to InstallerUtils --- .../common/InstallFinishedSignalHandler.java | 20 +++-------------- .../lab/teamkunpluginmanager/utils/Utils.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java index c8864d60..73c35373 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java @@ -5,13 +5,10 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; -import org.bukkit.ChatColor; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; public class InstallFinishedSignalHandler { - private static final String statsFormat = - ChatColor.GREEN + "%d 追加 " + ChatColor.RED + "%d 削除 " + ChatColor.YELLOW + "%d 変更 " + ChatColor.GRAY + "%d 保留"; - private final Terminal terminal; public InstallFinishedSignalHandler(Terminal terminal) @@ -28,26 +25,15 @@ public void onFinished(InstallFinishedSignal finished) onSuccess(finished.getResult()); } - private void printResultStatistics(InstallResult result) - { - terminal.writeLine(String.format( - statsFormat, - result.getInstalledCount(), - result.getRemovedCount(), - result.getUpgradedCount(), - result.getPendingCount() - )); - } - private void onSuccess(InstallResult result) { - printResultStatistics(result); + Utils.printInstallStatistics(terminal, result); terminal.success("インストールが正常に完了しました。"); } private void onFail(InstallFailedInstallResult result) { - printResultStatistics(result); + Utils.printInstallStatistics(terminal, result); Enum progress = result.getProgress().getCurrentTask(); Enum reason = result.getReason(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java new file mode 100644 index 00000000..59ef20c9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.utils; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import org.bukkit.ChatColor; + +public class Utils +{ + public static final String STATS_FORMAT + = ChatColor.GREEN + "%d 追加 " + ChatColor.RED + "%d 削除 " + ChatColor.YELLOW + "%d 変更 " + ChatColor.GRAY + "%d 保留"; + + public static void printInstallStatistics(Terminal terminal, InstallResult result) + { + terminal.writeLine(String.format( + STATS_FORMAT, + result.getInstalledCount(), + result.getRemovedCount(), + result.getUpgradedCount(), + result.getPendingCount() + )); + } +} From 8593a1d6fa4ebc4b075e451b3c7eeb7a4480c092 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 20:39:54 +0900 Subject: [PATCH 254/745] refactor: Refactor Utils#roundSizeUnit --- .../commands/CommandInfo.java | 3 +- .../commands/CommandUpdate.java | 8 +++--- .../intall/DownloadingSignalHandler.java | 8 +++--- .../plugin/Installer.java | 3 +- .../utils/PluginUtil.java | 28 ------------------- .../lab/teamkunpluginmanager/utils/Utils.java | 25 +++++++++++++++++ 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index 52972a2d..cb539b89 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -7,6 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree.Info; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; @@ -127,7 +128,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { terminal.writeLine(""); terminal.writeLine(Messages.keyValue("ファイル名", file.getName())); - terminal.writeLine(Messages.keyValue("ダウンロードサイズ", PluginUtil.getFileSizeString(file.length()))); + terminal.writeLine(Messages.keyValue("ダウンロードサイズ", Utils.roundSizeUnit(file.length()))); } terminal.writeLine(""); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 44a131eb..65f2775b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -9,7 +9,7 @@ import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import net.kyori.adventure.text.TextComponent; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -112,7 +112,7 @@ private static DownloadResult doDownload(Terminal terminal) terminal.writeLine(ChatColor.GREEN + "取得:" + num.incrementAndGet() + - " " + url + " [" + PluginUtil.getFileSizeString(file.length()) + "]"); + " " + url + " [" + Utils.roundSizeUnit(file.length()) + "]"); } catch (MalformedURLException e) { @@ -150,11 +150,11 @@ private static void printDownloadMessage(Terminal terminal, DownloadResult resul terminal.writeLine( ChatColor.LIGHT_PURPLE + - PluginUtil.getFileSizeString(size.get()) + + Utils.roundSizeUnit(size.get()) + " を " + seconds + "秒 で取得しました (" + - PluginUtil.getFileSizeString(size.get() / ((long) seconds == 0 ? 1: (long) seconds)) + + Utils.roundSizeUnit(size.get() / ((long) seconds == 0 ? 1: (long) seconds)) + "/s)" ); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java index e964cd8c..65e6f9d5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java @@ -6,7 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadSucceedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; /** @@ -39,7 +39,7 @@ private void startDownloads(String id) private void addDownloadArtifact(String url, long size) { this.downloadTotalSize += size; - terminal.writeLine(ChatColor.GREEN + "取得 " + url + " [" + PluginUtil.getFileSizeString(size) + "]"); + terminal.writeLine(ChatColor.GREEN + "取得 " + url + " [" + Utils.roundSizeUnit(size) + "]"); } private void endDownloads() @@ -50,10 +50,10 @@ private void endDownloads() elapsedSec = 1; long bytesPerSec = this.downloadTotalSize / elapsedSec; terminal.writeLine( - ChatColor.GREEN + PluginUtil.getFileSizeString(this.downloadTotalSize) + " を " + + ChatColor.GREEN + Utils.roundSizeUnit(this.downloadTotalSize) + " を " + ChatColor.YELLOW + elapsedSec + "秒" + ChatColor.GREEN + "で取得しました (" + - ChatColor.YELLOW + PluginUtil.getFileSizeString(bytesPerSec) + "/s" + + ChatColor.YELLOW + Utils.roundSizeUnit(bytesPerSec) + "/s" + ChatColor.GREEN + ")" ); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index a6f906d5..0b379939 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -18,6 +18,7 @@ import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.io.FileUtils; @@ -619,7 +620,7 @@ private static String getDiffMessage(File f, boolean isNew) return header + " " + pi("ファイル名", f.getName()) + - " " + pi("ファイルサイズ", f.exists() ? PluginUtil.getFileSizeString(f.length()): ChatColor.RED + "N/A") + + " " + pi("ファイルサイズ", f.exists() ? Utils.roundSizeUnit(f.length()): ChatColor.RED + "N/A") + " " + pi("SHA1", f.exists() ? HashLib.genSha1(f): ChatColor.RED + "N/A"); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index ff490bce..c7d6f43c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -17,9 +17,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; @@ -106,31 +103,6 @@ public static boolean isPluginLoaded(Plugin plugin) return ((PluginClassLoader) plugin.getClass().getClassLoader()).getPlugin() != null; } - private static final String[] fileUnits = { - "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" - }; - - public static String getFileSizeString(long bytes) - { - String suffix = "B"; - - BigDecimal dec = new BigDecimal(String.valueOf(bytes)); - BigDecimal base = new BigDecimal(1024); - - for (String fileUnit : fileUnits) - { - if (dec.compareTo(base) < 0) - { - suffix = fileUnit; - dec = dec.divide(base, 3, RoundingMode.HALF_UP); - } - else - break; - } - - return new DecimalFormat("#,###.##;#,###.##").format(dec) + suffix; - } - public static String loadToString(PluginLoadOrder order) { switch (order) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java index 59ef20c9..cb9bfaa2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java @@ -8,6 +8,17 @@ public class Utils { public static final String STATS_FORMAT = ChatColor.GREEN + "%d 追加 " + ChatColor.RED + "%d 削除 " + ChatColor.YELLOW + "%d 変更 " + ChatColor.GRAY + "%d 保留"; + public static final String[] SIZE_UNITS = { + "B", + "kB", + "MB", + "GB", + "TB", + "PB", + "EB", + "ZB", + "YB" + }; public static void printInstallStatistics(Terminal terminal, InstallResult result) { @@ -19,4 +30,18 @@ public static void printInstallStatistics(Terminal terminal, InstallResult re result.getPendingCount() )); } + + public static String roundSizeUnit(long size) + { + int unit = 0; + double dSize = size; + + while (dSize > 1024 && unit < SIZE_UNITS.length - 1) + { + dSize /= 1024; + unit++; + } + + return String.format("%.2f %s", dSize, SIZE_UNITS[unit]); + } } From 537abf98aba75c25dffcdc767083f9e6486e4dff Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 20:46:47 +0900 Subject: [PATCH 255/745] refactor: change method signature --- .../kunmc/lab/teamkunpluginmanager/utils/Utils.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java index cb9bfaa2..332fb623 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java @@ -20,15 +20,20 @@ public class Utils "YB" }; + public static void printInstallStatistics(Terminal terminal, int added, int removed, int changed, int pending) + { + terminal.writeLine(String.format(STATS_FORMAT, added, removed, changed, pending)); + } + public static void printInstallStatistics(Terminal terminal, InstallResult result) { - terminal.writeLine(String.format( - STATS_FORMAT, + printInstallStatistics( + terminal, result.getInstalledCount(), result.getRemovedCount(), result.getUpgradedCount(), result.getPendingCount() - )); + ); } public static String roundSizeUnit(long size) From ec8eb98aef895514c275451ebcfc8f1f3c33fb39 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 20:53:20 +0900 Subject: [PATCH 256/745] feat: UninstallReadySignal --- .../impls/uninstall/PluginUninstaller.java | 5 +++ .../signals/UninstallReadySignal.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/UninstallReadySignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index f0d6ee41..61afa8f9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.SearchingPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.UninstallReadySignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; @@ -97,6 +98,10 @@ public InstallResult execute(@NotNull String query) throws TaskF // endregion + UninstallReadySignal uninstallReadySignal = new UninstallReadySignal(plugins); + this.postSignal(uninstallReadySignal); + plugins = uninstallReadySignal.getPlugins(); + // region Uninstall plugin // Before uninstall plugin, we need to compute the order of plugins to uninstall. diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/UninstallReadySignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/UninstallReadySignal.java new file mode 100644 index 00000000..94e2e644 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/UninstallReadySignal.java @@ -0,0 +1,31 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals; + +import lombok.Getter; +import lombok.Setter; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.bukkit.plugin.Plugin; + +import java.util.List; + +/** + * プラグインの列挙が完了したことを通知するシグナルです。 + */ +@Getter +public class UninstallReadySignal implements Signal +{ + /** + * アンインストール対象のプラグインのリスト + */ + private final List plugins; + /** + * アンインストールを続行するかどうか + */ + @Setter + private boolean continueUninstall; + + public UninstallReadySignal(List plugins) + { + this.plugins = plugins; + this.continueUninstall = true; + } +} From 79d9bc42c3020b87589c532a0e576364f5a15b1d Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:09:24 +0900 Subject: [PATCH 257/745] feat: PluginUninstallingSignal --- .../task/tasks/uninstall/UnInstallTask.java | 3 +++ .../signals/PluginUninstallingSignal.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index c69cca0e..a5cfc960 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -7,6 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; @@ -133,6 +134,8 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan private UnInstallErrorCause uninstallOnePlugin(@NotNull Plugin plugin) { + this.postSignal(new PluginUninstallingSignal(plugin)); + this.taskState = UnInstallState.RECIPES_UNREGISTERING; this.unregisterRecipes(plugin); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java new file mode 100644 index 00000000..1d667355 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java @@ -0,0 +1,18 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.bukkit.plugin.Plugin; + +/** + * プラグインのアンインストールのシグナルです。 + */ +@Value +public class PluginUninstallingSignal implements Signal +{ + /** + * アンインストールされるプラグインです。 + */ + Plugin plugin; +} + From 5c2c49e4d8c6053f0e7b1fc4febe21b60af7cf25 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:11:53 +0900 Subject: [PATCH 258/745] feat: Shorter expression --- .../signal/handlers/intall/InstallerSignalHandler.java | 2 +- .../net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java index 6722c96c..ab8ef997 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java @@ -48,6 +48,6 @@ public void onPluginLoadPre(PluginLoadSignal.Pre signal) public void onPluginLoading(PluginEnablingSignal.Pre signal) { terminal.writeLine(ChatColor.GREEN + - PluginUtil.getPluginString(signal.getPlugin().getDescription()) + " のトリガを処理しています ..."); + PluginUtil.getPluginString(signal.getPlugin()) + " のトリガを処理しています ..."); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index c7d6f43c..baa74148 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -48,6 +48,11 @@ public static String getPluginString(PluginDescriptionFile description) return String.format("%s (%s)", description.getName(), description.getVersion()); } + public static String getPluginString(Plugin plugin) + { + return getPluginString(plugin.getDescription()); + } + @SuppressWarnings("unchecked") public static Map ms2Map(MemorySection ms) { From 8727bf8e6ec2c4137e3b60435e3aa8b9f93f388a Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:15:45 +0900 Subject: [PATCH 259/745] feat: Removing signal of PluginRegisteredRecipeSignal --- .../task/tasks/uninstall/UnInstallTask.java | 3 +++ .../signals/PluginRegisteredRecipeSignal.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index a5cfc960..2ab05fc3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -218,7 +218,10 @@ private void unregisterRecipes(@NotNull Plugin plugin) Recipe recipe = recipeIterator.next(); if (this.isRecipeRemoveTarget(plugin, targetNamespaces, recipe)) + { + this.postSignal(new PluginRegisteredRecipeSignal.Removing(plugin, recipe)); recipeIterator.remove(); + } } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java index 12af562b..db8005a7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java @@ -77,4 +77,23 @@ public Searching(@NotNull Plugin plugin) this.targetNamespaces = new String[]{plugin.getName().toLowerCase(Locale.ROOT)}; } } + + /** + * レシピを削除する前にスローされるシグナルです。 + */ + @Getter + public static class Removing extends PluginRegisteredRecipeSignal + { + /** + * 削除するレシピです。 + */ + @NotNull + private final Recipe recipe; + + public Removing(@NotNull Plugin plugin, @NotNull Recipe recipe) + { + super(plugin); + this.recipe = recipe; + } + } } From a82cc12fffd85a00019f03560633c89e8826e8d8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:28:26 +0900 Subject: [PATCH 260/745] feat: PluginUninstallErrorSignal --- .../task/tasks/uninstall/UnInstallTask.java | 4 ++++ .../signals/PluginUninstallErrorSignal.java | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 2ab05fc3..6ae674c2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -7,6 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; @@ -104,7 +105,10 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan if (errorCause == UnInstallErrorCause.INTERNAL_UNINSTALL_OK) uninstalledPlugins.add(description); else + { + this.postSignal(new PluginUninstallErrorSignal(errorCause, description)); errors.put(errorCause, description); + } } Runner.runLaterAsync(() -> { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java new file mode 100644 index 00000000..b8d1d70f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.bukkit.plugin.PluginDescriptionFile; + +/** + * プラグインのアンインストール中にエラーが発生したことを通知するシグナルです。 + */ +@Value +public class PluginUninstallErrorSignal implements Signal +{ + /** + * エラーの原因です。 + */ + UnInstallErrorCause cause; + /** + * エラーが発生したプラグインのプラグイン情報ファイルです。 + */ + PluginDescriptionFile description; +} From 70e090ab60d92b2a4096c71b379b7c24011b68df Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:29:02 +0900 Subject: [PATCH 261/745] feat: StartingGCSignal --- .../installer/task/tasks/uninstall/UnInstallTask.java | 2 ++ .../task/tasks/uninstall/signals/StartingGCSignal.java | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 6ae674c2..d06e0436 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -10,6 +10,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.StartingGCSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; @@ -125,6 +126,7 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan .map(Plugin::getDescription) .forEach(UnInstallTask.this.progress::addRemoved); + this.postSignal(new StartingGCSignal()); System.gc(); Bukkit.getOnlinePlayers().forEach(Player::updateCommands); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java new file mode 100644 index 00000000..a7faa294 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals; + +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +/** + * VMのGCを実行することを通知するシグナルです。 + */ +public class StartingGCSignal implements Signal +{ +} From 6e8c7dca5f5ecf502e67591f9905714f1eb8c647 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:32:27 +0900 Subject: [PATCH 262/745] =?UTF-8?q?fix:=20Invalid=20string:=20"=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../signal/handlers/common/InstallFinishedSignalHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java index 73c35373..e0ae6d20 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java @@ -28,7 +28,7 @@ public void onFinished(InstallFinishedSignal finished) private void onSuccess(InstallResult result) { Utils.printInstallStatistics(terminal, result); - terminal.success("インストールが正常に完了しました。"); + terminal.success("操作が正常に完了しました。"); } private void onFail(InstallFailedInstallResult result) @@ -40,7 +40,7 @@ private void onFail(InstallFailedInstallResult result) Enum taskStatus = result.getTaskStatus(); - String errorMessage = "インストールは %s(%s) 時に %s により失敗しました。"; + String errorMessage = "操作は %s(%s) 時に %s により失敗しました。"; terminal.error(String.format( errorMessage, From 72aaba2bc479a1fee7c4a90e289f21cbd338aa88 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:43:15 +0900 Subject: [PATCH 263/745] feat: Uninstall head --- .../commands/CommandUninstall.java | 14 +-- .../commands/signal/HeadSignalHandlers.java | 15 +++ .../uninstall/UninstallerSignalHandler.java | 107 ++++++++++++++++++ .../plugin/installer/InstallManager.java | 16 ++- .../plugin/signal/SignalHandlerList.java | 1 + 5 files changed, 139 insertions(+), 14 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index f5f43ea1..23fd0322 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -4,7 +4,6 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -24,16 +23,11 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (indicateArgsLengthInvalid(terminal, args, 1, 1)) return; - if (!TeamKunPluginManager.getPlugin().getSession().lock()) - { - terminal.error("TeamKunPluginManagerが多重起動しています。"); - return; - } + String query = args[0]; + + TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> { - Installer.unInstall(terminal, args[0], false); - TeamKunPluginManager.getPlugin().getSession().unlock(); - }); + Runner.runAsync(() -> kpmInstance.getInstallManager().runUninstall(terminal, query)); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index 4807f191..cd30d4cc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -8,6 +8,7 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DownloadingSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.ResolverSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallerSignalHandler; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -63,4 +64,18 @@ public static List getInstallHandlers(@NotNull Terminal terminal) new InstallerSignalHandler(terminal) ); } + + /** + * アンインストールに使用するハンドラを返します. + * + * @param terminal ターミナル + * @return アンインストールに使用するハンドラ + */ + public static List getUninstallHandlers(@NotNull Terminal terminal) + { + return createHandlersList( + getCommonHandlers(terminal), + new UninstallerSignalHandler(terminal) + ); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java new file mode 100644 index 00000000..e467d9bd --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java @@ -0,0 +1,107 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.UninstallReadySignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; +import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; + +import java.util.List; +import java.util.stream.Collectors; + +public class UninstallerSignalHandler +{ + private final Terminal terminal; + + public UninstallerSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + private static String getErrorCauseMessage(PluginUninstallErrorSignal signal) + { + switch (signal.getCause()) + { + case INTERNAL_CLASS_UNLOAD_FAILED: + return "クラスのアンロードに失敗しました。"; + case INTERNAL_PLUGIN_DISABLE_FAILED: + return "プラグインの無効化に失敗しました。"; + default: + return "不明なエラーが発生しました。"; + } + } + + private void printUninstallInfo(List uninstallTargets) + { + terminal.writeLine(ChatColor.GREEN + "以下のパッケージは「" + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); + terminal.writeLine(" " + uninstallTargets.stream() + .map(Plugin::getName) + .sorted() + .collect(Collectors.joining(" "))); + Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); + } + + private boolean pollContinue() + { + try + { + QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?").waitAndGetResult(); + return result.test(QuestionAttribute.YES); + } + catch (InterruptedException e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました: " + e.getMessage()); + return false; + } + } + + @SignalHandler + public void onPluginsEnumerated(UninstallReadySignal signal) + { + printUninstallInfo(signal.getPlugins()); + signal.setContinueUninstall(pollContinue()); + } + + @SignalHandler + public void onPluginUninstall(PluginUninstallingSignal signal) + { + terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " をアンインストールしています ..."); + } + + @SignalHandler + public void onRecipeRemove(PluginRegisteredRecipeSignal.Removing signal) + { + terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " のレシピを削除しています ..."); + } + + @SignalHandler + public void onDisabling(PluginDisablingSignal.Pre signal) + { + terminal.writeLine(ChatColor.GREEN + PluginUtil.getPluginString(signal.getPlugin()) + " のトリガを処理しています ..."); + } + + @SignalHandler + public void onUnloading(PluginUnloadingSignal.Pre signal) + { + terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " を削除しています ..."); + } + + @SignalHandler + public void onError(PluginUninstallErrorSignal signal) + { + terminal.error( + ChatColor.GREEN + PluginUtil.getPluginString(signal.getDescription()) + " のアンインストールに失敗しました: ", + getErrorCauseMessage(signal) + ); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index d703c497..e38188b6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -88,16 +88,24 @@ public void runInstall(@NotNull Terminal terminal, @NotNull String query) /** * アンインストールを実行します。 * - * @param query アンインストールするプラグインのクエリ + * @param terminal ターミナル + * @param query アンインストールするプラグインのクエリ * @throws IllegalStateException インストールが進行中の場合 * @throws IOException 予期しない例外が発生した場合 */ - public void runUninstall(@NotNull String query) throws IllegalStateException, IOException + public void runUninstall(@NotNull Terminal terminal, @NotNull String query) throws IllegalStateException, IOException { if (isRunning()) - throw new IllegalStateException("他のインストールが実行中です。"); + { + terminal.error("他のインストーラが起動しています。"); + return; + } + + SignalHandleManager copiedHandleManager = signalHandleManager.copy(); + HeadSignalHandlers.getUninstallHandlers(terminal).forEach(copiedHandleManager::register); + - PluginUninstaller uninstaller = new PluginUninstaller(signalHandleManager); + PluginUninstaller uninstaller = new PluginUninstaller(copiedHandleManager); runningInstall = uninstaller.getProgress(); uninstaller.run(query); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java index a8ada001..1f9dcf56 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java @@ -64,6 +64,7 @@ void onSignal(InstallProgress installProgress, T signal) } catch (Exception e) { + System.out.println("Target: " + pair.getRight().getDeclaringClass().getName() + "#" + pair.getRight().getName()); e.printStackTrace(); } }); From 25e5579c4019ef9a3ae6e9a0a3d267e957fea2d7 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:53:56 +0900 Subject: [PATCH 264/745] fix: Stats level of new installation --- .../plugin/installer/task/tasks/install/PluginsInstallTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index a6f365d0..8588465d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -129,7 +129,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr assert target != null; this.postSignal(new PluginLoadSignal.Post(path, pluginDescription, target)); - this.progress.addInstalled(target.getDescription()); + this.progress.addPending(target.getName()); // Run Plugin#onLoad this.state = PluginsInstallState.ONLOAD_RUNNING; From aa4b97e8b746cdb49cc7660aade366f568190762 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 21:54:10 +0900 Subject: [PATCH 265/745] refactor: Replace with lambda --- .../installer/task/tasks/install/PluginsInstallTask.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index 8588465d..5523e4ec 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -96,9 +96,7 @@ private static void patchPluginCommands(List targets) } finally { - Runner.runLater(() -> { - patchPluginCommands(installedPlugins); - }, 1L); + Runner.runLater(() -> patchPluginCommands(installedPlugins), 1L); } } From 5a6b7c90f9ae138917ef2c0a5db05e36e5f4e723 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 22:15:53 +0900 Subject: [PATCH 266/745] refactor: AbstractInstaller => installer.AbstractInstaller --- .../plugin/{ => installer}/AbstractInstaller.java | 5 +---- .../plugin/installer/InstallProgress.java | 1 - .../plugin/installer/impls/install/PluginInstaller.java | 2 +- .../plugin/installer/impls/uninstall/PluginUninstaller.java | 2 +- .../plugin/installer/task/TaskChain.java | 2 +- 5 files changed, 4 insertions(+), 8 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/{ => installer}/AbstractInstaller.java (93%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java similarity index 93% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java index e4879a3b..56584ce3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java @@ -1,10 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin; +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.GeneralTaskErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index d99f7f07..7aae20df 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -4,7 +4,6 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectStatus; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index 50cec0f1..48e57f02 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -1,7 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index 61afa8f9..a63ec939 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -1,7 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; -import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.SearchingPluginSignal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java index 64c0609b..9a3b0993 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java @@ -2,7 +2,7 @@ import lombok.AccessLevel; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; From 59df1fed69d5165822b2abe5ad207cf188b5da21 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 22:32:00 +0900 Subject: [PATCH 267/745] feat: Custom argument type of installer --- .../commands/CommandInstall.java | 5 +- .../commands/CommandUninstall.java | 5 +- .../plugin/installer/AbstractInstaller.java | 10 ++-- .../installer/AbstractInstallerArgument.java | 5 ++ .../plugin/installer/InstallManager.java | 14 ++--- .../plugin/installer/InstallProgress.java | 4 +- .../impls/install/InstallArgument.java | 20 +++++++ .../impls/install/PluginInstaller.java | 6 ++- .../impls/uninstall/PluginUninstaller.java | 52 +++++++++++-------- .../impls/uninstall/UninstallArgument.java | 32 ++++++++++++ .../plugin/installer/task/TaskChain.java | 6 +-- 11 files changed, 118 insertions(+), 41 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UninstallArgument.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index a171e32a..2611705a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -4,6 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -23,7 +24,9 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> kpmInstance.getInstallManager().runInstall(terminal, query)); + Runner.runAsync(() -> + kpmInstance.getInstallManager().runInstall(terminal, new InstallArgument(query)) + ); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index 23fd0322..9bff6ccf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -4,6 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -27,7 +28,9 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> kpmInstance.getInstallManager().runUninstall(terminal, query)); + Runner.runAsync(() -> + kpmInstance.getInstallManager().runUninstall(terminal, new UninstallArgument(query)) + ); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java index 56584ce3..39821f47 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java @@ -16,10 +16,10 @@ import java.io.File; import java.io.IOException; -public abstract class AbstractInstaller, P extends Enum

    > +public abstract class AbstractInstaller, P extends Enum

    > { @Getter - protected final InstallProgress> progress; + protected final InstallProgress> progress; protected final SignalHandleManager signalHandler; public AbstractInstaller(SignalHandleManager signalHandler) throws IOException @@ -33,13 +33,13 @@ protected void postSignal(@NotNull Signal signal) this.signalHandler.handleSignal(this.progress, signal); } - protected abstract InstallResult

    execute(@NotNull String query) throws IOException, TaskFailedException; + protected abstract InstallResult

    execute(@NotNull A arguments) throws IOException, TaskFailedException; - public InstallResult

    run(@NotNull String query) throws IOException + public InstallResult

    run(@NotNull A arguments) throws IOException { try { - return this.execute(query); + return this.execute(arguments); } catch (TaskFailedException e) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java new file mode 100644 index 00000000..a1351374 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer; + +public abstract class AbstractInstallerArgument +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index e38188b6..c1c068f9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -3,8 +3,10 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.commands.signal.HeadSignalHandlers; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; @@ -51,9 +53,9 @@ public boolean isRunning() * インストールを実行します。 * * @param terminal ターミナル - * @param query インストールするプラグインのクエリ + * @param argument インストールの引数 */ - public void runInstall(@NotNull Terminal terminal, @NotNull String query) + public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argument) { if (isRunning()) { @@ -76,7 +78,7 @@ public void runInstall(@NotNull Terminal terminal, @NotNull String query) installer = new PluginInstaller(copiedHandleManager); runningInstall = installer.getProgress(); - installer.run(query); + installer.run(argument); } catch (IOException e) { @@ -89,11 +91,11 @@ public void runInstall(@NotNull Terminal terminal, @NotNull String query) * アンインストールを実行します。 * * @param terminal ターミナル - * @param query アンインストールするプラグインのクエリ + * @param argument アンインストールするプラグインのクエリ * @throws IllegalStateException インストールが進行中の場合 * @throws IOException 予期しない例外が発生した場合 */ - public void runUninstall(@NotNull Terminal terminal, @NotNull String query) throws IllegalStateException, IOException + public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument argument) throws IllegalStateException, IOException { if (isRunning()) { @@ -108,6 +110,6 @@ public void runUninstall(@NotNull Terminal terminal, @NotNull String query) thro PluginUninstaller uninstaller = new PluginUninstaller(copiedHandleManager); runningInstall = uninstaller.getProgress(); - uninstaller.run(query); + uninstaller.run(argument); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 7aae20df..abedf71b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -27,7 +27,7 @@ * @param インストーラの状態の型 */ @Getter -public class InstallProgress, I extends AbstractInstaller> +public class InstallProgress, I extends AbstractInstaller> { @Getter(AccessLevel.NONE) private static final HashMap> PROGRESS_CACHES; @@ -142,7 +142,7 @@ private InstallProgress(@NotNull I installer, * @throws IOException ディレクトリの作成に失敗した場合 * @throws SecurityException ディレクトリの作成に失敗した場合 */ - public static

    , PI extends AbstractInstaller> InstallProgress of( + public static

    , PI extends AbstractInstaller> InstallProgress of( @NotNull PI installer, @NotNull SignalHandleManager signalHandler, @Nullable String id) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallArgument.java new file mode 100644 index 00000000..2f59d92a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallArgument.java @@ -0,0 +1,20 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import org.jetbrains.annotations.NotNull; + +/** + * インストールの引数を格納するクラスです。 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class InstallArgument extends AbstractInstallerArgument +{ + /** + * インストールするプラグインのクエリ + */ + @NotNull + private final String query; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index 48e57f02..4459b42e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -45,7 +45,7 @@ *

  • 依存関係とプラグインをインストールする({@link InstallTasks#INSTALLING_PLUGINS})。
  • * */ -public class PluginInstaller extends AbstractInstaller +public class PluginInstaller extends AbstractInstaller { public PluginInstaller(@NotNull SignalHandleManager signalHandler) throws IOException { @@ -54,8 +54,10 @@ public PluginInstaller(@NotNull SignalHandleManager signalHandler) throws IOExce @Override @SuppressWarnings("rawtypes") - public InstallResult execute(@NotNull String query) throws TaskFailedException + public InstallResult execute(@NotNull InstallArgument argument) throws TaskFailedException { + String query = argument.getQuery(); + Path pluginFilePath; PluginDescriptionFile pluginDescription; String pluginName; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index a63ec939..42578409 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -40,7 +40,7 @@ *
  • {@link UnInstallTasks#UNINSTALLING_PLUGINS} - プラグインをアンインストールする。
  • * */ -public class PluginUninstaller extends AbstractInstaller +public class PluginUninstaller extends AbstractInstaller { public PluginUninstaller(SignalHandleManager signalHandler) throws IOException { @@ -48,17 +48,20 @@ public PluginUninstaller(SignalHandleManager signalHandler) throws IOException } @Override - public InstallResult execute(@NotNull String query) throws TaskFailedException + public InstallResult execute(@NotNull UninstallArgument argument) throws TaskFailedException { List plugins = new ArrayList<>(); // region Search plugin this.progress.setCurrentTask(UnInstallTasks.SEARCHING_PLUGIN); - Plugin plugin = this.getPlugin(query); - if (plugin == null) - return this.error(UnInstallErrorCause.PLUGIN_NOT_FOUND); + for (String pluginName : argument.getPlugins()) + { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin == null) + return this.error(UnInstallErrorCause.PLUGIN_NOT_FOUND); - plugins.add(plugin); + plugins.add(plugin); + } // endregion @@ -67,31 +70,38 @@ public InstallResult execute(@NotNull String query) throws TaskF this.progress.setCurrentTask(UnInstallTasks.CHECKING_ENVIRONMENT); // region Check is plugin marked as ignored - if (this.isPluginIgnored(plugin.getName())) + for (Plugin plugin : plugins) { - IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(plugin.getDescription()); - this.postSignal(ignoredPluginSignal); - if (ignoredPluginSignal.isCancelInstall()) - return this.error(UnInstallErrorCause.PLUGIN_IGNORED); + if (this.isPluginIgnored(plugin.getName())) + { + IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(plugin.getDescription()); + this.postSignal(ignoredPluginSignal); + if (ignoredPluginSignal.isCancelInstall()) + return this.error(UnInstallErrorCause.PLUGIN_IGNORED); + } } // endregion // region Check plugin are depended by other plugins - List dependencies = this.getAllDependencies(plugin); - - if (!dependencies.isEmpty()) + for (Plugin plugin : plugins) { - PluginIsDependencySignal pluginIsDependencySignal = - new PluginIsDependencySignal(plugin.getName(), dependencies); + List dependencies = this.getAllDependencies(plugin); + dependencies.removeAll(plugins); + + if (!dependencies.isEmpty()) + { + PluginIsDependencySignal pluginIsDependencySignal = + new PluginIsDependencySignal(plugin.getName(), dependencies); - this.postSignal(pluginIsDependencySignal); + this.postSignal(pluginIsDependencySignal); - if (pluginIsDependencySignal.isForceUninstall()) - plugins.addAll(dependencies); - else - return this.error(UnInstallErrorCause.PLUGIN_IS_DEPENDENCY); + if (pluginIsDependencySignal.isForceUninstall()) + plugins.addAll(dependencies); + else + return this.error(UnInstallErrorCause.PLUGIN_IS_DEPENDENCY); + } } // endregion diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UninstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UninstallArgument.java new file mode 100644 index 00000000..fdaf5e1b --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UninstallArgument.java @@ -0,0 +1,32 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import org.jetbrains.annotations.NotNull; + +/** + * アンインストールの引数を格納するクラスです。 + */ +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class UninstallArgument extends AbstractInstallerArgument +{ + /** + * アンインストールするプラグインの名前 + */ + @NotNull + private final String[] plugins; + + /** + * 単一のプラグインをアンインストールするための引数を生成します。 + * + * @param plugin アンインストールするプラグイン + */ + public UninstallArgument(@NotNull String plugin) + { + this(new String[]{plugin}); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java index 9a3b0993..3226c992 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java @@ -33,7 +33,7 @@ public class TaskChain< private final IS installerState; @NotNull - private final AbstractInstaller installer; + private final AbstractInstaller installer; @Nullable @Setter(AccessLevel.NONE) @@ -54,7 +54,7 @@ public class TaskChain< * @param installer インストーラ */ public TaskChain(@NotNull T task, @NotNull IS installerState, @Nullable TaskChain first, - @NotNull AbstractInstaller installer) + @NotNull AbstractInstaller installer) { this.task = task; this.installerState = installerState; @@ -69,7 +69,7 @@ public TaskChain(@NotNull T task, @NotNull IS installerState, @Nullable TaskChai * @param installerState 設定するインストーラの状態 * @param installer インストーラ */ - public TaskChain(@NotNull T task, @NotNull IS installerState, @NotNull AbstractInstaller installer) + public TaskChain(@NotNull T task, @NotNull IS installerState, @NotNull AbstractInstaller installer) { this(task, installerState, null, installer); this.first = this; From cd838be2469b9dd6b5161353ecb4b776308e95c4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 22:34:49 +0900 Subject: [PATCH 268/745] refactor: Extract UninstallReadySignal handler from UninstallerSignalHandler --- .../commands/signal/HeadSignalHandlers.java | 4 +- .../UninstallReadySignalHandler.java | 55 +++++++++++++++++++ .../uninstall/UninstallerSignalHandler.java | 40 -------------- 3 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index cd30d4cc..5236f6ed 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -8,6 +8,7 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DownloadingSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.ResolverSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallReadySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallerSignalHandler; import org.jetbrains.annotations.NotNull; @@ -75,7 +76,8 @@ public static List getUninstallHandlers(@NotNull Terminal terminal) { return createHandlersList( getCommonHandlers(terminal), - new UninstallerSignalHandler(terminal) + new UninstallerSignalHandler(terminal), + new UninstallReadySignalHandler(terminal) ); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java new file mode 100644 index 00000000..f7227aec --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -0,0 +1,55 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.UninstallReadySignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; +import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; + +import java.util.List; +import java.util.stream.Collectors; + +public class UninstallReadySignalHandler +{ + private final Terminal terminal; + + public UninstallReadySignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + private void printUninstallInfo(List uninstallTargets) + { + terminal.writeLine(ChatColor.GREEN + "以下のパッケージは「" + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); + terminal.writeLine(" " + uninstallTargets.stream() + .map(Plugin::getName) + .sorted() + .collect(Collectors.joining(" "))); + Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); + } + + private boolean pollContinue() + { + try + { + QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?").waitAndGetResult(); + return result.test(QuestionAttribute.YES); + } + catch (InterruptedException e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました: " + e.getMessage()); + return false; + } + } + + @SignalHandler + public void onPluginsEnumerated(UninstallReadySignal signal) + { + printUninstallInfo(signal.getPlugins()); + signal.setContinueUninstall(pollContinue()); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java index e467d9bd..fd66c483 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java @@ -1,9 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.UninstallReadySignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; @@ -11,12 +8,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; -import org.bukkit.plugin.Plugin; - -import java.util.List; -import java.util.stream.Collectors; public class UninstallerSignalHandler { @@ -40,38 +32,6 @@ private static String getErrorCauseMessage(PluginUninstallErrorSignal signal) } } - private void printUninstallInfo(List uninstallTargets) - { - terminal.writeLine(ChatColor.GREEN + "以下のパッケージは「" + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); - terminal.writeLine(" " + uninstallTargets.stream() - .map(Plugin::getName) - .sorted() - .collect(Collectors.joining(" "))); - Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); - } - - private boolean pollContinue() - { - try - { - QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?").waitAndGetResult(); - return result.test(QuestionAttribute.YES); - } - catch (InterruptedException e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました: " + e.getMessage()); - return false; - } - } - - @SignalHandler - public void onPluginsEnumerated(UninstallReadySignal signal) - { - printUninstallInfo(signal.getPlugins()); - signal.setContinueUninstall(pollContinue()); - } - @SignalHandler public void onPluginUninstall(PluginUninstallingSignal signal) { From 178e435e4f3cf9b6f15d0744c498f90a3865a4dc Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 22:39:02 +0900 Subject: [PATCH 269/745] refactor: Change type of PluginIsDependencySignal --- .../plugin/installer/impls/uninstall/PluginUninstaller.java | 2 +- .../impls/uninstall/signals/PluginIsDependencySignal.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index 42578409..5600ea98 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -93,7 +93,7 @@ public InstallResult execute(@NotNull UninstallArgument argument if (!dependencies.isEmpty()) { PluginIsDependencySignal pluginIsDependencySignal = - new PluginIsDependencySignal(plugin.getName(), dependencies); + new PluginIsDependencySignal(plugin, dependencies); this.postSignal(pluginIsDependencySignal); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java index 545b8ad0..e6e4db1f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java @@ -15,7 +15,7 @@ public class PluginIsDependencySignal implements Signal { @NotNull - private final String pluginName; + private final Plugin plugin; @NotNull private final List dependedBy; @@ -25,9 +25,9 @@ public class PluginIsDependencySignal implements Signal */ private boolean forceUninstall; - public PluginIsDependencySignal(@NotNull String pluginName, @NotNull List dependedBy) + public PluginIsDependencySignal(@NotNull Plugin plugin, @NotNull List dependedBy) { - this.pluginName = pluginName; + this.plugin = plugin; this.dependedBy = dependedBy; this.forceUninstall = false; } From f8182430b9a573bd649b0af8de3e3a3f9e1cbe7d Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 22:45:57 +0900 Subject: [PATCH 270/745] feat: Head of installing plugin's dependencies --- .../commands/signal/HeadSignalHandlers.java | 2 + .../PluginIsDependencySignalHandler.java | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index 5236f6ed..149e263f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -8,6 +8,7 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DownloadingSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.ResolverSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.PluginIsDependencySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallReadySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallerSignalHandler; import org.jetbrains.annotations.NotNull; @@ -77,6 +78,7 @@ public static List getUninstallHandlers(@NotNull Terminal terminal) return createHandlersList( getCommonHandlers(terminal), new UninstallerSignalHandler(terminal), + new PluginIsDependencySignalHandler(terminal), new UninstallReadySignalHandler(terminal) ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java new file mode 100644 index 00000000..b6266c76 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java @@ -0,0 +1,63 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.plugin.Plugin; + +import java.util.List; +import java.util.stream.Collectors; + +public class PluginIsDependencySignalHandler +{ + private final Terminal terminal; + private boolean yesForAll = false; + + public PluginIsDependencySignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onPluginIsDependency(PluginIsDependencySignal signal) + { + terminal.warn(PluginUtil.getPluginString(signal.getPlugin()) + " は以下のプラグインの依存関係です。"); + terminal.writeLine(" " + signal.getDependedBy().stream() + .map(Plugin::getName) + .sorted() + .collect(Collectors.joining(" "))); + terminal.warn("このプラグインのアンインストールにより、これらのプラグインが動作しなくなる可能性があります。"); + + boolean uninstallThem = pollUninstallDeps(signal.getDependedBy()); + + signal.setForceUninstall(uninstallThem); + } + + private boolean pollUninstallDeps(List dependencies) + { + if (yesForAll) + return true; + + try + { + QuestionResult result = terminal.getInput().showYNQuestion( + "これらのプラグインもアンインストールを行いますか?", + QuestionAttribute.APPLY_FOR_ALL + ).waitAndGetResult(); + + if (result.test(QuestionAttribute.APPLY_FOR_ALL)) + yesForAll = true; + + return result.test(QuestionAttribute.YES); + } + catch (InterruptedException e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました: " + e.getMessage()); + return false; + } + } +} From 7921c611443dee0334788e04e96f2c92389e6824 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 23:01:46 +0900 Subject: [PATCH 271/745] refactor: Remove legacy code --- .../commands/CommandAutoRemove.java | 39 +- .../commands/debug/CommandInstallDebug.java | 3 +- .../commands/debug/CommandUninstallDebug.java | 3 +- .../plugin/Installer.java | 753 ------------------ 4 files changed, 25 insertions(+), 773 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 50cc8542..fe340cc3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -5,38 +5,29 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; -import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kyori.adventure.text.TextComponent; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class CommandAutoRemove extends CommandBase { - private static List removeUnusedPlugins(ArrayList removables) + private static List removeUnusedPlugins(ArrayList removables) throws IOException { - ArrayList removed = new ArrayList<>(); + TeamKunPluginManager.getPlugin().getInstallManager().runUninstall( + Terminals.ofConsole().quiet(), + new UninstallArgument(removables.toArray(new String[0])) + ); - for (String removable : removables) - { - Plugin plugin = Bukkit.getPluginManager().getPlugin(removable); - if (plugin != null) - { - Installer.unInstall(Terminals.ofConsole().quiet(), removable, true); - removed.add(removable); - } - DependencyTree.purge(removable); - } - - return removed; + return removables; } @Override @@ -63,11 +54,23 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); TeamKunPluginManager.getPlugin().getSession().unlock(); + return; } while (!removables.isEmpty()) { // のremoveUnusedPluginsで削除したプラグインによりいらない物ができた場合のためのループ - rem.addAll(removeUnusedPlugins(removables)); + try + { + rem.addAll(removeUnusedPlugins(removables)); + } + catch (IOException e) + { + sender.sendMessage(ChatColor.RED + "E: プラグインの削除に失敗しました。"); + sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); + sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); + TeamKunPluginManager.getPlugin().getSession().unlock(); + return; + } removables = DependencyTree.unusedPlugins(); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java index 429a13a8..47ae0b5b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java @@ -5,6 +5,7 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallTasks; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; @@ -31,7 +32,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { PluginInstaller installer = new PluginInstaller(DebugSignalHandler.toManager(terminal)); - InstallResult installResult = installer.execute(query); + InstallResult installResult = installer.execute(new InstallArgument(query)); if (installResult instanceof InstallFailedInstallResult) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java index 77301c9f..492bfc57 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java @@ -8,6 +8,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -34,7 +35,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { PluginUninstaller installer = new PluginUninstaller(DebugSignalHandler.toManager(terminal)); - InstallResult installResult = installer.execute(query); + InstallResult installResult = installer.execute(new UninstallArgument(query)); if (installResult instanceof InstallFailedInstallResult) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index 0b379939..b6f64ed0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -1,634 +1,20 @@ package net.kunmc.lab.teamkunpluginmanager.plugin; -import com.g00fy2.versioncompare.Version; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; -import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.HashLib; -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.jetbrains.annotations.NotNull; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.AbstractMap; -import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; @SuppressWarnings("unused") public class Installer { - - /** - * アンインストールをする - * - * @param terminal 発行者(Nullable) - * @param name 対象プラグ - * @param force 強制削除かどうか - */ - public static void unInstall(@NotNull Terminal terminal, @NotNull String name, boolean force) - { - - terminal.writeLine(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); - DependencyTree.Info info = DependencyTree.getInfo(name, false); - - //プラグインが見つからない場合はreturn - if (info == null) - { - terminal.error("プラグインが見つかりませんでした。"); - return; - } - - //プラグインを取得。 - Plugin plugin = Bukkit.getPluginManager().getPlugin(info.name); - - //アンインストール対象が存在するかチェック - if (!PluginUtil.isPluginLoaded(info.name)) - { - terminal.error("プラグインが見つかりませんでした。"); - return; - } - - //保護されているプラグインの場合は削除せずreturn - if (TeamKunPluginManager.getPlugin().getPluginConfig(). - getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name))) - { - terminal.warn("このプラグインは保護されています。\n" + - ChatColor.YELLOW + " 保護されているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - terminal.error("システムが保護されました。"); - return; - } - - //他のプラグインの依存関係になっている場合はreturn - // 強制アンインストールである場合は無視 - if (!info.rdepends.isEmpty() && !force) - { - terminal.warn("このプラグインは以下のプラグインの依存関係です。"); - terminal.writeLine(ChatColor.BLUE + info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.joining(" "))); - terminal.writeLine(ChatColor.YELLOW + " 依存関係になっているプラグインを削除すると、サーバの動作に支障を来す可能性がございます。"); - terminal.error("システムが保護されました。"); - return; - } - - terminal.writeLine(ChatColor.LIGHT_PURPLE + "プラグインを削除中..."); - - //プラグインをアンロード - PluginLoader.getInstance().unloadPlugin(plugin); - - //非同期実行 - Runner.runLaterAsync(() -> { - //プラグインのファイルを取得 - File file = PluginUtil.getFile(plugin); - //ファイルが有った場合は削除 - if (file != null) - file.delete(); - - //依存関係ツリーをワイプする - DependencyTree.wipePlugin(plugin); - terminal.writeLine(ChatColor.RED + "- " + plugin.getName() + ":" + plugin.getDescription().getVersion()); - - // エラーが有っる場合は表示 - String statusError = Messages.getErrorMessage(); - if (!statusError.isEmpty()) - terminal.writeLine(statusError); - - // 削除できるプラグイン(使われない依存関係等)があれば通知 - String autoRemovable = Messages.getUnInstallableMessage(); - - if (!autoRemovable.isEmpty()) - terminal.writeLine(autoRemovable); - terminal.writeLine(Messages.getStatusMessage(0, 1, 0)); - terminal.success(plugin.getName() + ":" + plugin.getDescription().getVersion() + " を正常にアンインストールしました。"); - - }, 20L); - } - - /** - * APIからのエラーjsonを取得 - * - * @param json {@code message}項を含んだjson - * @return メッセージ - */ - private static String error(String json) - { - try - { - // gsonを用いて変換 - JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class); - if (!jsonObject.has("message")) - return ""; - return jsonObject.get("message").getAsString(); - } - catch (Exception ignored) - { - return ""; - } - } - - /** - * URlからぶちこむ! - * - * @param terminal 結果を表示する対象の人 - * @param url URL!!! - * @param ignoreInstall インストールを除外するかどうか - * @param withoutResolveDepends 依存関係解決をしない - * @param withoutRemove 削除しない - * @param withoutDownload ダウンロードしない - * @return ファイル名, プラグイン名 - */ - public static InstallResult install(@NotNull Terminal terminal, String url, boolean ignoreInstall, boolean withoutResolveDepends, boolean withoutRemove, boolean withoutDownload) - { - //jarのURL - String jarURL = url; - //追加されたプラグインとステータス。 - ArrayList added = new ArrayList<>(); - - //追加数 - int add = 0; - //削除数 - int remove = 0; - //変更数(アップデート等) - int modify = 0; - - //ダウンロードする場合はURL・クエリを直リンに変換 - if (!withoutDownload) - { - ResolveResult resolveResult = TeamKunPluginManager.getPlugin().getResolver().resolve(url); - - if (resolveResult instanceof ErrorResult) - { - ErrorResult errorResult = (ErrorResult) resolveResult; - - terminal.error(errorResult.getCause().getMessage() + " リゾルバ:" + errorResult.getSource().getName()); - - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - return new InstallResult(add, remove, modify, false); - } - else if (resolveResult instanceof MultiResult) - { - MultiResult multiResult = (MultiResult) resolveResult; - - try - { - if (terminal.isQuiet()) - { - resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); - if (resolveResult instanceof ErrorResult) - { - ErrorResult errorResult = (ErrorResult) resolveResult; - - terminal.error(errorResult.getCause().getMessage() + - " リゾルバ:" + errorResult.getSource().getName()); - - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - return new InstallResult(add, remove, modify, false); - } - else if (resolveResult instanceof SuccessResult) - jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); - else - throw new IllegalStateException("resolveResultが不正です:プラグイン作成者に報告してください。"); - } - else - { - SuccessResult result = dependAskToTerminal(terminal, multiResult); - - if (result == null) - { - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - return new InstallResult(add, remove, modify, false); - } - - jarURL = result.getDownloadUrl(); - } - } - catch (IllegalArgumentException ignored) - { - } - } - else if (resolveResult instanceof SuccessResult) - jarURL = ((SuccessResult) resolveResult).getDownloadUrl(); - } - - long downloadResult; - Path downloadPath; - - //ダウンロード - if (!withoutDownload) - { - terminal.writeLine(ChatColor.GOLD + "ファイルのダウンロード中..."); - - //ダウンロード開始時間を控えておく - long startTime = System.currentTimeMillis(); - - //ファイルをダウンロード - try - { - downloadPath = Paths.get("plugins", jarURL.substring(url.lastIndexOf("/") + 1)); - downloadResult = Requests.downloadFile( - RequestMethod.GET, - jarURL, - downloadPath - ); - } - catch (IOException e) - { - terminal.error("ファイルのダウンロードに失敗しました:" + e.getMessage()); - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - return new InstallResult(add, remove, modify, false); - } - - - terminal.writeLine(Messages.getModifyMessage(Messages.ModifyType.ADD, downloadPath.getFileName().toString())); - add++; - - terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())) - .subtract(new BigDecimal(String.valueOf(startTime))) - .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN) + "秒で取得しました。"); - } - else //ダウンロードしない - { - downloadResult = -1; - downloadPath = Paths.get(url); - } - - terminal.writeLine(ChatColor.LIGHT_PURPLE + "情報を読み込み中..."); - - //plugin.yml - PluginDescriptionFile description; - try - { - //plugin.ymlを読み取り - description = PluginUtil.loadDescription(downloadPath.toFile()); - } - catch (FileNotFoundException e) //ファイルが見つからない場合はreturn - { - terminal.error("ファイルが見つかりませんでした。"); - if (!withoutRemove) - delete(terminal, downloadPath.toFile()); - - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - - return new InstallResult(add, remove, modify, false); - } - catch (IOException | InvalidDescriptionException e) //plugin.ymlがおかしい場合はreturn - { - terminal.error("情報を読み込めませんでした。"); - if (!withoutRemove) - delete(terminal, downloadPath.toFile()); - - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - return new InstallResult(add, remove, modify, false); - } - - //保護されているプラグインの場合はインスコ・変換せずreturn - if (TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(description.getName()))) - { - terminal.error("このプラグインは保護されています。"); - add--; - if (!withoutRemove) - delete(terminal, downloadPath.toFile()); - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - return new InstallResult(add, remove, modify, false); - } - - //spigotのapiから始まる場合はファイル名が番号のため - //プラグイン名-バージョン.jar に戻す。 - if (jarURL.startsWith("https://apple.api.spiget.org")) - { - try - { - String fileName = description.getName().replace(" ", "") + - "-" + - description.getVersion() + - ".jar"; - //ファイルを移動 - //114514.jar => YJSNPIPlugin-1.0.jar - FileUtils.moveFile( - downloadPath.toFile(), - new File("plugins/" + fileName) - ); - downloadPath = Paths.get("plugins/" + fileName); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - - //依存関係ツリーを取得 - DependencyTree.Info info = DependencyTree.getInfo(description.getName(), false); - - Plugin plugin = Bukkit.getPluginManager().getPlugin(description.getName()); - //同じ名前のプラグインがあるかどうか。 - //あった場合は、バージョンを比較し高い場合はインストール - if (PluginUtil.isPluginLoaded(description.getName()) && new Version(plugin.getDescription().getVersion()).isLowerThan(description.getVersion())) - { - modify++; - add--; - terminal.writeLine(Messages.getModifyMessage( - Messages.ModifyType.MODIFY, - plugin.getName() + ":" + plugin.getDescription().getVersion() + - " => " + description.getName() + ":" + description.getVersion() - )); - - //バージョンの低いプラグインをアンインストール。 - PluginLoader.getInstance().unloadPlugin(plugin); - - Runner.runLater(() -> { - //削除する場合は削除 - if (!withoutRemove) - delete(terminal, PluginUtil.getFile(plugin)); - }, 10L); - } - else if (PluginUtil.isPluginLoaded(description.getName())) //バージョンが変わらない(もしくは低い)。 - { - add--; - terminal.warn("既に同じプラグインが存在します。"); - - //それでもインストールするかどうかを尋 - if (terminal.isPlayer()) // TODO: Remove this if statement - { - //ファイルの比較を行う - terminal.writeLine(getDiffMessage(PluginUtil.getFile(plugin), false)); - terminal.writeLine(getDiffMessage(downloadPath.toFile(), true)); - terminal.writeLine("\n"); - //ファイナルにコピーする。 - String fileName = downloadPath.getFileName().toString(); - - try - { - QuestionResult questionResult = terminal.getInput() - .showQuestion("プラグインを置換しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) - .waitAndGetResult(); - - if (questionResult.test(QuestionAttribute.CANCELLABLE)) - { - if (!withoutRemove && new File("plugins/" + fileName).exists()) - delete(terminal, new File("plugins/" + fileName)); - - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.success(description.getFullName() + " を正常にインストールしました。"); - } - else - { - unInstall(terminal.quiet(), description.getName(), true); - InstallResult ir = install(terminal, fileName, false, false, false, true); - terminal.writeLine(Messages.getStatusMessage(ir.getAdd(), ir.getRemove(), ir.getModify() + 1)); - } - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); - - } - catch (InterruptedException e) - { - e.printStackTrace(); - } - } - - //削除 - if (!withoutRemove && downloadPath.toFile().exists()) - delete(terminal, downloadPath.toFile()); - - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.success(description.getFullName() + " を正常にインストールしました。"); - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); - - } - - added.add(new InstallResult(downloadPath.getFileName().toString(), description.getName(), add, remove, modify, true)); - - //==================依存関係解決処理 ここから================== - - //forが回ったかのフラグ - boolean dependFirst = true; - //依存関係の処理に失敗したプラグイン - ArrayList failedResolve = new ArrayList<>(); - - //ダウンロード開始時間を控えておく - long startTime = System.currentTimeMillis(); - - for (String dependency : description.getDepend()) - { - //依存関係を処理しない場合はbreak - if (withoutResolveDepends) - break; - - //プラグインが既に存在する場合はcontinue - if (Bukkit.getPluginManager().isPluginEnabled(dependency)) - continue; - - //最初の依存関係解決の場合 - if (dependFirst) - { - terminal.writeLine(ChatColor.GOLD + "依存関係をダウンロード中..."); - - dependFirst = false; - } - - //クエリを直リンに変換 - ResolveResult resolveResult = TeamKunPluginManager.getPlugin().getResolver().resolve(dependency); - String dependUrl; - - if (resolveResult instanceof ErrorResult) - { - ErrorResult errorResult = (ErrorResult) resolveResult; - - terminal.error(errorResult.getCause().getMessage() + - " リゾルバ:" + errorResult.getSource().getName()); - terminal.warn(dependency + ": " + dependency.substring(5)); - failedResolve.add(dependency); - continue; - } - else if (resolveResult instanceof MultiResult) - { - MultiResult multiResult = (MultiResult) resolveResult; - - resolveResult = multiResult.getResolver().autoPickOnePlugin(multiResult); - if (resolveResult instanceof ErrorResult) - { - terminal.warn(dependency + ": " + dependency.substring(5)); - failedResolve.add(dependency); - continue; - } - else if (resolveResult instanceof SuccessResult) - dependUrl = ((SuccessResult) resolveResult).getDownloadUrl(); - else - throw new IllegalStateException("resolveResultが不正です:プラグイン作成者に報告してください。"); - } - else if (resolveResult instanceof SuccessResult) - dependUrl = ((SuccessResult) resolveResult).getDownloadUrl(); - else - throw new IllegalStateException("resolveResultが不正です:プラグイン作成者に報告してください。"); - - //依存関係のインストール - InstallResult dependResolve = Installer.install(terminal.quiet(), dependUrl, true, false, true, false); - //ファイルの名前がない場合は失敗としてマーク - if (dependResolve.getFileName().isEmpty()) - { - failedResolve.add(dependency); - continue; - } - - if (Bukkit.getPluginManager().getPlugin(dependUrl.substring(dependUrl.lastIndexOf("/"))) == null) - terminal.writeLine(ChatColor.GREEN + "+ " + dependUrl.substring(dependUrl.lastIndexOf("/") + 1)); - else - { - Plugin dependPlugin = Bukkit.getPluginManager().getPlugin(dependUrl.substring(dependUrl.lastIndexOf("/"))); - terminal.writeLine(ChatColor.GREEN + "+ " + dependPlugin.getName() + ":" + dependPlugin.getDescription().getVersion()); - } - added.add(dependResolve); - add++; - - } - - //依存関係が1つでも読まれた場合はかかった時間を表示 - if (!dependFirst) - terminal.writeLine(ChatColor.DARK_GREEN.toString() + new BigDecimal(String.valueOf(System.currentTimeMillis())).subtract(new BigDecimal(String.valueOf(startTime))).divide(new BigDecimal("1000")).setScale(2, RoundingMode.DOWN) + "秒で取得しました。"); - - //結果を表示しないモードで依存関係エラーが発生した場合はreturn - if (!terminal.isPlayer() && !failedResolve.isEmpty()) - return new InstallResult(add, remove, modify, true); - - //依存関係エラーが発生した場合は表示 - if (!failedResolve.isEmpty()) - { - terminal.writeLine(Messages.getStatusMessage(add, remove, modify)); - terminal.warn(description.getFullName() + " を正常にインストールしましたが、以下の依存関係の処理に失敗しました。"); - terminal.writeLine(ChatColor.RED + String.join(", ", failedResolve)); - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); - } - - AtomicBoolean success = new AtomicBoolean(true); - //インストールを行う場合 - if (!ignoreInstall) - { - //依存関係<=>非依存関係 を考慮し、読み込む順番を計算 - ArrayList loadOrder = PluginUtil.mathLoadOrder(added); - - //読み込み順番に沿って読み込む - for (InstallResult f : loadOrder) - { - try - { - //プラグインが既に読まれてい場合はreturn - if (PluginUtil.isPluginLoaded(description.getName())) - { - terminal.error("Bukkitのインジェクションに失敗しました。"); - - //削除する場合は削除 - if (!withoutRemove) - delete(terminal, new File("plugins/" + f.getFileName())); - - //プラグインをアンロード - PluginLoader.getInstance().unloadPlugin(plugin); - - Runner.runLaterAsync(() -> { - File file = PluginUtil.getFile(plugin); - if (!withoutRemove && file != null) - file.delete(); - }, 20L); - } - - PluginLoader.getInstance().loadPlugin(new File("plugins", f.getFileName()).toPath()); - } - catch (Exception e) //例外が発生した場合 - { - //削除する場合は削除 - if (!withoutRemove) - delete(terminal, new File("plugins/" + f.getFileName())); - e.printStackTrace(); - //失敗フラグを建てる - success.set(false); - } - } - } - - //失敗フラグが立っていた場合は表示 - if (!success.get()) - terminal.error("プラグインの読み込みに失敗しました。"); - - int finalAdd1 = add; - int finalModify1 = modify; - /*new BukkitRunnable() - { - - @Override - public void run() - {*/ - //エラーが発生した場合 - String statusError = Messages.getErrorMessage(); - if (!statusError.isEmpty()) - terminal.writeLine(statusError); - - // 削除できるプラグイン(使われない依存関係等)があれば通知 - String autoRemovable = Messages.getUnInstallableMessage(); - if (!autoRemovable.isEmpty()) - terminal.writeLine(autoRemovable); - - terminal.writeLine(Messages.getStatusMessage(finalAdd1, remove, finalModify1)); - terminal.success(description.getFullName() + " を正常にインストールしました。"); - /*} - }.runTaskLater(TeamKunPluginManager.plugin, 10L);*/ - return new InstallResult(downloadPath.getFileName().toString(), description.getName(), - add, remove, modify, true - ); - } - - private static String getDiffMessage(File f, boolean isNew) - { - String header = ChatColor.BLUE + (isNew ? "---新規インストール---": "---既存プラグイン---") + "\n"; - if (f == null) - return header + - " " + ChatColor.RED + "ファイルなし"; - - return header + - " " + pi("ファイル名", f.getName()) + - " " + pi("ファイルサイズ", f.exists() ? Utils.roundSizeUnit(f.length()): ChatColor.RED + "N/A") + - " " + pi("SHA1", f.exists() ? HashLib.genSha1(f): ChatColor.RED + "N/A"); - } - - private static String pi(String property, String value) - { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + ChatColor.DARK_GREEN + value + "\n"; - } - /** * 削除可能なデータフォルダを取得 * @@ -654,145 +40,6 @@ public static String[] getRemovableDataDirs() } } - public static void delete(Terminal terminal, File f) - { - try - { - f.delete(); - } - catch (Exception e) - { - terminal.error("ファイルの削除に失敗しました: " + f.getName()); - } - - } - - private static HashMap buildChoicesRecursive(int count, MultiResult result) - { - HashMap choices = new HashMap<>(); - - for (ResolveResult resolveResult : result.getResults()) - { - if (resolveResult instanceof SuccessResult) - { - choices.put(count + "." + resolveResult.hashCode(), (SuccessResult) resolveResult); - continue; - } - - if (resolveResult instanceof MultiResult) - choices.putAll(buildChoicesRecursive(count + 1, (MultiResult) resolveResult)); - } - - return choices; - } - - private static SuccessResult dependAskToTerminal(Terminal terminal, MultiResult result) - { - terminal.warn("複数のリソースが見つかりました。"); - - Map hashResultMap = buildChoicesRecursive(1, result); - Map hashTextMap = hashResultMap.entrySet().stream() - .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(), entry.getValue().getFileName())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - - QuestionResult questionResult; - - try - { - questionResult = - terminal.getInput().showQuestion("インストールするリリースを選択してください。", - new AttributeChoice(hashTextMap), QuestionAttribute.CANCELLABLE - ) - .waitAndGetResult(); - } - catch (InterruptedException e) - { - terminal.error("処理が中断されました。"); - return null; - } - - if (questionResult.test(QuestionAttribute.CANCELLABLE)) - { - terminal.warn("インストールがキャンセルされました。"); - return null; - } - - return hashResultMap.get(questionResult.getRawAnswer()); - } - - private static String pickPluginJar(List> jar) - { - if (jar.isEmpty()) - return null; - - String result = ""; - String tmp = ""; - for (Pair pair : jar) - { - String name = pair.getLeft(); - if (!name.endsWith(".jar") && name.endsWith(".zip")) - continue; - - if (StringUtils.containsIgnoreCase(name, "plugin-") || - StringUtils.containsIgnoreCase(name, "plugin.")) - result = pair.getRight(); - if (StringUtils.containsIgnoreCase(name, "plugin")) - tmp = pair.getRight(); - } - - if (result.isEmpty() && !tmp.isEmpty()) - result = tmp; - if (result.isEmpty()) - result = jar.get(0).getRight(); - - return result; - } - - private static List> parseMultiResult(String mlt) - { - List> result = new ArrayList<>(); - - StringBuilder name = new StringBuilder(); - StringBuilder url = new StringBuilder(); - boolean escape = false; - boolean flag = true; - - for (int i = 0; i < mlt.length(); i++) - { - char c = mlt.charAt(i); - - - if (!escape && c == '|') - { - if (!name.toString().isEmpty() && !url.toString().isEmpty()) - { - result.add(new Pair<>(name.toString(), url.toString())); - name = new StringBuilder(); - url = new StringBuilder(); - - } - flag = !flag; - continue; - } - - if (c == '\\') - { - escape = true; - continue; - } - else - escape = false; - - if (flag) - name.append(c); - else - url.append(c); - } - - return result; - } - /** * プラグインデータフォルダを削除 * From d4b7f3e0619e872acf115c3d0df10b8a3bdaff88 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 12 Sep 2022 23:36:16 +0900 Subject: [PATCH 272/745] refactor: Remove legacy code2 --- .../utils/PluginUtil.java | 72 ------------------- 1 file changed, 72 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index baa74148..fb8eddb8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.utils; -import net.kunmc.lab.teamkunpluginmanager.plugin.InstallResult; import org.bukkit.Bukkit; import org.bukkit.configuration.MemorySection; import org.bukkit.plugin.InvalidDescriptionException; @@ -17,11 +16,9 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -134,75 +131,6 @@ public static File getFile(Plugin plugin) } } - @SuppressWarnings("unchecked") - public static ArrayList mathLoadOrder(ArrayList files) - { - ArrayList order = new ArrayList<>(); //読み込む順番 - ArrayList want = (ArrayList) files.clone(); //処理待ち - files.stream().parallel() - .forEach(stringStringPair -> { - if (!want.contains(stringStringPair)) //既に処理されていた(処理待ちになかった)場合は無視 - return; - if (!stringStringPair.isSuccess()) - return; - - PluginDescriptionFile desc; //dependとか - try - { - desc = loadDescription(new File("plugins/" + stringStringPair.getFileName())); //読み込み順番を取得 - } - catch (Exception e) - { - e.printStackTrace(); - return; - } - - desc.getDepend().stream().parallel() - .forEach(pluginName -> { - if (containValue(pluginName, want)) //dependに含まれていたものがインスコ対象ににあった - { - order.add(getContainsEntry(pluginName, want)); //読み込み指示 - want.remove(getContainsEntry(pluginName, want)); //後始末 - } - }); - - desc.getSoftDepend().stream().parallel() - .forEach(pluginName -> { - if (containValue(pluginName, want)) //softDependに含まれていたものがインスコ対象ににあった - { - order.add(getContainsEntry(pluginName, want)); //読み込み指示 - want.remove(getContainsEntry(pluginName, want)); //後始末 - } - }); - }); - - want.forEach(stringStringPair -> { - if (order.contains(stringStringPair.getFileName())) - return; - order.add(stringStringPair); //後回しプラグインの指示 - }); - return order; - } - - private static InstallResult getContainsEntry(String contain, ArrayList keys) - { - for (InstallResult p : keys) - { - if (p.getPluginName().equals(contain)) - return p; - } - return null; - } - - private static boolean containValue(String contain, ArrayList keys) - { - AtomicBoolean ab = new AtomicBoolean(false); - keys.stream() - .filter(stringStringPair -> stringStringPair.getPluginName().equals(contain)) - .forEach(stringStringPair -> ab.set(true)); - return ab.get(); - } - public static PluginDescriptionFile loadDescription(File file) throws InvalidDescriptionException, IOException { // TODO: File -> Path if (!file.exists()) From 18095a02d3da82421894e7b5a5fad4fdc4a7feed Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 13 Sep 2022 16:57:40 +0900 Subject: [PATCH 273/745] fix: Plugin doesn't remove from SimplePluginManager#lookupNames --- .../plugin/installer/task/tasks/uninstall/UnInstallTask.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index d06e0436..12b30830 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -163,7 +164,7 @@ private UnInstallErrorCause uninstallOnePlugin(@NotNull Plugin plugin) this.taskState = UnInstallState.REMOVING_FROM_BUKKIT; PLUGINS.remove(plugin); - LOOKUP_NAMES.remove(plugin.getName()); + LOOKUP_NAMES.remove(plugin.getName().toLowerCase(Locale.ENGLISH)); this.taskState = UnInstallState.CLASSES_UNLOADING; @SuppressWarnings("StringOperationCanBeSimplified") // Backup Plugin name to unload classes From a0487833c4a16263430a0afd562a63bcfdbf327e Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 13 Sep 2022 16:58:04 +0900 Subject: [PATCH 274/745] refactor: Replace with lambda --- .../task/tasks/uninstall/UnInstallTask.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 12b30830..79ce9bc8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -113,15 +113,13 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan } } - Runner.runLaterAsync(() -> { - orderedUninstallTargets.forEach(plugin -> { - File pluginFile = PluginUtil.getFile(plugin); - if (pluginFile.exists()) - pluginFile.delete(); - - DependencyTree.wipePlugin(plugin); - }); - }, 20L); + Runner.runLaterAsync(() -> orderedUninstallTargets.forEach(plugin -> { + File pluginFile = PluginUtil.getFile(plugin); + if (pluginFile.exists()) + pluginFile.delete(); + + DependencyTree.wipePlugin(plugin); + }), 20L); orderedUninstallTargets.stream() .map(Plugin::getDescription) From ccd6cc414b43e609df9e03996657e84e6d76af2a Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 13 Sep 2022 17:17:04 +0900 Subject: [PATCH 275/745] refactor: Split finish signal handlers --- .../commands/signal/HeadSignalHandlers.java | 12 ++-- .../common/InstallFinishedSignalBase.java | 58 +++++++++++++++++++ .../common/InstallFinishedSignalHandler.java | 52 ----------------- .../intall/InstallFinishedSignalHandler.java | 29 ++++++++++ .../UninstallFinishedSignalHandler.java | 29 ++++++++++ 5 files changed, 123 insertions(+), 57 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index 149e263f..2d21cab4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -2,13 +2,14 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.CheckEnvSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.ModifySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DependenciesSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DownloadingSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.ResolverSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.PluginIsDependencySignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallReadySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallerSignalHandler; import org.jetbrains.annotations.NotNull; @@ -44,8 +45,7 @@ public static List getCommonHandlers(@NotNull Terminal terminal) { return createHandlersList( new CheckEnvSignalHandler(terminal), - new ModifySignalHandler(terminal), - new InstallFinishedSignalHandler(terminal) + new ModifySignalHandler(terminal) ); } @@ -63,7 +63,8 @@ public static List getInstallHandlers(@NotNull Terminal terminal) new DownloadingSignalHandler(terminal), new CheckEnvSignalHandler(terminal), new DependenciesSignalHandler(terminal), - new InstallerSignalHandler(terminal) + new InstallerSignalHandler(terminal), + new InstallFinishedSignalHandler(terminal) ); } @@ -79,7 +80,8 @@ public static List getUninstallHandlers(@NotNull Terminal terminal) getCommonHandlers(terminal), new UninstallerSignalHandler(terminal), new PluginIsDependencySignalHandler(terminal), - new UninstallReadySignalHandler(terminal) + new UninstallReadySignalHandler(terminal), + new UninstallFinishedSignalHandler(terminal) ); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java new file mode 100644 index 00000000..99bf506d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java @@ -0,0 +1,58 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; + +import lombok.AccessLevel; +import lombok.Setter; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; + +/** + * インストールが完了したときのシグナルを処理するハンドラーの基底クラスです。 + * デフォルトでは, インストール結果が表示された後に, {@link #onSuccess(InstallResult)} または {@link #onFail(InstallFailedInstallResult)} が呼び出されます. + */ +public abstract class InstallFinishedSignalBase +{ + protected final Terminal terminal; + /** + * インストール結果を表示するかどうかです。 + */ + @Setter(AccessLevel.PROTECTED) + private boolean printResult; + + public InstallFinishedSignalBase(Terminal terminal) + { + this.terminal = terminal; + this.printResult = true; + } + + @SignalHandler + public void onFinished(InstallFinishedSignal finished) + { + InstallResult installResult = finished.getResult(); + + if (printResult) + Utils.printInstallStatistics(terminal, installResult); + + if (finished.getResult() instanceof InstallFailedInstallResult) + onFail((InstallFailedInstallResult) installResult); + else + onSuccess(installResult); + } + + /** + * インストールが成功したときに呼び出されます。 + * + * @param result インストールの結果 + */ + protected abstract void onSuccess(InstallResult result); + + /** + * インストールが失敗したときに呼び出されます。 + * + * @param result インストールの結果 + */ + protected abstract void onFail(InstallFailedInstallResult result); +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java deleted file mode 100644 index e0ae6d20..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; - -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; - -public class InstallFinishedSignalHandler -{ - private final Terminal terminal; - - public InstallFinishedSignalHandler(Terminal terminal) - { - this.terminal = terminal; - } - - @SignalHandler - public void onFinished(InstallFinishedSignal finished) - { - if (finished.getResult() instanceof InstallFailedInstallResult) - onFail((InstallFailedInstallResult) finished.getResult()); - else - onSuccess(finished.getResult()); - } - - private void onSuccess(InstallResult result) - { - Utils.printInstallStatistics(terminal, result); - terminal.success("操作が正常に完了しました。"); - } - - private void onFail(InstallFailedInstallResult result) - { - Utils.printInstallStatistics(terminal, result); - - Enum progress = result.getProgress().getCurrentTask(); - Enum reason = result.getReason(); - Enum taskStatus = result.getTaskStatus(); - - - String errorMessage = "操作は %s(%s) 時に %s により失敗しました。"; - - terminal.error(String.format( - errorMessage, - progress, - taskStatus, - reason - )); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java new file mode 100644 index 00000000..ada34d31 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -0,0 +1,29 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; + +/** + * インストールが完了したときのシグナルを処理するハンドラーです。 + */ +public class InstallFinishedSignalHandler extends InstallFinishedSignalBase +{ + public InstallFinishedSignalHandler(Terminal terminal) + { + super(terminal); + } + + @Override + protected void onSuccess(InstallResult result) + { + this.terminal.success("インストールが正常に完了しました。"); + } + + @Override + protected void onFail(InstallFailedInstallResult result) + { + this.terminal.error("インストールに失敗しました。"); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java new file mode 100644 index 00000000..ffd47601 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -0,0 +1,29 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; + +/** + * アンインストールが完了したときのシグナルを処理するハンドラーです。 + */ +public class UninstallFinishedSignalHandler extends InstallFinishedSignalBase +{ + public UninstallFinishedSignalHandler(Terminal terminal) + { + super(terminal); + } + + @Override + protected void onSuccess(InstallResult result) + { + this.terminal.success("アンインストールが正常に完了しました。"); + } + + @Override + protected void onFail(InstallFailedInstallResult result) + { + this.terminal.error("アンインストールに失敗しました。"); + } +} From c6ae24c5f614062c609fa228f193c50c0dfe7b56 Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 13 Sep 2022 21:33:12 +0900 Subject: [PATCH 276/745] feat: install/uninstall result handling --- .../common/InstallFinishedSignalBase.java | 38 ++++- .../intall/InstallFinishedSignalHandler.java | 130 +++++++++++++++++- .../UninstallFinishedSignalHandler.java | 40 +++++- .../plugin/installer/AbstractInstaller.java | 6 +- .../installer/InstallFailedInstallResult.java | 6 +- .../impls/install/InstallErrorCause.java | 16 --- .../installer/task/GeneralTaskErrorCause.java | 17 --- 7 files changed, 205 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java index 99bf506d..83894c57 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java @@ -13,7 +13,7 @@ * インストールが完了したときのシグナルを処理するハンドラーの基底クラスです。 * デフォルトでは, インストール結果が表示された後に, {@link #onSuccess(InstallResult)} または {@link #onFail(InstallFailedInstallResult)} が呼び出されます. */ -public abstract class InstallFinishedSignalBase +public abstract class InstallFinishedSignalBase

    , T extends Enum> { protected final Terminal terminal; /** @@ -37,7 +37,17 @@ public void onFinished(InstallFinishedSignal finished) Utils.printInstallStatistics(terminal, installResult); if (finished.getResult() instanceof InstallFailedInstallResult) - onFail((InstallFailedInstallResult) installResult); + { + try + { + //noinspection unchecked + onFail((InstallFailedInstallResult) installResult); + } + catch (ClassCastException e) + { + onFailGeneral((InstallFailedInstallResult) installResult); + } + } else onSuccess(installResult); } @@ -54,5 +64,27 @@ public void onFinished(InstallFinishedSignal finished) * * @param result インストールの結果 */ - protected abstract void onFail(InstallFailedInstallResult result); + protected abstract void onFail(InstallFailedInstallResult result); + + /** + * インストールが失敗し, かつ型変換に失敗したときに呼び出されます。 + * + * @param result インストールの結果 + */ + protected void onFailGeneral(InstallFailedInstallResult result) + { + Enum progress = result.getProgress().getCurrentTask(); + Enum reason = result.getReason(); + Enum taskStatus = result.getTaskStatus(); + + + String errorMessage = "操作は %s(%s) 時に %s により失敗しました。"; + + terminal.error(String.format( + errorMessage, + progress, + taskStatus, + reason + )); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java index ada34d31..6784992d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -4,11 +4,19 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallTasks; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveErrorCause; +import org.jetbrains.annotations.Nullable; /** * インストールが完了したときのシグナルを処理するハンドラーです。 */ -public class InstallFinishedSignalHandler extends InstallFinishedSignalBase +public class InstallFinishedSignalHandler extends InstallFinishedSignalBase { public InstallFinishedSignalHandler(Terminal terminal) { @@ -21,9 +29,125 @@ protected void onSuccess(InstallResult result) this.terminal.success("インストールが正常に完了しました。"); } + private boolean handleGeneralErrors(@Nullable InstallErrorCause cause) + { + if (cause == null) + return false; + + switch (cause) + { + case PLUGIN_IGNORED: + this.terminal.error("指定されたプラグインが無視リストに登録されています。"); + return true; + case PLUGIN_ALREADY_INSTALLED: + this.terminal.error("指定されたプラグインは既にインストールされています。"); + return true; + } + + return false; + } + + private void handlePluginResolveError(PluginResolveErrorCause cause) + { + switch (cause) + { + case CANCELLED: + this.terminal.error("プラグイン解決がキャンセルされました。"); + break; + case GOT_ERROR_RESULT: + this.terminal.error("プラグイン解決中にエラーが発生しました。"); + break; + case ILLEGAL_INTERNAL_STATE: + this.terminal.error("プラグイン解決中に予期しない内部エラーが発生しました。"); + break; + } + } + + private void handleDownloadError(DownloadErrorCause cause) + { + switch (cause) + { + case ILLEGAL_HTTP_RESPONSE: + this.terminal.error("ダウンロード中にサーバから無効なレスポンスを受け取りました。"); + break; + case NO_BODY_IN_RESPONSE: + this.terminal.error("Body が空でした。"); + break; + case IO_EXCEPTION: + this.terminal.error("ダウンロード中に I/O エラーが発生しました。"); + break; + case UNKNOWN_ERROR: + this.terminal.error("ダウンロード中に不明なエラーが発生しました。"); + break; + } + } + + private void handleDescriptionLoadError(DescriptionLoadErrorCause cause) + { + switch (cause) + { + case NOT_A_PLUGIN: + this.terminal.error("指定されたファイルがプラグインではないか、 plugin.yml が存在しません。"); + break; + case INVALID_DESCRIPTION: + this.terminal.error("不正なプラグイン情報ファイルです。"); + break; + case IO_EXCEPTION: + this.terminal.error("プラグイン情報ファイルの読み込み中に I/O エラーが発生しました。"); + break; + } + } + + @SuppressWarnings("SwitchStatementWithoutDefaultBranch") + private void handleDependsCollectError(DependsCollectErrorCause cause) + { + if (cause == DependsCollectErrorCause.SOME_DEPENDENCIES_COLLECT_FAILED) + { + this.terminal.error("いくつかの依存関係の解決に失敗しました。"); + } + } + + private void handleInstallError(PluginsInstallErrorCause cause) + { + switch (cause) + { + case RELOCATE_FAILED: + this.terminal.error("プラグインの再配置に失敗しました。"); + break; + case INVALID_PLUGIN: + this.terminal.error("不正なプラグインファイルをインストールしようとしました。"); + break; + case INVALID_PLUGIN_DESCRIPTION: + this.terminal.error("不正なプラグイン情報ファイルが含まれています。"); + break; + case IO_EXCEPTION_OCCURRED: + this.terminal.error("プラグインのインストール中に I/O エラーが発生しました。"); + break; + case EXCEPTION_OCCURRED: + this.terminal.error("プラグインのインストール中に予期しないエラーが発生しました。"); + break; + } + } + @Override - protected void onFail(InstallFailedInstallResult result) + protected void onFail(InstallFailedInstallResult result) { - this.terminal.error("インストールに失敗しました。"); + if (this.handleGeneralErrors(result.getReason())) + return; + + Enum taskStatus = result.getTaskStatus(); + + if (taskStatus instanceof PluginResolveErrorCause) + this.handlePluginResolveError((PluginResolveErrorCause) taskStatus); + else if (taskStatus instanceof DownloadErrorCause) + this.handleDownloadError((DownloadErrorCause) taskStatus); + else if (taskStatus instanceof DescriptionLoadErrorCause) + this.handleDescriptionLoadError((DescriptionLoadErrorCause) taskStatus); + else if (taskStatus instanceof DependsCollectErrorCause) + this.handleDependsCollectError((DependsCollectErrorCause) taskStatus); + else if (taskStatus instanceof PluginsInstallErrorCause) + this.handleInstallError((PluginsInstallErrorCause) taskStatus); + else + this.terminal.error("不明なエラーが発生しました。"); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java index ffd47601..2fd4e74b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -4,11 +4,14 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallErrorCause; +import org.jetbrains.annotations.Nullable; /** * アンインストールが完了したときのシグナルを処理するハンドラーです。 */ -public class UninstallFinishedSignalHandler extends InstallFinishedSignalBase +public class UninstallFinishedSignalHandler extends InstallFinishedSignalBase { public UninstallFinishedSignalHandler(Terminal terminal) { @@ -21,9 +24,40 @@ protected void onSuccess(InstallResult result) this.terminal.success("アンインストールが正常に完了しました。"); } + private boolean handleGeneralErrors(@Nullable net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause cause) + { + if (cause == null) + return false; + + switch (cause) + { + case PLUGIN_NOT_FOUND: + this.terminal.error("指定されたプラグインが見つかりませんでした。"); + return true; + case PLUGIN_IGNORED: + this.terminal.error("指定されたプラグインが無視リストに登録されています。"); + return true; + case PLUGIN_IS_DEPENDENCY: + this.terminal.error("指定されたプラグインが他のプラグインの依存関係に含まれています。"); + return true; + } + + return false; + } + @Override - protected void onFail(InstallFailedInstallResult result) + protected void onFail(InstallFailedInstallResult result) { - this.terminal.error("アンインストールに失敗しました。"); + if (this.handleGeneralErrors(result.getReason())) + return; + + if (result.getTaskStatus() instanceof UnInstallErrorCause) + { + UnInstallErrorCause cause = (UnInstallErrorCause) result.getTaskStatus(); + if (cause == UnInstallErrorCause.SOME_UNINSTALL_FAILED) + this.terminal.error("いくつかのプラグインのアンインストールに失敗しました。"); + } + } + } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java index 39821f47..3ec8a2cd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java @@ -3,7 +3,6 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.GeneralTaskErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskChain; @@ -12,6 +11,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -65,7 +65,7 @@ protected InstallResult

    success() } public , S extends Enum> InstallFailedInstallResult error( - @NotNull T reason, + @Nullable T reason, @NotNull S taskStatus) { // TODO: Implement debug mode InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, reason, taskStatus); @@ -81,7 +81,7 @@ private InstallResult

    handleTaskError(@NotNull TaskResult result) if (result.getErrorCause() != null) return this.error(result.getErrorCause(), result.getState()); else - return this.error(GeneralTaskErrorCause.ILLEGAL_INTERNAL_STATE, result.getState()); + return this.error(null, result.getState()); } @NotNull diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java index a49d589e..4982e1b1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java @@ -15,19 +15,19 @@ public class InstallFailedInstallResult

    , T extends Enum, S extends Enum> extends InstallResult

    { - @NotNull + @Nullable private final T reason; @Nullable private final S taskStatus; - public InstallFailedInstallResult(@NotNull InstallProgress progress, @NotNull T reason, @NotNull S taskStatus) + public InstallFailedInstallResult(@NotNull InstallProgress progress, @Nullable T reason, @NotNull S taskStatus) { super(false, progress); this.reason = reason; this.taskStatus = taskStatus; } - public InstallFailedInstallResult(InstallProgress progress, @NotNull T reason) + public InstallFailedInstallResult(InstallProgress progress, @Nullable T reason) { super(false, progress); this.reason = reason; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java index 4b042e73..51a793a9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java @@ -5,16 +5,6 @@ */ public enum InstallErrorCause { - // Tasks - /** - * タスクの実行中に例外が発生しました。 - */ - TASK_EXCEPTION_OCCURRED, - /** - * タスクの実行に失敗しました。 - */ - TASK_FAILED, - // Environment errors /** * 変更しようとしているプラグインが、無視リストに登録されており、 @@ -26,10 +16,4 @@ public enum InstallErrorCause * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 */ PLUGIN_ALREADY_INSTALLED, - - // Exceptions - /** - * 例外が発生しました。 - */ - EXCEPTION_OCCURRED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java deleted file mode 100644 index 68df8eaa..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/GeneralTaskErrorCause.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; - -/** - * 一般的なエラーの原因を表します。 - */ -public enum GeneralTaskErrorCause -{ - // General internal errors - /** - * 予期しないタスクの返答があリました。 - */ - ILLEGAL_INTERNAL_STATE, - /** - * {@link java.io.IOException} が発生しました。 - */ - IO_EXCEPTION_OCCURRED, -} From 4c9148b99d7bc764cb6a5cc0745ac41f1c306a0f Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 14 Sep 2022 19:08:08 +0900 Subject: [PATCH 277/745] fix: Error with error cause casting --- .../common/InstallFinishedSignalBase.java | 35 ++----------------- .../intall/InstallFinishedSignalHandler.java | 30 ++++++++-------- .../UninstallFinishedSignalHandler.java | 10 +++--- 3 files changed, 23 insertions(+), 52 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java index 83894c57..cc01aa5a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java @@ -13,7 +13,7 @@ * インストールが完了したときのシグナルを処理するハンドラーの基底クラスです。 * デフォルトでは, インストール結果が表示された後に, {@link #onSuccess(InstallResult)} または {@link #onFail(InstallFailedInstallResult)} が呼び出されます. */ -public abstract class InstallFinishedSignalBase

    , T extends Enum> +public abstract class InstallFinishedSignalBase { protected final Terminal terminal; /** @@ -38,15 +38,7 @@ public void onFinished(InstallFinishedSignal finished) if (finished.getResult() instanceof InstallFailedInstallResult) { - try - { - //noinspection unchecked - onFail((InstallFailedInstallResult) installResult); - } - catch (ClassCastException e) - { - onFailGeneral((InstallFailedInstallResult) installResult); - } + onFail((InstallFailedInstallResult) finished.getResult()); } else onSuccess(installResult); @@ -64,27 +56,6 @@ public void onFinished(InstallFinishedSignal finished) * * @param result インストールの結果 */ - protected abstract void onFail(InstallFailedInstallResult result); + protected abstract void onFail(InstallFailedInstallResult result); - /** - * インストールが失敗し, かつ型変換に失敗したときに呼び出されます。 - * - * @param result インストールの結果 - */ - protected void onFailGeneral(InstallFailedInstallResult result) - { - Enum progress = result.getProgress().getCurrentTask(); - Enum reason = result.getReason(); - Enum taskStatus = result.getTaskStatus(); - - - String errorMessage = "操作は %s(%s) 時に %s により失敗しました。"; - - terminal.error(String.format( - errorMessage, - progress, - taskStatus, - reason - )); - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java index 6784992d..e723073a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -5,7 +5,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallTasks; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadErrorCause; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadErrorCause; @@ -16,7 +15,7 @@ /** * インストールが完了したときのシグナルを処理するハンドラーです。 */ -public class InstallFinishedSignalHandler extends InstallFinishedSignalBase +public class InstallFinishedSignalHandler extends InstallFinishedSignalBase { public InstallFinishedSignalHandler(Terminal terminal) { @@ -130,23 +129,24 @@ private void handleInstallError(PluginsInstallErrorCause cause) } @Override - protected void onFail(InstallFailedInstallResult result) + protected void onFail(InstallFailedInstallResult result) { - if (this.handleGeneralErrors(result.getReason())) + if (result.getReason() instanceof InstallErrorCause && + this.handleGeneralErrors((InstallErrorCause) result.getReason())) return; - Enum taskStatus = result.getTaskStatus(); + Enum errorCause = result.getReason(); - if (taskStatus instanceof PluginResolveErrorCause) - this.handlePluginResolveError((PluginResolveErrorCause) taskStatus); - else if (taskStatus instanceof DownloadErrorCause) - this.handleDownloadError((DownloadErrorCause) taskStatus); - else if (taskStatus instanceof DescriptionLoadErrorCause) - this.handleDescriptionLoadError((DescriptionLoadErrorCause) taskStatus); - else if (taskStatus instanceof DependsCollectErrorCause) - this.handleDependsCollectError((DependsCollectErrorCause) taskStatus); - else if (taskStatus instanceof PluginsInstallErrorCause) - this.handleInstallError((PluginsInstallErrorCause) taskStatus); + if (errorCause instanceof PluginResolveErrorCause) + this.handlePluginResolveError((PluginResolveErrorCause) errorCause); + else if (errorCause instanceof DownloadErrorCause) + this.handleDownloadError((DownloadErrorCause) errorCause); + else if (errorCause instanceof DescriptionLoadErrorCause) + this.handleDescriptionLoadError((DescriptionLoadErrorCause) errorCause); + else if (errorCause instanceof DependsCollectErrorCause) + this.handleDependsCollectError((DependsCollectErrorCause) errorCause); + else if (errorCause instanceof PluginsInstallErrorCause) + this.handleInstallError((PluginsInstallErrorCause) errorCause); else this.terminal.error("不明なエラーが発生しました。"); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java index 2fd4e74b..8192d67f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -4,14 +4,13 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallErrorCause; import org.jetbrains.annotations.Nullable; /** * アンインストールが完了したときのシグナルを処理するハンドラーです。 */ -public class UninstallFinishedSignalHandler extends InstallFinishedSignalBase +public class UninstallFinishedSignalHandler extends InstallFinishedSignalBase { public UninstallFinishedSignalHandler(Terminal terminal) { @@ -46,12 +45,13 @@ private boolean handleGeneralErrors(@Nullable net.kunmc.lab.teamkunpluginmanager } @Override - protected void onFail(InstallFailedInstallResult result) + protected void onFail(InstallFailedInstallResult result) { - if (this.handleGeneralErrors(result.getReason())) + if (result.getReason() instanceof net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause && + this.handleGeneralErrors((net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause) result.getReason())) return; - if (result.getTaskStatus() instanceof UnInstallErrorCause) + if (result.getReason() instanceof UnInstallErrorCause) { UnInstallErrorCause cause = (UnInstallErrorCause) result.getTaskStatus(); if (cause == UnInstallErrorCause.SOME_UNINSTALL_FAILED) From 2322fddbb2036d314c5e22661bdd6e10f480bd3b Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 14 Sep 2022 19:14:38 +0900 Subject: [PATCH 278/745] =?UTF-8?q?fix:=20=E4=BA=8C=E9=87=8D=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../signal/handlers/intall/InstallFinishedSignalHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java index e723073a..ccb5cceb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -50,9 +50,10 @@ private void handlePluginResolveError(PluginResolveErrorCause cause) { switch (cause) { + /* This cause is handled in PluginResolveSignalHandler case CANCELLED: this.terminal.error("プラグイン解決がキャンセルされました。"); - break; + break;*/ case GOT_ERROR_RESULT: this.terminal.error("プラグイン解決中にエラーが発生しました。"); break; From 59844c1ec237c6b7ab326dd4cda2d9cf258b283b Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 14 Sep 2022 22:32:43 +0900 Subject: [PATCH 279/745] chore(deps): v bump PeyangPaperUtils to 1.0.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2d45d2a8..9c6db818 100644 --- a/pom.xml +++ b/pom.xml @@ -159,7 +159,7 @@ com.github.TeamKUN PeyangPaperUtils - 1.0.8 + 1.0.12 compile From 8b39a41c33185ff637e84ca22247f0ad0233797a Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 14 Sep 2022 22:32:43 +0900 Subject: [PATCH 280/745] chore(deps): v bump PeyangPaperUtils to 1.0.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2d45d2a8..9c6db818 100644 --- a/pom.xml +++ b/pom.xml @@ -159,7 +159,7 @@ com.github.TeamKUN PeyangPaperUtils - 1.0.8 + 1.0.12 compile From 66791dbd7ec56cf37069000805dbc435d8b0cc7d Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 14 Sep 2022 23:29:21 +0900 Subject: [PATCH 281/745] fix: Remove verbose message --- .../commands/signal/handlers/intall/ResolverSignalHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java index fee4b2af..616573dc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java @@ -39,7 +39,6 @@ public void onPluginResolving(PluginResolvingSignal signal) public void onPluginResolveError(PluginResolveErrorSignal signal) { terminal.error(signal.getError().getCause().getMessage()); - terminal.error("プラグインの解決に失敗しました。"); } @SignalHandler From de2f32290a2df337d702301e0a5e5379e695f54f Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 15 Sep 2022 08:27:52 +0900 Subject: [PATCH 282/745] fix: Fixed invalid error cause when causes repository is found, but releases is not found. --- .../resolver/impl/GitHubURLResolver.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java index 5f4b0137..0f18bcd8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java @@ -109,26 +109,38 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri List results = new ArrayList<>(); boolean isFound = false; + boolean isNoAssets = false; for (JsonElement jsonElement : jsonArray) { ResolveResult result = buildResultSingle(owner, repositoryName, jsonElement.getAsJsonObject(), version); if (result instanceof ErrorResult) { - if (((ErrorResult) result).getCause() == ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND) + ErrorResult errorResult = (ErrorResult) result; + if (errorResult.getCause() == ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND) isFound = true; + else if (errorResult.getCause() == ErrorResult.ErrorCause.ASSET_NOT_FOUND) + isNoAssets = true; continue; } results.add(result); } - if (results.isEmpty() && isFound) - return new ErrorResult( - this, - ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("指定されたバージョンが見つかりませんでした。"), - ResolveResult.Source.GITHUB - ); + if (results.isEmpty()) + if (isFound) + return new ErrorResult( + this, + ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("指定されたバージョンが見つかりませんでした。"), + ResolveResult.Source.GITHUB + ); + else if (isNoAssets) + return new ErrorResult( + this, + ErrorResult.ErrorCause.ASSET_NOT_FOUND, + ResolveResult.Source.GITHUB + ); + return new MultiResult(this, results.toArray(new ResolveResult[0])); } From deb625701c34ffb38c73a3019e3b581f404506de Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 15 Sep 2022 08:40:48 +0900 Subject: [PATCH 283/745] fix: Invalid order of multi result resolving --- .../signal/handlers/intall/ResolverSignalHandler.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java index 616573dc..42df1022 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java @@ -13,6 +13,7 @@ import java.util.AbstractMap; import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; @@ -48,17 +49,17 @@ public void onPluginsResolve(MultiplePluginResolvedSignal signal) AtomicLong index = new AtomicLong(0); - Map keywordToResolveResult = Arrays.stream(signal.getResults().getResults()) + LinkedHashMap keywordToResolveResult = Arrays.stream(signal.getResults().getResults()) .filter(r -> r instanceof SuccessResult) .map(r -> (SuccessResult) r) - .collect(Collectors.toMap(r -> String.valueOf(index.getAndIncrement()), r -> r)); - Map keywordToTitle = keywordToResolveResult.entrySet().stream() + .collect(Collectors.toMap(r -> String.valueOf(index.getAndIncrement()), r -> r, (a, b) -> a, LinkedHashMap::new)); + LinkedHashMap keywordToTitle = keywordToResolveResult.entrySet().stream() .map(e -> new AbstractMap.SimpleEntry<>( e.getKey(), e.getValue().getFileName() + "(" + e.getValue().getVersion() + ")" ) ) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new)); keywordToTitle.put("a", "自動で最適なプラグインを選択する"); try From 1dec4d36d29c432b0ae31e073e8019ac69c5ead5 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 15 Sep 2022 09:37:34 +0900 Subject: [PATCH 284/745] fix: suppress unknown error --- .../plugin/installer/InstallManager.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index c1c068f9..a8130850 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -84,6 +84,8 @@ public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argu { e.printStackTrace(); terminal.error("不明なエラーが発生しました。"); + + runningInstall = null; } } @@ -106,10 +108,19 @@ public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument SignalHandleManager copiedHandleManager = signalHandleManager.copy(); HeadSignalHandlers.getUninstallHandlers(terminal).forEach(copiedHandleManager::register); + try + { + PluginUninstaller uninstaller = new PluginUninstaller(copiedHandleManager); + runningInstall = uninstaller.getProgress(); - PluginUninstaller uninstaller = new PluginUninstaller(copiedHandleManager); - runningInstall = uninstaller.getProgress(); + uninstaller.run(argument); + } + catch (Exception e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました。"); - uninstaller.run(argument); + runningInstall = null; + } } } From d50754d16c3cd6559f1d8aaa25f36e8f7011257b Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 15 Sep 2022 10:56:15 +0900 Subject: [PATCH 285/745] chore: v3.0.0-pre2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9c6db818..7fc94c2c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kunmc.lab TeamKunPluginManager - 3.0.0-pre1 + 3.0.0-pre2 jar TeamKunPluginManager From cdd2c83354665eac126c68164bfad7906a32600f Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 15 Sep 2022 16:04:21 +0900 Subject: [PATCH 286/745] feat: New token store --- .../TeamKunPluginManager.java | 35 ++- .../lab/teamkunpluginmanager/TokenVault.java | 50 ----- .../commands/CommandRegister.java | 15 +- .../commands/CommandUpdate.java | 2 +- .../utils/TokenStore.java | 200 ++++++++++++++++++ .../utils/http/Requests.java | 2 +- 6 files changed, 239 insertions(+), 65 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenVault.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 682e02f0..623f10ff 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -30,11 +30,13 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.Session; +import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; +import java.io.IOException; @Getter public final class TeamKunPluginManager extends JavaPlugin @@ -44,7 +46,7 @@ public final class TeamKunPluginManager extends JavaPlugin private static TeamKunPluginManager plugin; private FileConfiguration pluginConfig; - private TokenVault vault; + private TokenStore tokenStore; @Setter private boolean enableBuildTree = true; @@ -105,7 +107,7 @@ public void onDisable() public boolean isTokenAvailable() { - return !vault.getToken().isEmpty(); + return tokenStore.isTokenAvailable(); } public static void registerCommands(CommandManager commandManager) @@ -140,7 +142,25 @@ public void onEnable() setupResolver(this); - vault = new TokenVault(); + tokenStore = new TokenStore( + this.getDataFolder().toPath().resolve("token.dat"), + this.getDataFolder().toPath().resolve("token_key.dat") + ); + try + { + boolean tokenAvailable = tokenStore.loadToken(); + if (!tokenAvailable) + if (tokenStore.migrateToken()) + tokenAvailable = true; + + if (!tokenAvailable) + System.out.println("Tokenが見つかりませんでした。/kpm registerでTokenを登録してください。"); + } + catch (IOException e) + { + e.printStackTrace(); + System.out.println("トークンの読み込みに失敗しました。"); + } setupDependencyTree(this); @@ -150,14 +170,7 @@ public void onEnable() String tokenEnv = System.getenv("TOKEN"); if (tokenEnv != null && !tokenEnv.isEmpty()) - { - if (!vault.getToken().equals(tokenEnv)) - vault.vault(tokenEnv); - return; - } - - if (vault.getToken().isEmpty()) - vault.vault(""); + tokenStore.fromEnv(); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenVault.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenVault.java deleted file mode 100644 index 42384b7d..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenVault.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager; - -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -public class TokenVault -{ - - private String token; - - public TokenVault() - { - token = ""; - - if (!new File(new File("").getAbsolutePath(), "kpm.vault").exists()) - return; - try - { - token = FileUtils.readFileToString(new File(new File("").getAbsolutePath(), "kpm.vault"), StandardCharsets.UTF_8); - } - catch (IOException e) - { - System.out.println("TOKENの読み込みに失敗しました。"); - e.printStackTrace(); - } - } - - public synchronized void vault(String token) - { - this.token = token; - try - { - FileUtils.writeStringToFile(new File(new File("").getAbsolutePath(), "kpm.vault"), token, Charset.defaultCharset()); - } - catch (IOException e) - { - System.out.println("TOKENの保管に失敗しました。"); - e.printStackTrace(); - } - } - - public String getToken() - { - return token; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 071078ce..d30b7969 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -132,7 +133,7 @@ private static Runner.GeneralExceptableRunner polling(Terminal terminal, String throw new RuntimeException(); // For cancel bukkit task } - kpmInstance.getVault().vault(response.get("access_token").getAsString()); + kpmInstance.getTokenStore().storeToken(response.get("access_token").getAsString()); terminal.success("S: トークンを正常に保管しました!"); if (terminal.isPlayer()) terminal.clearNotification(); @@ -160,7 +161,17 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (args.length == 1) { - kpmInstance.getVault().vault(args[0]); + try + { + kpmInstance.getTokenStore().storeToken(args[0]); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("トークンの保存に失敗しました。"); + return; + } + terminal.success("トークンを正常に保管しました!"); kpmInstance.getSession().unlock(); return; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 65f2775b..3bd7b1a9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -68,7 +68,7 @@ private static DownloadResult doDownload(Terminal terminal) urlObj.getHost().equals("raw.githubusercontent.com"))) connection.setRequestProperty( "Authorization", - "token " + TeamKunPluginManager.getPlugin().getVault().getToken() + "token " + TeamKunPluginManager.getPlugin().getTokenStore().getToken() ); connection.setRequestProperty( "User-Agent", diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java new file mode 100644 index 00000000..18d3bfa3 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java @@ -0,0 +1,200 @@ +package net.kunmc.lab.teamkunpluginmanager.utils; + +import org.jetbrains.annotations.NotNull; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.PosixFilePermissions; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import java.util.Base64; + +public class TokenStore +{ + private static final String ALGORITHM = "AES"; + private static final String SALT = "TeamKunPluginManager>114514"; + private static final String SECONDARY_KEY = "KPM>Origin>114514"; + + private final Path tokenPath; + + private final byte[] key; + private final SecretKeySpec SECONDARY_KEY_SPEC; + + private String tokenCache; + + public TokenStore(@NotNull Path tokenPath, @NotNull Path keyPath) + { + this.tokenPath = tokenPath; + try + { + this.key = getkey(keyPath); + this.SECONDARY_KEY_SPEC = getKeySpec(SECONDARY_KEY); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + + private static SecretKeySpec getKeySpec(String key) + { + try + { + SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); + KeySpec spec = new PBEKeySpec(key.toCharArray(), SALT.getBytes(), 65536, 256); + return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES"); + } + catch (NoSuchAlgorithmException | InvalidKeySpecException e) + { + // Never happen + throw new RuntimeException(e); + } + } + + private byte[] getkey(Path keyPath) throws IOException + { + if (Files.exists(keyPath)) + return Files.readAllBytes(keyPath); + + try + { + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); + keyGenerator.init(256); + SecretKey key = keyGenerator.generateKey(); + byte[] keyBytes = key.getEncoded(); + Files.write(keyPath, keyBytes); + Files.setPosixFilePermissions(keyPath, PosixFilePermissions.fromString("rw-------")); + + return keyBytes; + } + catch (NoSuchAlgorithmException e) + { + throw new IllegalStateException("Failed to generate key.", e); + } + } + + private byte[] encryptToken(String token) + { + try + { + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, SECONDARY_KEY_SPEC); + byte[] encrypted = cipher.doFinal(token.getBytes()); + + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, ALGORITHM)); + + return cipher.doFinal(encrypted); + } + catch (Exception e) + { + throw new IllegalStateException("Failed to encrypt token.", e); + } + } + + private String decryptToken(byte[] encryptedToken) + { + try + { + Cipher cipher = Cipher.getInstance(ALGORITHM); + cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, ALGORITHM)); + + byte[] decrypted = cipher.doFinal(encryptedToken); + + cipher.init(Cipher.DECRYPT_MODE, SECONDARY_KEY_SPEC); + + return new String(cipher.doFinal(decrypted)); + } + catch (Exception e) + { + throw new IllegalStateException("Failed to decrypt token.", e); + } + } + + public void storeToken(String token) throws IOException + { + byte[] tokenBytes = encryptToken(token); + long time = System.currentTimeMillis(); + String tokenBody = Base64.getEncoder().encodeToString(tokenBytes); + String tokenString = String.format( + "%s,%s", + tokenBody, + time + ); + + Files.write(tokenPath, tokenString.getBytes()); + Files.setPosixFilePermissions(tokenPath, PosixFilePermissions.fromString("rw-------")); + + this.tokenCache = token; + } + + public boolean loadToken() throws IOException + { + if (!Files.exists(tokenPath)) + return false; + + String tokenString = new String(Files.readAllBytes(tokenPath)); + + String[] tokenParts = tokenString.split(","); + if (tokenParts.length != 2) + return false; + + String tokenBody = tokenParts[0]; + this.tokenCache = decryptToken(Base64.getDecoder().decode(tokenBody)); + + return true; + } + + public boolean migrateToken() throws IOException + { + File oldToken = new File(new File("").getAbsoluteFile(), "kpm.vault"); + + if (!oldToken.exists()) + return false; + + String token = new String(Files.readAllBytes(oldToken.toPath())); + storeToken(token); + + //noinspection ResultOfMethodCallIgnored + oldToken.delete(); + + return true; + } + + public boolean isTokenAvailable() + { + return this.tokenCache != null; + } + + public String getToken() + { + if (this.tokenCache == null) + { + try + { + loadToken(); + } + catch (IOException e) + { + System.out.println("Failed to load token."); + throw new RuntimeException(e); + } + } + return this.tokenCache; + } + + public void fromEnv() + { + String token = System.getenv("TOKEN"); + if (token != null) + this.tokenCache = token; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index fb906501..7f12508d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -67,7 +67,7 @@ private static Map setupDefaultHeaders(@NotNull String host) headers.put("Accept", "application/vnd.github.v3+json"); if (TeamKunPluginManager.getPlugin().isTokenAvailable()) - headers.put("Authorization", "Token " + TeamKunPluginManager.getPlugin().getVault().getToken()); + headers.put("Authorization", "Token " + TeamKunPluginManager.getPlugin().getTokenStore().getToken()); } else if (host.equalsIgnoreCase("file.io")) From 9d948055140ea4d4175d438a34f91e6184100017 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 15 Sep 2022 16:47:41 +0900 Subject: [PATCH 287/745] fix: Degrade register command by 6fa1ee955e354743f688c046dfd0cbd966c084e6. --- .../lab/teamkunpluginmanager/commands/CommandRegister.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index d30b7969..95c772dd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -60,7 +60,7 @@ private static void performAction(Terminal terminal) terminal.info(ChatColor.LIGHT_PURPLE + "サーバと通信しています..."); HTTPResponse response = Requests.request(RequestContext.builder() - .method(RequestMethod.GET) + .method(RequestMethod.POST) .url(OAUTH_PREPARE_URL) .build()); @@ -134,7 +134,7 @@ private static Runner.GeneralExceptableRunner polling(Terminal terminal, String } kpmInstance.getTokenStore().storeToken(response.get("access_token").getAsString()); - terminal.success("S: トークンを正常に保管しました!"); + terminal.success("トークンを正常に保管しました!"); if (terminal.isPlayer()) terminal.clearNotification(); kpmInstance.getSession().unlock(); From 1c11425da5155e44a7d470cc29ea17d8f017d6ea Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 15 Sep 2022 17:42:33 +0900 Subject: [PATCH 288/745] chore: v3.0.0-pre3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7fc94c2c..3537b293 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kunmc.lab TeamKunPluginManager - 3.0.0-pre2 + 3.0.0-pre3 jar TeamKunPluginManager From ce9dfc24be12ac49cc1669b0207a6c66a3805913 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Sep 2022 20:09:19 +0000 Subject: [PATCH 289/745] chore(deps): bump maven-shade-plugin from 3.2.4 to 3.4.0 Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.4 to 3.4.0. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.4...maven-shade-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fead6abe..fb38e403 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.4.0 package From a6b2f2a46f7b8c4421b226b12c83f8f1ac3df198 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Sep 2022 20:09:37 +0000 Subject: [PATCH 290/745] chore(deps): bump maven-compiler-plugin from 3.8.1 to 3.10.1 Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.8.1 to 3.10.1. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.8.1...maven-compiler-plugin-3.10.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fead6abe..be2e9a8d 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.10.1 ${java.version} ${java.version} From 77f4d9fa0e65d69b547f91c712067dcf7c617744 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 22:40:40 +0900 Subject: [PATCH 291/745] fix: Verbose dependency resolving --- .../task/tasks/dependencies/collector/DependsCollectTask.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index fcb187a1..1dc2cdc8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -81,7 +81,9 @@ public DependsCollectTask(@NotNull InstallProgress progress, @NotNull Sign this.postSignal(dependsSignal); - dependsSignal.getDependencies().forEach(this.status::addDependency); + dependsSignal.getDependencies().stream().parallel() + .filter(dependency -> !arguments.getAlreadyInstalledPlugins().contains(dependency)) + .forEach(this.status::addDependency); HashMap resolvedResults; // region Resolve dependencies From 45506555ae0d4e6cdac9b5b114264cdf4859ceb6 Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 20 Sep 2022 16:14:00 +0900 Subject: [PATCH 292/745] fix: Deep plugin resolving in KnownPluginResolver --- .../TeamKunPluginManager.java | 2 +- .../resolver/impl/KnownPluginsResolver.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 623f10ff..86689fdb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -89,7 +89,7 @@ private static void setupResolver(TeamKunPluginManager plugin) GitHubURLResolver githubResolver = new GitHubURLResolver(); resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); - resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); + resolver.addResolver(new KnownPluginsResolver(resolver), "local", "alias"); resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); resolver.addResolver(githubResolver, "github", "gh"); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java index 2bf2e813..9976f0d7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java @@ -1,7 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +import lombok.AllArgsConstructor; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; @@ -9,8 +11,11 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +@AllArgsConstructor public class KnownPluginsResolver implements BaseResolver { + private final PluginResolver resolver; + @Override public ResolveResult resolve(QueryContext query) { @@ -19,6 +24,18 @@ public ResolveResult resolve(QueryContext query) if (entry == null) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); + try + { + ResolveResult detailedResult = resolver.resolve(entry.getUrl()); + if (detailedResult instanceof SuccessResult) + return new SuccessResult(this, ((SuccessResult) detailedResult).getDownloadUrl(), ResolveResult.Source.LOCAL_KNOWN); + else + return detailedResult; + } + catch (StackOverflowError ignored) + { + } + return new SuccessResult(this, entry.getUrl(), null, null, ResolveResult.Source.LOCAL_KNOWN); } From 24a3600923762eb5dd71c9d17f0dc02b290ad234 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 18 Sep 2022 19:10:09 +0900 Subject: [PATCH 293/745] feat: PluginMetaManager --- .../plugin/meta/DependType.java | 22 + .../plugin/meta/DependencyNode.java | 25 + .../plugin/meta/InstallOperator.java | 24 + .../plugin/meta/PluginInstaller.java | 9 - .../plugin/meta/PluginMeta.java | 49 +- .../plugin/meta/PluginMetaManager.java | 639 ++++++++++++++++++ .../plugin/meta/PluginType.java | 7 - .../plugin/meta/ResolverType.java | 10 + 8 files changed, 760 insertions(+), 25 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependType.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependencyNode.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependType.java new file mode 100644 index 00000000..6f475813 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependType.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +/** + * 依存の種類です。 + */ +public enum DependType +{ + /** + * ハードな依存です。 + * 依存先のプラグインが存在しない場合、依存元のプラグインはロードされません。 + */ + HARD_DEPEND, + /** + * ソフトな依存です。 + * 依存先のプラグインが存在しない場合でも、依存元のプラグインはロードされます。 + */ + SOFT_DEPEND, + /** + * 自プラグインのロード前にロードする必要がある依存です。 + */ + LOAD_BEFORE +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependencyNode.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependencyNode.java new file mode 100644 index 00000000..34afb28f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/DependencyNode.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +import lombok.Value; + +/** + * 依存関係のノードです。 + */ +@Value +public class DependencyNode +{ + /** + * 依存しているプラグインの名前です。 + */ + String plugin; + + /** + * 依存先のプラグインの名前です。 + */ + String dependsOn; + + /** + * 依存の種類です。 + */ + DependType dependType; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java new file mode 100644 index 00000000..89c36335 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java @@ -0,0 +1,24 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +/** + * プラグインが誰によってインストールされたかを表します。 + */ +public enum InstallOperator +{ + /** + * サーバの管理者によって手動でインストールされたことを表します。 + */ + SERVER_ADMIN, + /** + * プラグイン依存関係リゾルバによって自動でインストールされたことを表します。 + */ + KPM_DEPENDENCY_RESOLVER, + /** + * プラグインアップデータによって自動でインストールされたことを表します。 + */ + KPM_PLUGIN_UPDATER, + /** + * その他の方法でインストールされたことを表します。 + */ + OTHER +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java deleted file mode 100644 index 522f1b1d..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginInstaller.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.meta; - -public enum PluginInstaller -{ - SERVER_ADMIN, - KPM_DEPENDENCY_RESOLVER, - OTHER_PLUGIN, - UNKNOWN -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java index 81542071..3ebee886 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java @@ -1,26 +1,57 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.meta; import lombok.Value; -import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + +/** + * プラグインのメタ情報を表します。 + */ @Value public class PluginMeta { + /** + * プラグインの名前です。 + */ @NotNull String name; + /** + * プラグインのバージョンです。 + */ @NotNull - PluginDescriptionFile pluginYML; + String version; + /** + * プラグインのインストール者です。 + */ @NotNull - PluginInstaller pluginInstaller; - @NotNull - PluginType pluginType; + InstallOperator installedBy; + /** + * プラグインが依存関係であるかどうかを表します。 + */ + boolean isDependency; + /** + * プラグインのインストールに使用した解決クエリです。 + */ + @Nullable + String resolveQuery; - long installedIn; - boolean enable; + /** + * プラグインがいつインストールされたかを表します。 + */ + long installedAt; + + /** + * 依存しているプラグインのリストです。 + */ + @NotNull + List dependedBy; + /** + * + */ + @NotNull + List dependsOn; - @Nullable - String resolver; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java new file mode 100644 index 00000000..ec71e270 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -0,0 +1,639 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class PluginMetaManager implements Listener +{ + private final HikariDataSource db; + private final List exceptedPluginModifications; + + public PluginMetaManager(@NotNull Plugin plugin, @NotNull Path databasePath) + { + this.db = createConnection(databasePath); + this.exceptedPluginModifications = new ArrayList<>(); + + this.initializeTables(); + + // Below lambda will be executed after all plugins are loaded. + // (Bukkit runs task after all plugins are loaded.) + Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, plugin), 1L); + } + + private static String normalizePluginName(@NotNull String name) + { + return name.toLowerCase().replace(" ", "_"); + } + + public void close() + { + db.close(); + } + + public List getDependOn(@NotNull String pluginName) + { + return getListFromTable("depend", normalizePluginName(pluginName), "name"); + } + + public List getSoftDependOn(@NotNull String pluginName) + { + return getListFromTable("soft_depend", normalizePluginName(pluginName), "name"); + } + + public List getLoadBefore(@NotNull String pluginName) + { + return getListFromTable("load_before", normalizePluginName(pluginName), "name"); + } + + public List getDependedBy(@NotNull String pluginName) + { + return getListFromTable("dependency_tree", normalizePluginName(pluginName), "dependency"); + } + + public List getSoftDependedBy(@NotNull String pluginName) + { + return getListFromTable("dependency_tree", normalizePluginName(pluginName), "soft_dependency"); + } + + public List getLoadBeforeBy(@NotNull String pluginName) + { + return getListFromTable("dependency_tree", normalizePluginName(pluginName), "load_before"); + } + + public List getAuthors(@NotNull String pluginName) + { + return getListFromTable("plugin_author", normalizePluginName(pluginName), "author"); + } + + public InstallOperator getInstalledBy(@NotNull String pluginName) + { + try (Connection con = db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + statement.setString(1, normalizePluginName(pluginName)); + + ResultSet resultSet = statement.executeQuery(); + + if (!resultSet.next()) + return InstallOperator.OTHER; + + return InstallOperator.valueOf(resultSet.getString("installed_by")); + } + catch (SQLException e) + { + return InstallOperator.OTHER; + } + } + + public boolean isDependency(@NotNull String pluginName) + { + try (Connection con = db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + statement.setString(1, normalizePluginName(pluginName)); + + ResultSet resultSet = statement.executeQuery(); + + if (!resultSet.next()) + return false; + + return resultSet.getBoolean("is_dependency"); + } + catch (SQLException e) + { + return false; + } + } + + public boolean setDependencyFlag(@NotNull String pluginName, boolean isDependency) + { + try (Connection con = db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("UPDATE meta SET is_dependency = ? WHERE name = ?"); + statement.setInt(1, isDependency ? 0: 1); + statement.setString(2, normalizePluginName(pluginName)); + + return statement.executeUpdate() > 0; + } + catch (SQLException e) + { + return false; + } + } + + public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) + { + PluginDescriptionFile description = plugin.getDescription(); + + String name = description.getName(); + String version = description.getVersion(); + List authors = description.getAuthors(); + String loadTiming = description.getLoad().name(); + + List dependencies = description.getDepend(); + List softDependencies = description.getSoftDepend(); + List loadBefore = description.getLoadBefore(); + + try (Connection connection = this.db.getConnection()) + { + // Lock + + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("INSERT INTO plugin(name, version, load_timing) VALUES(?, ?, ?)"); + statement.setString(1, name); + statement.setString(2, version); + statement.setString(3, loadTiming); + statement.execute(); + + statement = connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); + statement.setString(1, name); + + for (String author : authors) + { + statement.setString(2, author); + statement.execute(); + } + + statement = connection.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); + statement.setString(1, name); + + for (String dependency : dependencies) + { + statement.setString(2, dependency); + statement.execute(); + } + + statement = connection.prepareStatement("INSERT INTO soft_depend(name, soft_dependency) VALUES(?, ?)"); + statement.setString(1, name); + + for (String softDependency : softDependencies) + { + statement.setString(2, softDependency); + statement.execute(); + } + + statement = connection.prepareStatement("INSERT INTO load_before(name, load_before) VALUES(?, ?)"); + statement.setString(1, name); + + for (String load : loadBefore) + { + statement.setString(2, load); + statement.execute(); + } + + connection.createStatement().execute("COMMIT TRANSACTION"); + + if (buildDependencyTree) + this.buildDependencyTree(plugin); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void savePluginMeta(@NotNull PluginMeta meta) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("INSERT INTO meta(name, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?)"); + statement.setString(1, meta.getName()); + statement.setLong(2, meta.getInstalledAt()); + statement.setString(3, meta.getInstalledBy().name()); + statement.setString(4, meta.getResolveQuery()); + statement.setInt(5, meta.isDependency() ? 1: 0); + + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void removePluginMeta(@NotNull String pluginName) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("DELETE FROM meta WHERE name = ?"); + statement.setString(1, pluginName); + + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void removePluginData(@NotNull String pluginName, boolean thinDependencyTree) + { + + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); + statement.setString(1, normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM depend WHERE name = ?"); + statement.setString(1, normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); + statement.setString(1, normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM load_before WHERE name = ?"); + statement.setString(1, normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM plugin WHERE name = ?"); + statement.setString(1, normalizePluginName(pluginName)); + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + + if (thinDependencyTree) + this.thinDependencyTree(pluginName); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, long installedAt) + { + this.savePluginData(plugin, false); + + List dummy = Collections.emptyList(); + this.savePluginMeta( + new PluginMeta( + normalizePluginName(plugin.getName()), + plugin.getDescription().getVersion(), + operator, + false, // Dummy value + resolveQuery, + installedAt, + dummy, + dummy + ) + ); + } + + public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery) + { + onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis()); + } + + public void onUninstalled(@NotNull String pluginName) + { + this.removePluginData(pluginName, false); + this.removePluginMeta(pluginName); + } + + public void preparePluginModify(@NotNull String pluginName) + { + this.exceptedPluginModifications.add(normalizePluginName(pluginName)); + } + + public void preparePluginModify(@NotNull Plugin plugin) + { + this.exceptedPluginModifications.add(normalizePluginName(plugin.getName())); + } + + public void saveDependencyTree(@NotNull List dependencyNodes) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("INSERT INTO dependency_tree(name, parent, depend_type) VALUES(?, ?, ?)"); + + for (DependencyNode node : dependencyNodes) + { + statement.setString(1, node.getPlugin()); + statement.setString(2, node.getDependsOn()); + statement.setString(3, node.getDependType().name()); + statement.execute(); + } + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void buildDependencyTree(@NotNull Plugin plugin) + { + String pluginName = normalizePluginName(plugin.getName()); + + List dependencies = this.getDependOn(pluginName); + List softDependencies = this.getDependOn(pluginName); + List loadBefore = this.getLoadBeforeBy(pluginName); + + List dependencyNodes = + this.createDependencyNodes(pluginName, dependencies, softDependencies, loadBefore); + + this.saveDependencyTree(dependencyNodes); + } + + public void thinDependencyTree(@NotNull String pluginName) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("DELETE FROM dependency_tree WHERE name = ? OR parent = ?"); + statement.setString(1, pluginName); + statement.setString(2, pluginName); + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + @EventHandler + public void onPluginEnable(PluginEnableEvent event) + { + Plugin plugin = event.getPlugin(); + if (this.isNoAutoCreateMetadata(plugin)) + return; + + String pluginNameFull = PluginUtil.getPluginString(plugin); + + System.out.println("プラグインの追加が検出されました: " + pluginNameFull); + + System.out.println("プラグインのメタデータを作成してします ..."); + this.onInstalled(plugin, InstallOperator.SERVER_ADMIN, null); + + System.out.println("依存関係ツリーを構築しています ..."); + this.buildDependencyTree(plugin); + + } + + @EventHandler + public void onDisable(PluginDisableEvent event) + { + Plugin plugin = event.getPlugin(); + if (this.isNoAutoCreateMetadata(plugin)) + return; + + String normalized = normalizePluginName(plugin.getName()); + if (this.exceptedPluginModifications.contains(normalized)) + { + this.exceptedPluginModifications.remove(normalized); + return; + } + + String pluginNameFull = PluginUtil.getPluginString(plugin); + + System.out.println("プラグインの削除が検出されました: " + pluginNameFull); + + System.out.println("プラグインのメタデータを削除しています ..."); + this.onUninstalled(pluginNameFull); + + System.out.println("依存関係ツリーを構築しています ..."); + this.thinDependencyTree(pluginNameFull); + } + + private boolean isNoAutoCreateMetadata(Plugin plugin) + { + String normalized = normalizePluginName(plugin.getName()); + if (this.exceptedPluginModifications.contains(normalized)) + { + this.exceptedPluginModifications.remove(normalized); + return true; + } + + return false; + } + + private List createDependencyNodes(String pluginName, List dependencies, List softDependencies, List loadBefore) + { + List dependencyNodes = new ArrayList<>(); + List processed = new ArrayList<>(); + + for (String dependency : dependencies) + { + dependency = normalizePluginName(dependency); + dependencyNodes.add(new DependencyNode(pluginName, dependency, DependType.HARD_DEPEND)); + processed.add(dependency); + } + + for (String softDependency : softDependencies) + { + softDependency = normalizePluginName(softDependency); + + if (processed.contains(softDependency)) + continue; + + dependencyNodes.add(new DependencyNode(pluginName, softDependency, DependType.SOFT_DEPEND)); + processed.add(softDependency); + } + + for (String load : loadBefore) + { + load = normalizePluginName(load); + + if (processed.contains(load)) + continue; + + dependencyNodes.add(new DependencyNode(pluginName, load, DependType.LOAD_BEFORE)); + processed.add(load); + } + + return dependencyNodes; + } + + private void initializeTables() + { + try (Connection con = db.getConnection()) + { + Statement statement = con.createStatement(); + statement.execute("CREATE TABLE IF NOT EXISTS plugin(" + + "name TEXT NOT NULL PRIMARY KEY, " + + "version TEXT NOT NULL," + + "load_timing TEXT NOT NULL" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS plugin_author(" + + "name TEXT NOT NULL UNIQUE," + + "author TEXT NOT NULL" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS meta(" + + "name TEXT NOT NULL PRIMARY KEY, " + + "installed_at INTEGER NOT NULL," + + "installed_by TEXT NOT NULL," + + "resolve_query TEXT," + + "is_dependency INTEGER(1) NOT NULL" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS depend(" + + "name TEXT NOT NULL," + + "dependency TEXT" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS soft_depend(" + + "name TEXT NOT NULL," + + "soft_dependency TEXT" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS load_before(" + + "name TEXT NOT NULL," + + "load_before TEXT" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS dependency_tree(" + + "name TEXT NOT NULL PRIMARY KEY," + + "parent TEXT," + + "depend_type NOT NULL" + + ")" + ); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + + private HikariDataSource createConnection(@NotNull Path databasePath) + { + HikariConfig config = new HikariConfig(); + + config.setDriverClassName("org.sqlite.JDBC"); + config.setJdbcUrl("jdbc:sqlite:" + databasePath); + + config.setMaximumPoolSize(20); + config.setLeakDetectionThreshold(300000); + config.setAutoCommit(false); + + return new HikariDataSource(config); + } + + @SuppressWarnings("SqlResolve") + private List getListFromTable(String tableName, String name, String field) + { + List depends = new ArrayList<>(); + + try (Connection con = db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("SELECT * FROM " + tableName + " WHERE name = ?"); + statement.setString(1, name); + + ResultSet resultSet = statement.executeQuery(); + + while (resultSet.next()) + depends.add(resultSet.getString(field)); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + + return depends; + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java deleted file mode 100644 index 2cba1b38..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginType.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.meta; - -public enum PluginType -{ - INDEPENDENCE, - DEPENDENCY -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java new file mode 100644 index 00000000..934c0760 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +public enum ResolverType +{ + GITHUB, + BUKKIT, + SPIGOT, + LOCAL, + CUSTOM +} From e9c2a2df624d46a207a753aec9e18f453ffe1ed3 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 18 Sep 2022 19:21:34 +0900 Subject: [PATCH 294/745] refactor: Separate extended feats from PluginMetaManager to PluginMetaProvider --- .../plugin/meta/PluginMetaManager.java | 578 ++---------------- .../plugin/meta/PluginMetaProvider.java | 530 ++++++++++++++++ .../utils/PluginUtil.java | 6 + 3 files changed, 571 insertions(+), 543 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index ec71e270..6e8a6618 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.meta; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; +import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; @@ -10,445 +9,38 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.nio.file.Path; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class PluginMetaManager implements Listener { - private final HikariDataSource db; + @Getter + private final PluginMetaProvider provider; private final List exceptedPluginModifications; public PluginMetaManager(@NotNull Plugin plugin, @NotNull Path databasePath) { - this.db = createConnection(databasePath); + this.provider = new PluginMetaProvider(plugin, databasePath); this.exceptedPluginModifications = new ArrayList<>(); - this.initializeTables(); - // Below lambda will be executed after all plugins are loaded. // (Bukkit runs task after all plugins are loaded.) Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, plugin), 1L); } - private static String normalizePluginName(@NotNull String name) - { - return name.toLowerCase().replace(" ", "_"); - } - - public void close() - { - db.close(); - } - - public List getDependOn(@NotNull String pluginName) - { - return getListFromTable("depend", normalizePluginName(pluginName), "name"); - } - - public List getSoftDependOn(@NotNull String pluginName) - { - return getListFromTable("soft_depend", normalizePluginName(pluginName), "name"); - } - - public List getLoadBefore(@NotNull String pluginName) - { - return getListFromTable("load_before", normalizePluginName(pluginName), "name"); - } - - public List getDependedBy(@NotNull String pluginName) - { - return getListFromTable("dependency_tree", normalizePluginName(pluginName), "dependency"); - } - - public List getSoftDependedBy(@NotNull String pluginName) - { - return getListFromTable("dependency_tree", normalizePluginName(pluginName), "soft_dependency"); - } - - public List getLoadBeforeBy(@NotNull String pluginName) - { - return getListFromTable("dependency_tree", normalizePluginName(pluginName), "load_before"); - } - - public List getAuthors(@NotNull String pluginName) - { - return getListFromTable("plugin_author", normalizePluginName(pluginName), "author"); - } - - public InstallOperator getInstalledBy(@NotNull String pluginName) - { - try (Connection con = db.getConnection()) - { - PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); - statement.setString(1, normalizePluginName(pluginName)); - - ResultSet resultSet = statement.executeQuery(); - - if (!resultSet.next()) - return InstallOperator.OTHER; - - return InstallOperator.valueOf(resultSet.getString("installed_by")); - } - catch (SQLException e) - { - return InstallOperator.OTHER; - } - } - - public boolean isDependency(@NotNull String pluginName) - { - try (Connection con = db.getConnection()) - { - PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); - statement.setString(1, normalizePluginName(pluginName)); - - ResultSet resultSet = statement.executeQuery(); - - if (!resultSet.next()) - return false; - - return resultSet.getBoolean("is_dependency"); - } - catch (SQLException e) - { - return false; - } - } - - public boolean setDependencyFlag(@NotNull String pluginName, boolean isDependency) - { - try (Connection con = db.getConnection()) - { - PreparedStatement statement = con.prepareStatement("UPDATE meta SET is_dependency = ? WHERE name = ?"); - statement.setInt(1, isDependency ? 0: 1); - statement.setString(2, normalizePluginName(pluginName)); - - return statement.executeUpdate() > 0; - } - catch (SQLException e) - { - return false; - } - } - - public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) - { - PluginDescriptionFile description = plugin.getDescription(); - - String name = description.getName(); - String version = description.getVersion(); - List authors = description.getAuthors(); - String loadTiming = description.getLoad().name(); - - List dependencies = description.getDepend(); - List softDependencies = description.getSoftDepend(); - List loadBefore = description.getLoadBefore(); - - try (Connection connection = this.db.getConnection()) - { - // Lock - - connection.createStatement().execute("BEGIN TRANSACTION"); - - PreparedStatement statement = - connection.prepareStatement("INSERT INTO plugin(name, version, load_timing) VALUES(?, ?, ?)"); - statement.setString(1, name); - statement.setString(2, version); - statement.setString(3, loadTiming); - statement.execute(); - - statement = connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); - statement.setString(1, name); - - for (String author : authors) - { - statement.setString(2, author); - statement.execute(); - } - - statement = connection.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); - statement.setString(1, name); - - for (String dependency : dependencies) - { - statement.setString(2, dependency); - statement.execute(); - } - - statement = connection.prepareStatement("INSERT INTO soft_depend(name, soft_dependency) VALUES(?, ?)"); - statement.setString(1, name); - - for (String softDependency : softDependencies) - { - statement.setString(2, softDependency); - statement.execute(); - } - - statement = connection.prepareStatement("INSERT INTO load_before(name, load_before) VALUES(?, ?)"); - statement.setString(1, name); - - for (String load : loadBefore) - { - statement.setString(2, load); - statement.execute(); - } - - connection.createStatement().execute("COMMIT TRANSACTION"); - - if (buildDependencyTree) - this.buildDependencyTree(plugin); - } - catch (SQLException e) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); - } - throw new RuntimeException(e); - } - } - - public void savePluginMeta(@NotNull PluginMeta meta) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("BEGIN TRANSACTION"); - - PreparedStatement statement = - connection.prepareStatement("INSERT INTO meta(name, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?)"); - statement.setString(1, meta.getName()); - statement.setLong(2, meta.getInstalledAt()); - statement.setString(3, meta.getInstalledBy().name()); - statement.setString(4, meta.getResolveQuery()); - statement.setInt(5, meta.isDependency() ? 1: 0); - - statement.execute(); - - connection.createStatement().execute("COMMIT TRANSACTION"); - } - catch (SQLException e) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); - } - throw new RuntimeException(e); - } - } - - public void removePluginMeta(@NotNull String pluginName) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("BEGIN TRANSACTION"); - - PreparedStatement statement = - connection.prepareStatement("DELETE FROM meta WHERE name = ?"); - statement.setString(1, pluginName); - - statement.execute(); - - connection.createStatement().execute("COMMIT TRANSACTION"); - } - catch (SQLException e) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); - } - throw new RuntimeException(e); - } - } - - public void removePluginData(@NotNull String pluginName, boolean thinDependencyTree) - { - - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("BEGIN TRANSACTION"); - - PreparedStatement statement = - connection.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); - statement.setString(1, normalizePluginName(pluginName)); - statement.execute(); - - statement = connection.prepareStatement("DELETE FROM depend WHERE name = ?"); - statement.setString(1, normalizePluginName(pluginName)); - statement.execute(); - - statement = connection.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); - statement.setString(1, normalizePluginName(pluginName)); - statement.execute(); - - statement = connection.prepareStatement("DELETE FROM load_before WHERE name = ?"); - statement.setString(1, normalizePluginName(pluginName)); - statement.execute(); - - statement = connection.prepareStatement("DELETE FROM plugin WHERE name = ?"); - statement.setString(1, normalizePluginName(pluginName)); - statement.execute(); - - connection.createStatement().execute("COMMIT TRANSACTION"); - - if (thinDependencyTree) - this.thinDependencyTree(pluginName); - } - catch (SQLException e) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); - } - throw new RuntimeException(e); - } - } - - public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, long installedAt) - { - this.savePluginData(plugin, false); - - List dummy = Collections.emptyList(); - this.savePluginMeta( - new PluginMeta( - normalizePluginName(plugin.getName()), - plugin.getDescription().getVersion(), - operator, - false, // Dummy value - resolveQuery, - installedAt, - dummy, - dummy - ) - ); - } - - public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery) - { - onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis()); - } - - public void onUninstalled(@NotNull String pluginName) - { - this.removePluginData(pluginName, false); - this.removePluginMeta(pluginName); - } - public void preparePluginModify(@NotNull String pluginName) { - this.exceptedPluginModifications.add(normalizePluginName(pluginName)); + this.exceptedPluginModifications.add(PluginUtil.normalizePluginName(pluginName)); } public void preparePluginModify(@NotNull Plugin plugin) { - this.exceptedPluginModifications.add(normalizePluginName(plugin.getName())); - } - - public void saveDependencyTree(@NotNull List dependencyNodes) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("BEGIN TRANSACTION"); - - PreparedStatement statement = - connection.prepareStatement("INSERT INTO dependency_tree(name, parent, depend_type) VALUES(?, ?, ?)"); - - for (DependencyNode node : dependencyNodes) - { - statement.setString(1, node.getPlugin()); - statement.setString(2, node.getDependsOn()); - statement.setString(3, node.getDependType().name()); - statement.execute(); - } - - connection.createStatement().execute("COMMIT TRANSACTION"); - } - catch (SQLException e) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); - } - throw new RuntimeException(e); - } - } - - public void buildDependencyTree(@NotNull Plugin plugin) - { - String pluginName = normalizePluginName(plugin.getName()); - - List dependencies = this.getDependOn(pluginName); - List softDependencies = this.getDependOn(pluginName); - List loadBefore = this.getLoadBeforeBy(pluginName); - - List dependencyNodes = - this.createDependencyNodes(pluginName, dependencies, softDependencies, loadBefore); - - this.saveDependencyTree(dependencyNodes); - } - - public void thinDependencyTree(@NotNull String pluginName) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("BEGIN TRANSACTION"); - - PreparedStatement statement = - connection.prepareStatement("DELETE FROM dependency_tree WHERE name = ? OR parent = ?"); - statement.setString(1, pluginName); - statement.setString(2, pluginName); - statement.execute(); - - connection.createStatement().execute("COMMIT TRANSACTION"); - } - catch (SQLException e) - { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); - } - throw new RuntimeException(e); - } + this.exceptedPluginModifications.add(PluginUtil.normalizePluginName(plugin.getName())); } @EventHandler @@ -466,7 +58,7 @@ public void onPluginEnable(PluginEnableEvent event) this.onInstalled(plugin, InstallOperator.SERVER_ADMIN, null); System.out.println("依存関係ツリーを構築しています ..."); - this.buildDependencyTree(plugin); + this.provider.buildDependencyTree(plugin); } @@ -477,7 +69,7 @@ public void onDisable(PluginDisableEvent event) if (this.isNoAutoCreateMetadata(plugin)) return; - String normalized = normalizePluginName(plugin.getName()); + String normalized = PluginUtil.normalizePluginName(plugin.getName()); if (this.exceptedPluginModifications.contains(normalized)) { this.exceptedPluginModifications.remove(normalized); @@ -492,148 +84,48 @@ public void onDisable(PluginDisableEvent event) this.onUninstalled(pluginNameFull); System.out.println("依存関係ツリーを構築しています ..."); - this.thinDependencyTree(pluginNameFull); + this.provider.thinDependencyTree(pluginNameFull); } - private boolean isNoAutoCreateMetadata(Plugin plugin) - { - String normalized = normalizePluginName(plugin.getName()); - if (this.exceptedPluginModifications.contains(normalized)) - { - this.exceptedPluginModifications.remove(normalized); - return true; - } - - return false; - } - - private List createDependencyNodes(String pluginName, List dependencies, List softDependencies, List loadBefore) + public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, long installedAt) { - List dependencyNodes = new ArrayList<>(); - List processed = new ArrayList<>(); - - for (String dependency : dependencies) - { - dependency = normalizePluginName(dependency); - dependencyNodes.add(new DependencyNode(pluginName, dependency, DependType.HARD_DEPEND)); - processed.add(dependency); - } - - for (String softDependency : softDependencies) - { - softDependency = normalizePluginName(softDependency); - - if (processed.contains(softDependency)) - continue; - - dependencyNodes.add(new DependencyNode(pluginName, softDependency, DependType.SOFT_DEPEND)); - processed.add(softDependency); - } - - for (String load : loadBefore) - { - load = normalizePluginName(load); - - if (processed.contains(load)) - continue; + this.provider.savePluginData(plugin, false); - dependencyNodes.add(new DependencyNode(pluginName, load, DependType.LOAD_BEFORE)); - processed.add(load); - } - - return dependencyNodes; + List dummy = Collections.emptyList(); + this.provider.savePluginMeta( + new PluginMeta( + PluginUtil.normalizePluginName(plugin.getName()), + plugin.getDescription().getVersion(), + operator, + false, // Dummy value + resolveQuery, + installedAt, + dummy, + dummy + ) + ); } - private void initializeTables() + public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery) { - try (Connection con = db.getConnection()) - { - Statement statement = con.createStatement(); - statement.execute("CREATE TABLE IF NOT EXISTS plugin(" + - "name TEXT NOT NULL PRIMARY KEY, " + - "version TEXT NOT NULL," + - "load_timing TEXT NOT NULL" + - ")" - ); - statement.execute("CREATE TABLE IF NOT EXISTS plugin_author(" + - "name TEXT NOT NULL UNIQUE," + - "author TEXT NOT NULL" + - ")" - ); - - statement.execute("CREATE TABLE IF NOT EXISTS meta(" + - "name TEXT NOT NULL PRIMARY KEY, " + - "installed_at INTEGER NOT NULL," + - "installed_by TEXT NOT NULL," + - "resolve_query TEXT," + - "is_dependency INTEGER(1) NOT NULL" + - ")" - ); - - statement.execute("CREATE TABLE IF NOT EXISTS depend(" + - "name TEXT NOT NULL," + - "dependency TEXT" + - ")" - ); - statement.execute("CREATE TABLE IF NOT EXISTS soft_depend(" + - "name TEXT NOT NULL," + - "soft_dependency TEXT" + - ")" - ); - statement.execute("CREATE TABLE IF NOT EXISTS load_before(" + - "name TEXT NOT NULL," + - "load_before TEXT" + - ")" - ); - - statement.execute("CREATE TABLE IF NOT EXISTS dependency_tree(" + - "name TEXT NOT NULL PRIMARY KEY," + - "parent TEXT," + - "depend_type NOT NULL" + - ")" - ); - } - catch (SQLException e) - { - throw new RuntimeException(e); - } + onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis()); } - private HikariDataSource createConnection(@NotNull Path databasePath) + public void onUninstalled(@NotNull String pluginName) { - HikariConfig config = new HikariConfig(); - - config.setDriverClassName("org.sqlite.JDBC"); - config.setJdbcUrl("jdbc:sqlite:" + databasePath); - - config.setMaximumPoolSize(20); - config.setLeakDetectionThreshold(300000); - config.setAutoCommit(false); - - return new HikariDataSource(config); + this.provider.removePluginData(pluginName, false); + this.provider.removePluginMeta(pluginName); } - @SuppressWarnings("SqlResolve") - private List getListFromTable(String tableName, String name, String field) + private boolean isNoAutoCreateMetadata(Plugin plugin) { - List depends = new ArrayList<>(); - - try (Connection con = db.getConnection()) - { - PreparedStatement statement = con.prepareStatement("SELECT * FROM " + tableName + " WHERE name = ?"); - statement.setString(1, name); - - ResultSet resultSet = statement.executeQuery(); - - while (resultSet.next()) - depends.add(resultSet.getString(field)); - } - catch (SQLException e) + String normalized = PluginUtil.normalizePluginName(plugin.getName()); + if (this.exceptedPluginModifications.contains(normalized)) { - throw new RuntimeException(e); + this.exceptedPluginModifications.remove(normalized); + return true; } - return depends; + return false; } - } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java new file mode 100644 index 00000000..3b4dd9e2 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -0,0 +1,530 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +public class PluginMetaProvider implements Listener +{ + private final HikariDataSource db; + + public PluginMetaProvider(@NotNull Plugin plugin, @NotNull Path databasePath) + { + this.db = createConnection(databasePath); + + this.initializeTables(); + + // Below lambda will be executed after all plugins are loaded. + // (Bukkit runs task after all plugins are loaded.) + Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, plugin), 1L); + } + + private static List createDependencyNodes(String pluginName, List dependencies, List softDependencies, List loadBefore) + { + List dependencyNodes = new ArrayList<>(); + List processed = new ArrayList<>(); + + for (String dependency : dependencies) + { + dependency = PluginUtil.normalizePluginName(dependency); + dependencyNodes.add(new DependencyNode(pluginName, dependency, DependType.HARD_DEPEND)); + processed.add(dependency); + } + + for (String softDependency : softDependencies) + { + softDependency = PluginUtil.normalizePluginName(softDependency); + + if (processed.contains(softDependency)) + continue; + + dependencyNodes.add(new DependencyNode(pluginName, softDependency, DependType.SOFT_DEPEND)); + processed.add(softDependency); + } + + for (String load : loadBefore) + { + load = PluginUtil.normalizePluginName(load); + + if (processed.contains(load)) + continue; + + dependencyNodes.add(new DependencyNode(pluginName, load, DependType.LOAD_BEFORE)); + processed.add(load); + } + + return dependencyNodes; + } + + public void close() + { + db.close(); + } + + public List getDependOn(@NotNull String pluginName) + { + return getListFromTable("depend", PluginUtil.normalizePluginName(pluginName), "name"); + } + + public List getSoftDependOn(@NotNull String pluginName) + { + return getListFromTable("soft_depend", PluginUtil.normalizePluginName(pluginName), "name"); + } + + public List getLoadBefore(@NotNull String pluginName) + { + return getListFromTable("load_before", PluginUtil.normalizePluginName(pluginName), "name"); + } + + public List getDependedBy(@NotNull String pluginName) + { + return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "dependency"); + } + + public List getSoftDependedBy(@NotNull String pluginName) + { + return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "soft_dependency"); + } + + public List getLoadBeforeBy(@NotNull String pluginName) + { + return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "load_before"); + } + + public List getAuthors(@NotNull String pluginName) + { + return getListFromTable("plugin_author", PluginUtil.normalizePluginName(pluginName), "author"); + } + + public InstallOperator getInstalledBy(@NotNull String pluginName) + { + try (Connection con = this.db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + + ResultSet resultSet = statement.executeQuery(); + + if (!resultSet.next()) + return InstallOperator.OTHER; + + return InstallOperator.valueOf(resultSet.getString("installed_by")); + } + catch (SQLException e) + { + return InstallOperator.OTHER; + } + } + + public boolean isDependency(@NotNull String pluginName) + { + try (Connection con = this.db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + + ResultSet resultSet = statement.executeQuery(); + + if (!resultSet.next()) + return false; + + return resultSet.getBoolean("is_dependency"); + } + catch (SQLException e) + { + return false; + } + } + + public boolean setDependencyFlag(@NotNull String pluginName, boolean isDependency) + { + try (Connection con = this.db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("UPDATE meta SET is_dependency = ? WHERE name = ?"); + statement.setInt(1, isDependency ? 0: 1); + statement.setString(2, PluginUtil.normalizePluginName(pluginName)); + + return statement.executeUpdate() > 0; + } + catch (SQLException e) + { + return false; + } + } + + public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) + { + PluginDescriptionFile description = plugin.getDescription(); + + String name = description.getName(); + String version = description.getVersion(); + List authors = description.getAuthors(); + String loadTiming = description.getLoad().name(); + + List dependencies = description.getDepend(); + List softDependencies = description.getSoftDepend(); + List loadBefore = description.getLoadBefore(); + + try (Connection connection = this.db.getConnection()) + { + // Lock + + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("INSERT INTO plugin(name, version, load_timing) VALUES(?, ?, ?)"); + statement.setString(1, name); + statement.setString(2, version); + statement.setString(3, loadTiming); + statement.execute(); + + statement = connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); + statement.setString(1, name); + + for (String author : authors) + { + statement.setString(2, author); + statement.execute(); + } + + statement = connection.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); + statement.setString(1, name); + + for (String dependency : dependencies) + { + statement.setString(2, dependency); + statement.execute(); + } + + statement = connection.prepareStatement("INSERT INTO soft_depend(name, soft_dependency) VALUES(?, ?)"); + statement.setString(1, name); + + for (String softDependency : softDependencies) + { + statement.setString(2, softDependency); + statement.execute(); + } + + statement = connection.prepareStatement("INSERT INTO load_before(name, load_before) VALUES(?, ?)"); + statement.setString(1, name); + + for (String load : loadBefore) + { + statement.setString(2, load); + statement.execute(); + } + + connection.createStatement().execute("COMMIT TRANSACTION"); + + if (buildDependencyTree) + this.buildDependencyTree(plugin); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void savePluginMeta(@NotNull PluginMeta meta) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("INSERT INTO meta(name, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?)"); + statement.setString(1, meta.getName()); + statement.setLong(2, meta.getInstalledAt()); + statement.setString(3, meta.getInstalledBy().name()); + statement.setString(4, meta.getResolveQuery()); + statement.setInt(5, meta.isDependency() ? 1: 0); + + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void removePluginMeta(@NotNull String pluginName) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("DELETE FROM meta WHERE name = ?"); + statement.setString(1, pluginName); + + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void removePluginData(@NotNull String pluginName, boolean thinDependencyTree) + { + + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); + statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM depend WHERE name = ?"); + statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); + statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM load_before WHERE name = ?"); + statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM plugin WHERE name = ?"); + statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + + if (thinDependencyTree) + this.thinDependencyTree(pluginName); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void saveDependencyTree(@NotNull List dependencyNodes) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("INSERT INTO dependency_tree(name, parent, depend_type) VALUES(?, ?, ?)"); + + for (DependencyNode node : dependencyNodes) + { + statement.setString(1, node.getPlugin()); + statement.setString(2, node.getDependsOn()); + statement.setString(3, node.getDependType().name()); + statement.execute(); + } + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + public void buildDependencyTree(@NotNull Plugin plugin) + { + String pluginName = PluginUtil.normalizePluginName(plugin.getName()); + + List dependencies = this.getDependOn(pluginName); + List softDependencies = this.getDependOn(pluginName); + List loadBefore = this.getLoadBeforeBy(pluginName); + + List dependencyNodes = createDependencyNodes(pluginName, dependencies, softDependencies, loadBefore); + + this.saveDependencyTree(dependencyNodes); + } + + public void thinDependencyTree(@NotNull String pluginName) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("BEGIN TRANSACTION"); + + PreparedStatement statement = + connection.prepareStatement("DELETE FROM dependency_tree WHERE name = ? OR parent = ?"); + statement.setString(1, pluginName); + statement.setString(2, pluginName); + statement.execute(); + + connection.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); + } + } + + private void initializeTables() + { + try (Connection con = this.db.getConnection()) + { + Statement statement = con.createStatement(); + statement.execute("CREATE TABLE IF NOT EXISTS plugin(" + + "name TEXT NOT NULL PRIMARY KEY, " + + "version TEXT NOT NULL," + + "load_timing TEXT NOT NULL" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS plugin_author(" + + "name TEXT NOT NULL UNIQUE," + + "author TEXT NOT NULL" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS meta(" + + "name TEXT NOT NULL PRIMARY KEY, " + + "installed_at INTEGER NOT NULL," + + "installed_by TEXT NOT NULL," + + "resolve_query TEXT," + + "is_dependency INTEGER(1) NOT NULL" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS depend(" + + "name TEXT NOT NULL," + + "dependency TEXT" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS soft_depend(" + + "name TEXT NOT NULL," + + "soft_dependency TEXT" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS load_before(" + + "name TEXT NOT NULL," + + "load_before TEXT" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS dependency_tree(" + + "name TEXT NOT NULL PRIMARY KEY," + + "parent TEXT," + + "depend_type NOT NULL" + + ")" + ); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + + private HikariDataSource createConnection(@NotNull Path databasePath) + { + HikariConfig config = new HikariConfig(); + + config.setDriverClassName("org.sqlite.JDBC"); + config.setJdbcUrl("jdbc:sqlite:" + databasePath); + + config.setMaximumPoolSize(20); + config.setLeakDetectionThreshold(300000); + config.setAutoCommit(false); + + return new HikariDataSource(config); + } + + @SuppressWarnings("SqlResolve") + private List getListFromTable(String tableName, String name, String field) + { + List depends = new ArrayList<>(); + + try (Connection con = this.db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("SELECT * FROM " + tableName + " WHERE name = ?"); + statement.setString(1, name); + + ResultSet resultSet = statement.executeQuery(); + + while (resultSet.next()) + depends.add(resultSet.getString(field)); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + + return depends; + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index fb8eddb8..bdaebff8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -8,6 +8,7 @@ import org.bukkit.plugin.PluginLoadOrder; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.PluginClassLoader; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileNotFoundException; @@ -156,4 +157,9 @@ public static PluginDescriptionFile loadDescription(File file) throws InvalidDes return desc; } + + public static String normalizePluginName(@NotNull String name) + { + return name.toLowerCase().replace(" ", "_"); + } } From 97e131aa6dd16d6ccf2fede760dbd08783058d50 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 18 Sep 2022 19:22:30 +0900 Subject: [PATCH 295/745] refactor: Remove verbose class: ResolverType (it can be replaced with Resolver scheme) --- .../teamkunpluginmanager/plugin/meta/ResolverType.java | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java deleted file mode 100644 index 934c0760..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/ResolverType.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.meta; - -public enum ResolverType -{ - GITHUB, - BUKKIT, - SPIGOT, - LOCAL, - CUSTOM -} From e999c84e95be073fb2f6c219a0d255bc323aef5e Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 18 Sep 2022 19:39:16 +0900 Subject: [PATCH 296/745] docs: Javadoc --- .../plugin/meta/PluginMetaManager.java | 47 ++++++- .../plugin/meta/PluginMetaProvider.java | 124 +++++++++++++++++- 2 files changed, 164 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index 6e8a6618..9c460784 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -17,8 +17,14 @@ import java.util.Collections; import java.util.List; +/** + * プラグインのメタデータを管理するクラスです。 + */ public class PluginMetaManager implements Listener { + /** + * メタデータを提供するプロバイダです。 + */ @Getter private final PluginMetaProvider provider; private final List exceptedPluginModifications; @@ -33,21 +39,34 @@ public PluginMetaManager(@NotNull Plugin plugin, @NotNull Path databasePath) Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, plugin), 1L); } + /** + * プラグインの変更(変更や追加)を準備します。 + * このメソッドを呼び出した後にプラグインを変更すると, 自動的なメタデータの更新が行われません。 + * + * @param pluginName プラグインの名前 + */ public void preparePluginModify(@NotNull String pluginName) { this.exceptedPluginModifications.add(PluginUtil.normalizePluginName(pluginName)); } + /** + * プラグインの変更(変更や追加)を準備します。 + * このメソッドを呼び出した後にプラグインを変更すると, 自動的なメタデータの更新が行われません。 + * + * @param plugin プラグイン + * @see #preparePluginModify(String) + */ public void preparePluginModify(@NotNull Plugin plugin) { - this.exceptedPluginModifications.add(PluginUtil.normalizePluginName(plugin.getName())); + this.preparePluginModify(plugin.getName()); } @EventHandler public void onPluginEnable(PluginEnableEvent event) { Plugin plugin = event.getPlugin(); - if (this.isNoAutoCreateMetadata(plugin)) + if (this.checkNoAutoCreateMetadata(plugin)) return; String pluginNameFull = PluginUtil.getPluginString(plugin); @@ -66,7 +85,7 @@ public void onPluginEnable(PluginEnableEvent event) public void onDisable(PluginDisableEvent event) { Plugin plugin = event.getPlugin(); - if (this.isNoAutoCreateMetadata(plugin)) + if (this.checkNoAutoCreateMetadata(plugin)) return; String normalized = PluginUtil.normalizePluginName(plugin.getName()); @@ -87,6 +106,14 @@ public void onDisable(PluginDisableEvent event) this.provider.thinDependencyTree(pluginNameFull); } + /** + * プラグインがインストールされたときに呼び出します。 + * + * @param plugin インストールされたプラグイン + * @param operator インストールした操作者 + * @param resolveQuery インストール時に使用したプラグイン解決クエリ + * @param installedAt インストールされた時刻 + */ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, long installedAt) { this.provider.savePluginData(plugin, false); @@ -106,18 +133,30 @@ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operato ); } + /** + * プラグインがインストールされたときに呼び出します。 + * + * @param plugin インストールされたプラグイン + * @param operator インストールした操作者 + * @param resolveQuery インストール時に使用したプラグイン解決クエリ + */ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery) { onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis()); } + /** + * プラグインがアンインストールされたときに呼び出します。 + * + * @param pluginName アンインストールされたプラグインの名前 + */ public void onUninstalled(@NotNull String pluginName) { this.provider.removePluginData(pluginName, false); this.provider.removePluginMeta(pluginName); } - private boolean isNoAutoCreateMetadata(Plugin plugin) + private boolean checkNoAutoCreateMetadata(Plugin plugin) { String normalized = PluginUtil.normalizePluginName(plugin.getName()); if (this.exceptedPluginModifications.contains(normalized)) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 3b4dd9e2..ef3877db 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -19,6 +19,9 @@ import java.util.ArrayList; import java.util.List; +/** + * プラグインのメタデータを提供するクラスです。 + */ public class PluginMetaProvider implements Listener { private final HikariDataSource db; @@ -71,46 +74,99 @@ private static List createDependencyNodes(String pluginName, Lis return dependencyNodes; } + /** + * このクラスを破棄します。 + */ public void close() { db.close(); } + /** + * プラグインが依存(depend)しているプラグインのリストを取得します。 + * + * @param pluginName プラグインの名前 + * @return 依存しているプラグインのリスト + */ public List getDependOn(@NotNull String pluginName) { return getListFromTable("depend", PluginUtil.normalizePluginName(pluginName), "name"); } + /** + * プラグインが依存(soft_depend)しているプラグインのリストを取得します。 + * + * @param pluginName プラグインの名前 + * @return 依存しているプラグインのリスト + */ public List getSoftDependOn(@NotNull String pluginName) { return getListFromTable("soft_depend", PluginUtil.normalizePluginName(pluginName), "name"); } + /** + * プラグインを依存(load_before)しているプラグインのリストを取得します。 + * load_before は特殊な依存で, 依存しているプラグインを先に読み込むようにします。 + * + * @param pluginName プラグインの名前 + * @return 依存しているプラグインのリスト + */ public List getLoadBefore(@NotNull String pluginName) { return getListFromTable("load_before", PluginUtil.normalizePluginName(pluginName), "name"); } + /** + * プラグインが依存(depend)されているプラグインのリストを取得します。 + * + * @param pluginName プラグインの名前 + * @return 依存されているプラグインのリスト + */ public List getDependedBy(@NotNull String pluginName) { return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "dependency"); } + /** + * プラグインが依存(soft_depend)されているプラグインのリストを取得します。 + * + * @param pluginName プラグインの名前 + * @return 依存されているプラグインのリスト + */ public List getSoftDependedBy(@NotNull String pluginName) { return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "soft_dependency"); } + /** + * プラグインが依存(load_before)されているプラグインのリストを取得します。 + * load_before は特殊な依存で, 依存しているプラグインを先に読み込むようにします。 + * + * @param pluginName プラグインの名前 + * @return 依存されているプラグインのリスト + */ public List getLoadBeforeBy(@NotNull String pluginName) { return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "load_before"); } + /** + * プラグインの作者を取得します。 + * + * @param pluginName プラグインの名前 + * @return プラグインの作者 + */ public List getAuthors(@NotNull String pluginName) { return getListFromTable("plugin_author", PluginUtil.normalizePluginName(pluginName), "author"); } + /** + * プラグインが誰によってインストールされたかを取得します。 + * + * @param pluginName プラグインの名前 + * @return プラグインのインストール者 + */ public InstallOperator getInstalledBy(@NotNull String pluginName) { try (Connection con = this.db.getConnection()) @@ -131,6 +187,13 @@ public InstallOperator getInstalledBy(@NotNull String pluginName) } } + /** + * プラグインが依存関係かどうかを取得します。 + * 依存関係としてマークされている場合, 自動削除等の機能の対象になります。 + * + * @param pluginName プラグインの名前 + * @return 依存関係かどうか + */ public boolean isDependency(@NotNull String pluginName) { try (Connection con = this.db.getConnection()) @@ -151,22 +214,46 @@ public boolean isDependency(@NotNull String pluginName) } } - public boolean setDependencyFlag(@NotNull String pluginName, boolean isDependency) + /** + * プラグインが依存関係かどうかを設定します。 + * + * @param pluginName プラグインの名前 + * @param isDependency 依存関係かどうか + */ + public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) { try (Connection con = this.db.getConnection()) { + con.createStatement().execute("BEGIN TRANSACTION"); PreparedStatement statement = con.prepareStatement("UPDATE meta SET is_dependency = ? WHERE name = ?"); statement.setInt(1, isDependency ? 0: 1); statement.setString(2, PluginUtil.normalizePluginName(pluginName)); - return statement.executeUpdate() > 0; + statement.executeUpdate(); + + con.createStatement().execute("COMMIT TRANSACTION"); } catch (SQLException e) { - return false; + try (Connection connection = this.db.getConnection()) + { + connection.createStatement().execute("ROLLBACK TRANSACTION"); + } + catch (SQLException e1) + { + System.err.println("Failed to rollback transaction"); + throw new RuntimeException(e1); + } + throw new RuntimeException(e); } } + /** + * プラグインデータを保存します。 + * + * @param plugin プラグイン + * @param buildDependencyTree 依存関係ツリーを構築するかどうか + */ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) { PluginDescriptionFile description = plugin.getDescription(); @@ -249,6 +336,11 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) } } + /** + * プラグインのメタデータを保存します。 + * + * @param meta メタデータ + */ public void savePluginMeta(@NotNull PluginMeta meta) { try (Connection connection = this.db.getConnection()) @@ -282,6 +374,11 @@ public void savePluginMeta(@NotNull PluginMeta meta) } } + /** + * プラグインのメタデータを削除します。 + * + * @param pluginName プラグインの名前 + */ public void removePluginMeta(@NotNull String pluginName) { try (Connection connection = this.db.getConnection()) @@ -311,6 +408,12 @@ public void removePluginMeta(@NotNull String pluginName) } } + /** + * プラグインのデータを削除します。 + * + * @param pluginName プラグインの名前 + * @param thinDependencyTree 依存関係ツリーを構築するかどうか + */ public void removePluginData(@NotNull String pluginName, boolean thinDependencyTree) { @@ -359,6 +462,11 @@ public void removePluginData(@NotNull String pluginName, boolean thinDependencyT } } + /** + * 依存関係ツリーを保存します。 + * + * @param dependencyNodes 依存関係ツリー + */ public void saveDependencyTree(@NotNull List dependencyNodes) { try (Connection connection = this.db.getConnection()) @@ -393,6 +501,11 @@ public void saveDependencyTree(@NotNull List dependencyNodes) } } + /** + * 依存関係ツリーを構築します。 + * + * @param plugin プラグイン + */ public void buildDependencyTree(@NotNull Plugin plugin) { String pluginName = PluginUtil.normalizePluginName(plugin.getName()); @@ -406,6 +519,11 @@ public void buildDependencyTree(@NotNull Plugin plugin) this.saveDependencyTree(dependencyNodes); } + /** + * 依存関係ツリーを間引きします。 + * + * @param pluginName プラグインの名前 + */ public void thinDependencyTree(@NotNull String pluginName) { try (Connection connection = this.db.getConnection()) From 159af05cc8aa8e92c480ee9a9e60945e2438f3fd Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 18 Sep 2022 19:42:21 +0900 Subject: [PATCH 297/745] feat: getPluginsByAuthor --- .../plugin/meta/PluginMetaProvider.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index ef3877db..55f738d2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -161,6 +161,17 @@ public List getAuthors(@NotNull String pluginName) return getListFromTable("plugin_author", PluginUtil.normalizePluginName(pluginName), "author"); } + /** + * プラグインの作者からプラグインのリストを取得します。 + * + * @param author プラグインの作者 + * @return プラグインのリスト + */ + public List getPluginsByAuthor(@NotNull String author) + { + return getListFromTable("plugin_author", author, "author", "name"); + } + /** * プラグインが誰によってインストールされたかを取得します。 * @@ -622,14 +633,20 @@ private HikariDataSource createConnection(@NotNull Path databasePath) return new HikariDataSource(config); } - @SuppressWarnings("SqlResolve") private List getListFromTable(String tableName, String name, String field) + { + return this.getListFromTable(tableName, name, "name", field); + } + + @SuppressWarnings("SqlResolve") + private List getListFromTable(String tableName, String name, String queryField, String field) { List depends = new ArrayList<>(); try (Connection con = this.db.getConnection()) { - PreparedStatement statement = con.prepareStatement("SELECT * FROM " + tableName + " WHERE name = ?"); + PreparedStatement statement = + con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + queryField + " = ?"); statement.setString(1, name); ResultSet resultSet = statement.executeQuery(); From 3190b953276f4396839603585b46ff1922b25c6f Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 18 Sep 2022 19:57:37 +0900 Subject: [PATCH 298/745] refactor: Remove normalize --- .../plugin/meta/PluginMetaManager.java | 17 +++------ .../plugin/meta/PluginMetaProvider.java | 38 ++++++++----------- .../utils/PluginUtil.java | 5 --- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index 9c460784..2e2a6787 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -47,7 +47,7 @@ public PluginMetaManager(@NotNull Plugin plugin, @NotNull Path databasePath) */ public void preparePluginModify(@NotNull String pluginName) { - this.exceptedPluginModifications.add(PluginUtil.normalizePluginName(pluginName)); + this.exceptedPluginModifications.add(pluginName); } /** @@ -88,13 +88,6 @@ public void onDisable(PluginDisableEvent event) if (this.checkNoAutoCreateMetadata(plugin)) return; - String normalized = PluginUtil.normalizePluginName(plugin.getName()); - if (this.exceptedPluginModifications.contains(normalized)) - { - this.exceptedPluginModifications.remove(normalized); - return; - } - String pluginNameFull = PluginUtil.getPluginString(plugin); System.out.println("プラグインの削除が検出されました: " + pluginNameFull); @@ -121,7 +114,7 @@ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operato List dummy = Collections.emptyList(); this.provider.savePluginMeta( new PluginMeta( - PluginUtil.normalizePluginName(plugin.getName()), + plugin.getName(), plugin.getDescription().getVersion(), operator, false, // Dummy value @@ -158,10 +151,10 @@ public void onUninstalled(@NotNull String pluginName) private boolean checkNoAutoCreateMetadata(Plugin plugin) { - String normalized = PluginUtil.normalizePluginName(plugin.getName()); - if (this.exceptedPluginModifications.contains(normalized)) + String pluginName = plugin.getName(); + if (this.exceptedPluginModifications.contains(pluginName)) { - this.exceptedPluginModifications.remove(normalized); + this.exceptedPluginModifications.remove(pluginName); return true; } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 55f738d2..0262ba7f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -3,7 +3,6 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; @@ -44,15 +43,12 @@ private static List createDependencyNodes(String pluginName, Lis for (String dependency : dependencies) { - dependency = PluginUtil.normalizePluginName(dependency); dependencyNodes.add(new DependencyNode(pluginName, dependency, DependType.HARD_DEPEND)); processed.add(dependency); } for (String softDependency : softDependencies) { - softDependency = PluginUtil.normalizePluginName(softDependency); - if (processed.contains(softDependency)) continue; @@ -62,8 +58,6 @@ private static List createDependencyNodes(String pluginName, Lis for (String load : loadBefore) { - load = PluginUtil.normalizePluginName(load); - if (processed.contains(load)) continue; @@ -90,7 +84,7 @@ public void close() */ public List getDependOn(@NotNull String pluginName) { - return getListFromTable("depend", PluginUtil.normalizePluginName(pluginName), "name"); + return getListFromTable("depend", pluginName, "name"); } /** @@ -101,7 +95,7 @@ public List getDependOn(@NotNull String pluginName) */ public List getSoftDependOn(@NotNull String pluginName) { - return getListFromTable("soft_depend", PluginUtil.normalizePluginName(pluginName), "name"); + return getListFromTable("soft_depend", pluginName, "name"); } /** @@ -113,7 +107,7 @@ public List getSoftDependOn(@NotNull String pluginName) */ public List getLoadBefore(@NotNull String pluginName) { - return getListFromTable("load_before", PluginUtil.normalizePluginName(pluginName), "name"); + return getListFromTable("load_before", pluginName, "name"); } /** @@ -124,7 +118,7 @@ public List getLoadBefore(@NotNull String pluginName) */ public List getDependedBy(@NotNull String pluginName) { - return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "dependency"); + return getListFromTable("dependency_tree", pluginName, "dependency"); } /** @@ -135,7 +129,7 @@ public List getDependedBy(@NotNull String pluginName) */ public List getSoftDependedBy(@NotNull String pluginName) { - return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "soft_dependency"); + return getListFromTable("dependency_tree", pluginName, "soft_dependency"); } /** @@ -147,7 +141,7 @@ public List getSoftDependedBy(@NotNull String pluginName) */ public List getLoadBeforeBy(@NotNull String pluginName) { - return getListFromTable("dependency_tree", PluginUtil.normalizePluginName(pluginName), "load_before"); + return getListFromTable("dependency_tree", pluginName, "load_before"); } /** @@ -158,7 +152,7 @@ public List getLoadBeforeBy(@NotNull String pluginName) */ public List getAuthors(@NotNull String pluginName) { - return getListFromTable("plugin_author", PluginUtil.normalizePluginName(pluginName), "author"); + return getListFromTable("plugin_author", pluginName, "author"); } /** @@ -183,7 +177,7 @@ public InstallOperator getInstalledBy(@NotNull String pluginName) try (Connection con = this.db.getConnection()) { PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); - statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.setString(1, pluginName); ResultSet resultSet = statement.executeQuery(); @@ -210,7 +204,7 @@ public boolean isDependency(@NotNull String pluginName) try (Connection con = this.db.getConnection()) { PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); - statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.setString(1, pluginName); ResultSet resultSet = statement.executeQuery(); @@ -238,7 +232,7 @@ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) con.createStatement().execute("BEGIN TRANSACTION"); PreparedStatement statement = con.prepareStatement("UPDATE meta SET is_dependency = ? WHERE name = ?"); statement.setInt(1, isDependency ? 0: 1); - statement.setString(2, PluginUtil.normalizePluginName(pluginName)); + statement.setString(2, pluginName); statement.executeUpdate(); @@ -434,23 +428,23 @@ public void removePluginData(@NotNull String pluginName, boolean thinDependencyT PreparedStatement statement = connection.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); - statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.setString(1, pluginName); statement.execute(); statement = connection.prepareStatement("DELETE FROM depend WHERE name = ?"); - statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.setString(1, pluginName); statement.execute(); statement = connection.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); - statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.setString(1, pluginName); statement.execute(); statement = connection.prepareStatement("DELETE FROM load_before WHERE name = ?"); - statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.setString(1, pluginName); statement.execute(); statement = connection.prepareStatement("DELETE FROM plugin WHERE name = ?"); - statement.setString(1, PluginUtil.normalizePluginName(pluginName)); + statement.setString(1, pluginName); statement.execute(); connection.createStatement().execute("COMMIT TRANSACTION"); @@ -519,7 +513,7 @@ public void saveDependencyTree(@NotNull List dependencyNodes) */ public void buildDependencyTree(@NotNull Plugin plugin) { - String pluginName = PluginUtil.normalizePluginName(plugin.getName()); + String pluginName = plugin.getName(); List dependencies = this.getDependOn(pluginName); List softDependencies = this.getDependOn(pluginName); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index bdaebff8..ba9cc7b2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -8,7 +8,6 @@ import org.bukkit.plugin.PluginLoadOrder; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.PluginClassLoader; -import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileNotFoundException; @@ -158,8 +157,4 @@ public static PluginDescriptionFile loadDescription(File file) throws InvalidDes return desc; } - public static String normalizePluginName(@NotNull String name) - { - return name.toLowerCase().replace(" ", "_"); - } } From de450c50591db0b2ec1469f155395c4ef5852cb8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 18 Sep 2022 20:09:15 +0900 Subject: [PATCH 299/745] fix: Wrong transaction management --- .../plugin/meta/PluginMetaProvider.java | 231 +++++++++++------- 1 file changed, 146 insertions(+), 85 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 0262ba7f..f48759e1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -21,6 +21,7 @@ /** * プラグインのメタデータを提供するクラスです。 */ +@SuppressWarnings("unused") public class PluginMetaProvider implements Listener { private final HikariDataSource db; @@ -240,14 +241,48 @@ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) } catch (SQLException e) { - try (Connection connection = this.db.getConnection()) + throw new RuntimeException(e); + } + } + + public void updateResolveQuery(@NotNull String pluginName, @NotNull String query) + { + Connection con = null; + try + { + con = this.db.getConnection(); + con.createStatement().execute("BEGIN TRANSACTION"); + // Check if the plugin exists + PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + statement.setString(1, pluginName); + + if (!statement.executeQuery().next()) { - connection.createStatement().execute("ROLLBACK TRANSACTION"); + con.createStatement().execute("ROLLBACK TRANSACTION"); + throw new IllegalArgumentException("Plugin does not exist"); } - catch (SQLException e1) + + statement = con.prepareStatement("UPDATE meta SET resolve_query = ? WHERE name = ?"); + statement.setString(1, query); + statement.setString(2, pluginName); + + statement.executeUpdate(); + + con.createStatement().execute("COMMIT TRANSACTION"); + } + catch (SQLException e) + { + if (con != null) { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); + try + { + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } } throw new RuntimeException(e); } @@ -272,20 +307,18 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) List softDependencies = description.getSoftDepend(); List loadBefore = description.getLoadBefore(); - try (Connection connection = this.db.getConnection()) + Connection con = null; + try { - // Lock - - connection.createStatement().execute("BEGIN TRANSACTION"); - + con = this.db.getConnection(); PreparedStatement statement = - connection.prepareStatement("INSERT INTO plugin(name, version, load_timing) VALUES(?, ?, ?)"); + con.prepareStatement("INSERT INTO plugin(name, version, load_timing) VALUES(?, ?, ?)"); statement.setString(1, name); statement.setString(2, version); statement.setString(3, loadTiming); statement.execute(); - statement = connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); + statement = con.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); statement.setString(1, name); for (String author : authors) @@ -294,7 +327,7 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) statement.execute(); } - statement = connection.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); + statement = con.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); statement.setString(1, name); for (String dependency : dependencies) @@ -303,7 +336,7 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) statement.execute(); } - statement = connection.prepareStatement("INSERT INTO soft_depend(name, soft_dependency) VALUES(?, ?)"); + statement = con.prepareStatement("INSERT INTO soft_depend(name, soft_dependency) VALUES(?, ?)"); statement.setString(1, name); for (String softDependency : softDependencies) @@ -312,7 +345,7 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) statement.execute(); } - statement = connection.prepareStatement("INSERT INTO load_before(name, load_before) VALUES(?, ?)"); + statement = con.prepareStatement("INSERT INTO load_before(name, load_before) VALUES(?, ?)"); statement.setString(1, name); for (String load : loadBefore) @@ -321,21 +354,24 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) statement.execute(); } - connection.createStatement().execute("COMMIT TRANSACTION"); + con.commit(); if (buildDependencyTree) this.buildDependencyTree(plugin); } catch (SQLException e) { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) + if (con != null) { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); + try + { + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } } throw new RuntimeException(e); } @@ -348,33 +384,38 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) */ public void savePluginMeta(@NotNull PluginMeta meta) { - try (Connection connection = this.db.getConnection()) + Connection con = null; + try { - connection.createStatement().execute("BEGIN TRANSACTION"); + con = this.db.getConnection(); PreparedStatement statement = - connection.prepareStatement("INSERT INTO meta(name, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?)"); + con.prepareStatement("INSERT INTO meta(name, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?)"); statement.setString(1, meta.getName()); statement.setLong(2, meta.getInstalledAt()); statement.setString(3, meta.getInstalledBy().name()); statement.setString(4, meta.getResolveQuery()); statement.setInt(5, meta.isDependency() ? 1: 0); - statement.execute(); + statement.executeUpdate(); - connection.createStatement().execute("COMMIT TRANSACTION"); + con.commit(); } catch (SQLException e) { - try (Connection connection = this.db.getConnection()) + if (con != null) { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); + try + { + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } } + throw new RuntimeException(e); } } @@ -386,29 +427,34 @@ public void savePluginMeta(@NotNull PluginMeta meta) */ public void removePluginMeta(@NotNull String pluginName) { - try (Connection connection = this.db.getConnection()) + Connection con = null; + try { - connection.createStatement().execute("BEGIN TRANSACTION"); + con = this.db.getConnection(); PreparedStatement statement = - connection.prepareStatement("DELETE FROM meta WHERE name = ?"); + con.prepareStatement("DELETE FROM meta WHERE name = ?"); statement.setString(1, pluginName); - statement.execute(); + statement.executeUpdate(); - connection.createStatement().execute("COMMIT TRANSACTION"); + con.commit(); } catch (SQLException e) { - try (Connection connection = this.db.getConnection()) + if (con != null) { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); + try + { + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } } + throw new RuntimeException(e); } } @@ -421,48 +467,52 @@ public void removePluginMeta(@NotNull String pluginName) */ public void removePluginData(@NotNull String pluginName, boolean thinDependencyTree) { - - try (Connection connection = this.db.getConnection()) + Connection con = null; + try { - connection.createStatement().execute("BEGIN TRANSACTION"); + con = this.db.getConnection(); PreparedStatement statement = - connection.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); + con.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); statement.setString(1, pluginName); statement.execute(); - statement = connection.prepareStatement("DELETE FROM depend WHERE name = ?"); + statement = con.prepareStatement("DELETE FROM depend WHERE name = ?"); statement.setString(1, pluginName); statement.execute(); - statement = connection.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); + statement = con.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); statement.setString(1, pluginName); statement.execute(); - statement = connection.prepareStatement("DELETE FROM load_before WHERE name = ?"); + statement = con.prepareStatement("DELETE FROM load_before WHERE name = ?"); statement.setString(1, pluginName); statement.execute(); - statement = connection.prepareStatement("DELETE FROM plugin WHERE name = ?"); + statement = con.prepareStatement("DELETE FROM plugin WHERE name = ?"); statement.setString(1, pluginName); statement.execute(); - connection.createStatement().execute("COMMIT TRANSACTION"); + con.commit(); if (thinDependencyTree) this.thinDependencyTree(pluginName); } catch (SQLException e) { - try (Connection connection = this.db.getConnection()) - { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) + if (con != null) { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); + try + { + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } } + throw new RuntimeException(e); } } @@ -474,12 +524,14 @@ public void removePluginData(@NotNull String pluginName, boolean thinDependencyT */ public void saveDependencyTree(@NotNull List dependencyNodes) { - try (Connection connection = this.db.getConnection()) + Connection con = null; + + try { - connection.createStatement().execute("BEGIN TRANSACTION"); + con = this.db.getConnection(); PreparedStatement statement = - connection.prepareStatement("INSERT INTO dependency_tree(name, parent, depend_type) VALUES(?, ?, ?)"); + con.prepareStatement("INSERT INTO dependency_tree(name, parent, depend_type) VALUES(?, ?, ?)"); for (DependencyNode node : dependencyNodes) { @@ -489,19 +541,23 @@ public void saveDependencyTree(@NotNull List dependencyNodes) statement.execute(); } - connection.createStatement().execute("COMMIT TRANSACTION"); + con.commit(); } catch (SQLException e) { - try (Connection connection = this.db.getConnection()) + if (con != null) { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); + try + { + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } } + throw new RuntimeException(e); } } @@ -531,29 +587,34 @@ public void buildDependencyTree(@NotNull Plugin plugin) */ public void thinDependencyTree(@NotNull String pluginName) { - try (Connection connection = this.db.getConnection()) + Connection con = null; + try { - connection.createStatement().execute("BEGIN TRANSACTION"); + con = this.db.getConnection(); PreparedStatement statement = - connection.prepareStatement("DELETE FROM dependency_tree WHERE name = ? OR parent = ?"); + con.prepareStatement("DELETE FROM dependency_tree WHERE name = ? OR parent = ?"); statement.setString(1, pluginName); statement.setString(2, pluginName); statement.execute(); - connection.createStatement().execute("COMMIT TRANSACTION"); + con.createStatement().execute("COMMIT"); } catch (SQLException e) { - try (Connection connection = this.db.getConnection()) + if (con != null) { - connection.createStatement().execute("ROLLBACK TRANSACTION"); - } - catch (SQLException e1) - { - System.err.println("Failed to rollback transaction"); - throw new RuntimeException(e1); + try + { + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } } + throw new RuntimeException(e); } } From bd6c1b8c0df78ee9337d696ba185ba4eba0f0f1b Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 11:40:41 +0900 Subject: [PATCH 300/745] feat: Apply new meta provider --- .../TeamKunPluginManager.java | 43 +-- .../commands/CommandAutoRemove.java | 53 +-- .../commands/CommandClean.java | 8 - .../commands/CommandFix.java | 63 ---- .../commands/CommandInfo.java | 42 ++- .../commands/CommandStatus.java | 7 - .../plugin/DependencyTree.java | 303 ------------------ .../plugin/Installer.java | 4 - .../plugin/PluginEventListener.java | 45 --- .../impls/uninstall/PluginUninstaller.java | 12 +- .../task/tasks/uninstall/UnInstallTask.java | 6 +- .../plugin/meta/PluginMetaProvider.java | 203 +++++++++--- .../teamkunpluginmanager/utils/Messages.java | 10 +- 13 files changed, 225 insertions(+), 574 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 86689fdb..afc9374a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -1,14 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager; import lombok.Getter; -import lombok.Setter; import net.kunmc.lab.peyangpaperutils.lib.command.CommandManager; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; -import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.commands.CommandAutoRemove; import net.kunmc.lab.teamkunpluginmanager.commands.CommandClean; import net.kunmc.lab.teamkunpluginmanager.commands.CommandDebug; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandFix; import net.kunmc.lab.teamkunpluginmanager.commands.CommandInfo; import net.kunmc.lab.teamkunpluginmanager.commands.CommandInstall; import net.kunmc.lab.teamkunpluginmanager.commands.CommandRegister; @@ -17,11 +14,10 @@ import net.kunmc.lab.teamkunpluginmanager.commands.CommandStatus; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUninstall; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; -import net.kunmc.lab.teamkunpluginmanager.plugin.PluginEventListener; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallManager; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.BruteforceGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitResolver; @@ -37,6 +33,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Paths; @Getter public final class TeamKunPluginManager extends JavaPlugin @@ -48,38 +45,27 @@ public final class TeamKunPluginManager extends JavaPlugin private FileConfiguration pluginConfig; private TokenStore tokenStore; - @Setter - private boolean enableBuildTree = true; private Session session; private PluginResolver resolver; private CommandManager commandManager; private InstallManager installManager; + private PluginMetaManager pluginMetaManager; - private static void setupDependencyTree(TeamKunPluginManager plugin) + private void setupDependencyTree() { - DependencyTree.initialize(plugin.getPluginConfig().getString("dependPath")); - DependencyTree.initializeTable(); - KnownPlugins.initialization(plugin.getPluginConfig().getString("resolvePath")); + this.pluginMetaManager = new PluginMetaManager( + this, + Paths.get(plugin.getDataFolder().toURI()).resolve("plugins.db") + ); + + KnownPlugins.initialization(this.getPluginConfig().getString("resolvePath")); if (KnownPlugins.isLegacy()) { - plugin.getLogger().warning("プラグイン定義ファイルの形式が古いです。更新しています..."); + this.getLogger().warning("プラグイン定義ファイルの形式が古いです。更新しています..."); KnownPlugins.migration(); new CommandUpdate().onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); } - - Runner.runLater(() -> { - DependencyTree.wipeAllPlugin(); - plugin.getLogger().info("依存関係ツリーを構築中..."); - DependencyTree.crawlAllPlugins(); - plugin.getLogger().info("依存関係ツリーの構築完了"); - - //すべてのPLが読み終わった後にイベントリスナを登録 - Bukkit.getPluginManager().registerEvents( - new PluginEventListener(plugin), - TeamKunPluginManager.plugin - ); - }, 1L); } private static void setupResolver(TeamKunPluginManager plugin) @@ -99,8 +85,7 @@ private static void setupResolver(TeamKunPluginManager plugin) @Override public void onDisable() { - if (DependencyTree.dataSource != null) - DependencyTree.dataSource.close(); + pluginMetaManager.getProvider().close(); if (KnownPlugins.dataSource != null) KnownPlugins.dataSource.close(); } @@ -114,7 +99,6 @@ public static void registerCommands(CommandManager commandManager) { commandManager.registerCommand("autoremove", new CommandAutoRemove()); commandManager.registerCommand("clean", new CommandClean()); - commandManager.registerCommand("fix", new CommandFix()); commandManager.registerCommand("info", new CommandInfo()); commandManager.registerCommand("install", new CommandInstall(), "add", "i"); commandManager.registerCommand("register", new CommandRegister(), "login"); @@ -138,6 +122,7 @@ public void onEnable() installManager = new InstallManager(this); new PluginLoader(); // Initialize plugin loader + setupDependencyTree(); registerCommands(commandManager); setupResolver(this); @@ -162,8 +147,6 @@ public void onEnable() System.out.println("トークンの読み込みに失敗しました。"); } - setupDependencyTree(this); - if (!new File(DATABASE_PATH).exists()) new CommandUpdate().onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index fe340cc3..c582b426 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -2,9 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kyori.adventure.text.TextComponent; @@ -14,30 +12,17 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class CommandAutoRemove extends CommandBase { - private static List removeUnusedPlugins(ArrayList removables) throws IOException - { - TeamKunPluginManager.getPlugin().getInstallManager().runUninstall( - Terminals.ofConsole().quiet(), - new UninstallArgument(removables.toArray(new String[0])) - ); - - return removables; - } - @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { // TODO: Separate frontend and backend if (checkPermission(sender, terminal, "kpm.autoremove")) sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - ArrayList rem = new ArrayList<>(); - if (!TeamKunPluginManager.getPlugin().getSession().lock()) { sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); @@ -47,7 +32,8 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, AtomicInteger removed = new AtomicInteger(); sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); - ArrayList removables = DependencyTree.unusedPlugins(); + List removables = TeamKunPluginManager.getPlugin().getPluginMetaManager() + .getProvider().getUnusedPlugins(); if (removables.isEmpty()) { sender.sendMessage(ChatColor.RED + "E: 削除可能なプラグインはありません。"); @@ -57,28 +43,21 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } - while (!removables.isEmpty()) - { // のremoveUnusedPluginsで削除したプラグインによりいらない物ができた場合のためのループ - try - { - rem.addAll(removeUnusedPlugins(removables)); - } - catch (IOException e) - { - sender.sendMessage(ChatColor.RED + "E: プラグインの削除に失敗しました。"); - sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); - sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - return; - } - removables = DependencyTree.unusedPlugins(); + try + { + TeamKunPluginManager.getPlugin().getInstallManager().runUninstall( + terminal, + new UninstallArgument(removables.toArray(new String[0])) + ); + } + catch (IOException e) + { + sender.sendMessage(ChatColor.RED + "E: プラグインの削除に失敗しました。"); + sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); + sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); + TeamKunPluginManager.getPlugin().getSession().unlock(); + return; } - - rem.forEach(s -> { - sender.sendMessage(Messages.getModifyMessage(Messages.ModifyType.REMOVE, s)); - removed.getAndIncrement(); - }); - sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); TeamKunPluginManager.getPlugin().getSession().unlock(); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index 3bcdd23b..bedacb98 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -6,7 +6,6 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kyori.adventure.text.TextComponent; @@ -26,13 +25,6 @@ public class CommandClean extends CommandBase @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (DependencyTree.isErrors()) - { - terminal.error("重大なエラーが検出されました。/kpm fix で修正を行ってください。"); - terminal.info("エラーが検出されたため、システムが保護されました。"); - return; - } - TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); if (!kpmInstance.getSession().lock()) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java deleted file mode 100644 index 8b974096..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandFix.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; - -import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; -import net.kyori.adventure.text.TextComponent; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class CommandFix extends CommandBase -{ - @Override - public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) - { - if (!TeamKunPluginManager.getPlugin().getSession().lock()) - { - terminal.error("TeamKunPluginManagerが多重起動しています。"); - return; - } - - terminal.info("依存関係ツリーを読み込み中..."); - if (!DependencyTree.isErrors()) - { - terminal.error("エラーは検出されませんでした。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - return; - } - - terminal.info(ChatColor.GREEN + "問題を修復しています..."); - DependencyTree.fix(); - terminal.success("問題の修復に成功しました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) - { - return null; - } - - @Override - public @Nullable String getPermission() - { - return "kpm.fix"; - } - - @Override - public TextComponent getHelpOneLine() - { - return of("エラーを修復します。" + ChatColor.YELLOW + "エラーメッセージが表示された場合のみ実行してください。"); - } - - @Override - public String[] getArguments() - { - return new String[0]; - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index cb539b89..b3590609 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -3,8 +3,8 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree.Info; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependType; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMeta; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; @@ -30,10 +30,10 @@ public class CommandInfo extends CommandBase { private static Component dependTree(String name, List l) { - TextComponent content = Component.text(ChatColor.GREEN + name + ": "); + TextComponent content = Component.text(name + ": "); if (l.isEmpty()) - return content.append(Component.text(ChatColor.DARK_GREEN + "なし")).asComponent(); + return content.append(Component.text(ChatColor.GRAY + "なし")).asComponent(); for (String depend : l) { @@ -98,7 +98,9 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, terminal.info("依存関係ツリーを読み込み中..."); - Info info = DependencyTree.getInfo(args[0], false); + PluginMeta meta = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().getPluginMeta( + args[0], true + ); terminal.info("情報を読み込み中..."); JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(args[0]); @@ -111,11 +113,15 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, File file = PluginUtil.getFile(plugin); - terminal.writeLine(Messages.keyValue("名前", info.name)); + terminal.writeLine(Messages.keyValue("名前", meta.getName())); terminal.writeLine(Messages.keyValue("作成者", String.join(", ", plugin.getDescription().getAuthors()))); terminal.writeLine(Messages.keyValue("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); terminal.writeLine(Messages.keyValue("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); - terminal.writeLine(Messages.keyValueYesNo("保護", TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().anyMatch(s -> s.equalsIgnoreCase(info.name)))); + terminal.writeLine(Messages.keyValueYesNo( + "保護", + TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().parallel() + .anyMatch(s -> s.equalsIgnoreCase(meta.getName())) + )); if (plugin.getDescription().getWebsite() != null) terminal.writeLine(Messages.keyValue("ウェブサイト", ChatColor.UNDERLINE + plugin.getDescription().getWebsite())); @@ -132,8 +138,26 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, } terminal.writeLine(""); - terminal.write(dependTree("依存関係", plugin.getDescription().getDepend())); - terminal.write(dependTree("被依存関係", info.rdepends.stream().parallel().map(depend -> depend.depend).collect(Collectors.toList()))); + terminal.write(dependTree("依存関係", meta.getDependsOn().stream() + .map(dep -> { + if (dep.getDependType() == DependType.HARD_DEPEND) + return ChatColor.DARK_GREEN + dep.getDependsOn(); + else if (dep.getDependType() == DependType.SOFT_DEPEND) + return ChatColor.GREEN + dep.getDependsOn(); + else + return ChatColor.RED + dep.getDependsOn(); + }) + .collect(Collectors.toList()))); + terminal.write(dependTree("被依存関係", meta.getDependedBy().stream() + .map(dep -> { + if (dep.getDependType() == DependType.HARD_DEPEND) + return ChatColor.DARK_GREEN + dep.getPlugin(); + else if (dep.getDependType() == DependType.SOFT_DEPEND) + return ChatColor.GREEN + dep.getPlugin(); + else + return ChatColor.RED + dep.getPlugin(); + }) + .collect(Collectors.toList()))); terminal.writeLine(""); terminal.write(commandList(plugin.getDescription().getCommands())); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java index f6a515f9..3bad1b6c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java @@ -23,10 +23,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { terminal.writeLine("===現在の状態==="); - String statusError = Messages.getErrorMessage(); - - terminal.writeLine(ChatColor.GREEN + "ステータス: " + - (!statusError.isEmpty() ? ChatColor.RED + "エラー": ChatColor.DARK_GREEN + "正常")); terminal.writeLine(Messages.keyValue("プラグイン数", Bukkit.getPluginManager().getPlugins().length)); File resolve = new File( @@ -39,9 +35,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(resolve.lastModified())) )); - if (!statusError.isEmpty()) - terminal.writeLine(statusError); - String autoRemovable = Messages.getUnInstallableMessage(); if (!autoRemovable.isEmpty()) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java deleted file mode 100644 index 4c2eb548..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/DependencyTree.java +++ /dev/null @@ -1,303 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin; - -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - -import java.io.File; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class DependencyTree -{ - public static HikariDataSource dataSource; - - public static void initialize(String fileName) - { - HikariConfig config = new HikariConfig(); - config.setDriverClassName("org.sqlite.JDBC"); - - config.setJdbcUrl("jdbc:sqlite:" + new File(TeamKunPluginManager.getPlugin().getDataFolder().getPath(), fileName).getAbsolutePath()); - - config.setMaximumPoolSize(20); - config.setLeakDetectionThreshold(300000); - - dataSource = new HikariDataSource(config); - } - - public static Info getInfo(String plugin, boolean allowEmpty) - { - return getInfo(Bukkit.getPluginManager().getPlugin(plugin), allowEmpty); - } - - public static Info getInfo(Plugin plugin, boolean allowEmpty) - { - if (plugin == null) - return null; - - Info result = new Info(); - - try (Connection con = dataSource.getConnection(); - PreparedStatement pluginSQL = con.prepareStatement("SELECT * FROM PLUGIN WHERE PLUGIN=?"); - PreparedStatement dependSQL = con.prepareStatement("SELECT * FROM DEPEND WHERE PLUGIN=?"); - PreparedStatement dependBySQL = con.prepareStatement("SELECT * FROM DEPENDBY WHERE PLUGIN=?") - ) - { - pluginSQL.setString(1, plugin.getName()); - dependSQL.setString(1, plugin.getName()); - dependBySQL.setString(1, plugin.getName()); - - ResultSet pl = pluginSQL.executeQuery(); - while (pl.next()) - { - result.name = pl.getString("PLUGIN"); - result.version = pl.getString("VERSION"); - } - pl.close(); - - if (result.name == null && !allowEmpty) - return null; - - ResultSet dp = dependSQL.executeQuery(); - ArrayList dps = new ArrayList<>(); - while (dp.next()) - { - Info.Depend depend = new Info.Depend(); - depend.depend = dp.getString("DEPEND"); - dps.add(depend); - } - result.depends = dps; - dp.close(); - - ResultSet rdp = dependBySQL.executeQuery(); - ArrayList rdps = new ArrayList<>(); - while (rdp.next()) - { - Info.Depend depend = new Info.Depend(); - depend.depend = rdp.getString("DEPENDBY"); - rdps.add(depend); - } - result.rdepends = rdps; - rdp.close(); - - return result; - - } - catch (Exception e) - { - e.printStackTrace(); - } - return null; - } - - public static void initializeTable() - { - try (Connection con = dataSource.getConnection(); - Statement stmt = con.createStatement()) - { - stmt.execute("CREATE TABLE IF NOT EXISTS PLUGIN(" + - "PLUGIN TEXT UNIQUE," + - "VERSION TEXT" + - ")"); - stmt.execute("CREATE TABLE IF NOT EXISTS DEPEND(" + - "PLUGIN TEXT," + - "DEPEND TEXT UNIQUE" + - ")"); - stmt.execute("CREATE TABLE IF NOT EXISTS DEPENDBY(" + - "PLUGIN TEXT UNIQUE," + - "DEPENDBY TEXT" + - ")"); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public static void crawlAllPlugins() - { - Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() - .forEach(DependencyTree::crawlPlugin); - } - - public static void crawlPlugin(String name) - { - crawlPlugin(Bukkit.getPluginManager().getPlugin(name)); - } - - public static void wipeAllPlugin() - { - try (Connection con = dataSource.getConnection(); - Statement stmt = con.createStatement()) - { - stmt.execute("DELETE FROM PLUGIN"); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public static void wipePlugin(String name) - { - wipePlugin(Bukkit.getPluginManager().getPlugin(name)); - } - - public static void wipePlugin(Plugin plugin) - { - if (plugin == null) - return; - try (Connection con = dataSource.getConnection(); - PreparedStatement p = con.prepareStatement("DELETE FROM PLUGIN WHERE PLUGIN=?") - ) - { - p.setString(1, plugin.getName()); - p.execute(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public static void purge(String name) - { - try (Connection con = dataSource.getConnection(); - PreparedStatement dp = con.prepareStatement("DELETE FROM DEPEND WHERE PLUGIN=?"); - PreparedStatement rdp = con.prepareStatement("DELETE FROM DEPENDBY WHERE PLUGIN=?")) - { - dp.setString(1, name); - rdp.setString(1, name); - dp.execute(); - rdp.execute(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public static void crawlPlugin(Plugin plugin) - { - if (plugin == null) - return; - try (Connection con = dataSource.getConnection(); - PreparedStatement pluginSQL = con.prepareStatement("INSERT OR REPLACE INTO PLUGIN(PLUGIN, VERSION) VALUES (?,?)"); - PreparedStatement dependSQL = con.prepareStatement("INSERT OR REPLACE INTO DEPEND(PLUGIN, DEPEND) VALUES (?,?)"); - PreparedStatement dependBySQL = con.prepareStatement("INSERT OR REPLACE INTO DEPENDBY(PLUGIN, DEPENDBY) VALUES (?,?)") - ) - { - pluginSQL.setString(1, plugin.getName()); - dependSQL.setString(1, plugin.getName()); - dependBySQL.setString(2, plugin.getName()); - - pluginSQL.setString(2, plugin.getDescription().getVersion()); - pluginSQL.execute(); - - plugin.getDescription().getDepend() - .forEach(depend -> { - try - { - dependSQL.setString(2, depend); - dependSQL.execute(); - - dependBySQL.setString(1, depend); - dependBySQL.execute(); - } - catch (SQLException throwable) - { - throwable.printStackTrace(); - } - }); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public static ArrayList unusedPlugins() - { - ArrayList result = new ArrayList<>(); - try (Connection con = dataSource.getConnection(); - Statement pluginSQL = con.createStatement()) - { - ResultSet set = pluginSQL.executeQuery("SELECT * FROM DEPENDBY"); - while (set.next()) - { - String name = set.getString("PLUGIN"); //Depend - String dependBy = set.getString("DEPENDBY"); //Dependしてるプラグ - - Info info = getInfo(dependBy, false); - - if (info == null) - result.add(name); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - return result; - } - - public static boolean isErrors() - { - if (checkError()) - DependencyTree.fix(); - return checkError(); - } - - private static boolean checkError() - { - ArrayList plugin = Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel().map(Plugin::getName).collect(Collectors.toCollection(ArrayList::new)); - - try (Connection con = dataSource.getConnection(); - Statement pluginSQL = con.createStatement()) - { - ResultSet set = pluginSQL.executeQuery("SELECT * FROM PLUGIN"); - while (set.next()) - { - String name = set.getString("PLUGIN"); - if (!plugin.contains(name)) - return true; - plugin.remove(name); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - - return !plugin.isEmpty(); - } - - public static void fix() - { - wipeAllPlugin(); - crawlAllPlugins(); - } - - public static class Info - { - public String name; - public String version; - public List depends; - public List rdepends; - - public static class Depend - { - public String name; - public String depend; - } - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java index b6f64ed0..41bb57ae 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java @@ -48,10 +48,6 @@ public static String[] getRemovableDataDirs() */ public static boolean clean(String name) { - //依存関係エラーが有った場合は安全を優先しreturn - if (DependencyTree.isErrors()) - return false; - Plugin plugin = Bukkit.getPluginManager().getPlugin(name); if (PluginUtil.isPluginLoaded(name)) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java deleted file mode 100644 index 3e095dbb..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/PluginEventListener.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin; - -import lombok.AllArgsConstructor; -import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.server.PluginDisableEvent; -import org.bukkit.event.server.PluginEnableEvent; - -import java.io.File; - -@AllArgsConstructor -public class PluginEventListener implements Listener -{ - private final TeamKunPluginManager kpmInstance; - - @EventHandler - public void onEnable(PluginEnableEvent e) - { - if (!kpmInstance.isEnableBuildTree()) - return; - kpmInstance.getLogger().info("依存関係ツリーを構築中(ADD:" + e.getPlugin().getName() + ")..."); - DependencyTree.crawlPlugin(e.getPlugin()); - kpmInstance.getLogger().info("依存関係ツリーの構築完了"); - } - - @EventHandler - public void onDisable(PluginDisableEvent e) - { - if (!kpmInstance.isEnableBuildTree()) - return; - - Runner.runLater(() -> { - File f = PluginUtil.getFile(e.getPlugin()); - if (f == null || !f.exists()) - { - kpmInstance.getLogger().info("依存関係ツリーを構築中(RMV:" + e.getPlugin().getName() + ")..."); - DependencyTree.wipePlugin(e.getPlugin()); - kpmInstance.getLogger().info("依存関係ツリーの構築完了"); - } - }, 2L); - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index 5600ea98..7afa267e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; @@ -14,6 +14,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependencyNode; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.ReversedCollector; @@ -171,13 +172,12 @@ private ArrayList getAllDependencies(Plugin target) { ArrayList plugins = new ArrayList<>(); - DependencyTree.Info info = DependencyTree.getInfo(target.getName(), false); - if (info == null) - return new ArrayList<>(); + List dependencies = + TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().getDependOn(target.getName()); - for (DependencyTree.Info.Depend depend : info.rdepends) + for (DependencyNode depend : dependencies) { - Plugin dependPlugin = this.getPlugin(depend.depend); + Plugin dependPlugin = this.getPlugin(depend.getDependsOn()); if (dependPlugin != null) { plugins.add(dependPlugin); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 79ce9bc8..509aa3e4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -2,7 +2,6 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; @@ -102,8 +101,11 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan for (Plugin plugin : orderedUninstallTargets) { + TeamKunPluginManager.getPlugin().getPluginMetaManager().preparePluginModify(plugin.getName()); + PluginDescriptionFile description = plugin.getDescription(); UnInstallErrorCause errorCause = uninstallOnePlugin(plugin); + if (errorCause == UnInstallErrorCause.INTERNAL_UNINSTALL_OK) uninstalledPlugins.add(description); else @@ -118,7 +120,7 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan if (pluginFile.exists()) pluginFile.delete(); - DependencyTree.wipePlugin(plugin); + TeamKunPluginManager.getPlugin().getPluginMetaManager().onUninstalled(plugin.getName()); }), 20L); orderedUninstallTargets.stream() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index f48759e1..65edd592 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -8,6 +8,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.sql.Connection; @@ -17,6 +18,8 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * プラグインのメタデータを提供するクラスです。 @@ -37,38 +40,6 @@ public PluginMetaProvider(@NotNull Plugin plugin, @NotNull Path databasePath) Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, plugin), 1L); } - private static List createDependencyNodes(String pluginName, List dependencies, List softDependencies, List loadBefore) - { - List dependencyNodes = new ArrayList<>(); - List processed = new ArrayList<>(); - - for (String dependency : dependencies) - { - dependencyNodes.add(new DependencyNode(pluginName, dependency, DependType.HARD_DEPEND)); - processed.add(dependency); - } - - for (String softDependency : softDependencies) - { - if (processed.contains(softDependency)) - continue; - - dependencyNodes.add(new DependencyNode(pluginName, softDependency, DependType.SOFT_DEPEND)); - processed.add(softDependency); - } - - for (String load : loadBefore) - { - if (processed.contains(load)) - continue; - - dependencyNodes.add(new DependencyNode(pluginName, load, DependType.LOAD_BEFORE)); - processed.add(load); - } - - return dependencyNodes; - } - /** * このクラスを破棄します。 */ @@ -83,9 +54,11 @@ public void close() * @param pluginName プラグインの名前 * @return 依存しているプラグインのリスト */ - public List getDependOn(@NotNull String pluginName) + public List getDependOn(@NotNull String pluginName) { - return getListFromTable("depend", pluginName, "name"); + return getDependDataFromTable("depend", pluginName, "dependency", + DependType.HARD_DEPEND, false + ); } /** @@ -94,9 +67,11 @@ public List getDependOn(@NotNull String pluginName) * @param pluginName プラグインの名前 * @return 依存しているプラグインのリスト */ - public List getSoftDependOn(@NotNull String pluginName) + public List getSoftDependOn(@NotNull String pluginName) { - return getListFromTable("soft_depend", pluginName, "name"); + return getDependDataFromTable("soft_depend", pluginName, "soft_depend", + DependType.SOFT_DEPEND, false + ); } /** @@ -106,9 +81,11 @@ public List getSoftDependOn(@NotNull String pluginName) * @param pluginName プラグインの名前 * @return 依存しているプラグインのリスト */ - public List getLoadBefore(@NotNull String pluginName) + public List getLoadBefore(@NotNull String pluginName) { - return getListFromTable("load_before", pluginName, "name"); + return getDependDataFromTable("load_before", pluginName, "load_before", + DependType.LOAD_BEFORE, false + ); } /** @@ -117,9 +94,11 @@ public List getLoadBefore(@NotNull String pluginName) * @param pluginName プラグインの名前 * @return 依存されているプラグインのリスト */ - public List getDependedBy(@NotNull String pluginName) + public List getDependedBy(@NotNull String pluginName) { - return getListFromTable("dependency_tree", pluginName, "dependency"); + return getDependDataFromTable("dependency_tree", pluginName, "dependency", + DependType.HARD_DEPEND, true + ); } /** @@ -128,9 +107,11 @@ public List getDependedBy(@NotNull String pluginName) * @param pluginName プラグインの名前 * @return 依存されているプラグインのリスト */ - public List getSoftDependedBy(@NotNull String pluginName) + public List getSoftDependedBy(@NotNull String pluginName) { - return getListFromTable("dependency_tree", pluginName, "soft_dependency"); + return getDependDataFromTable("dependency_tree", pluginName, "soft_dependency", + DependType.SOFT_DEPEND, true + ); } /** @@ -140,9 +121,11 @@ public List getSoftDependedBy(@NotNull String pluginName) * @param pluginName プラグインの名前 * @return 依存されているプラグインのリスト */ - public List getLoadBeforeBy(@NotNull String pluginName) + public List getLoadBeforeBy(@NotNull String pluginName) { - return getListFromTable("dependency_tree", pluginName, "load_before"); + return getDependDataFromTable("dependency_tree", pluginName, "load_before", + DependType.LOAD_BEFORE, true + ); } /** @@ -153,7 +136,7 @@ public List getLoadBeforeBy(@NotNull String pluginName) */ public List getAuthors(@NotNull String pluginName) { - return getListFromTable("plugin_author", pluginName, "author"); + return getListFromTable("plugin_author", pluginName, "name", "author"); } /** @@ -517,6 +500,71 @@ public void removePluginData(@NotNull String pluginName, boolean thinDependencyT } } + /** + * プラグインのメタデータを取得します。 + * + * @param pluginName プラグインの名前 + * @param includeDependencies 依存関係を含めるかどうか + * @return プラグインのメタデータ + */ + public @Nullable PluginMeta getPluginMeta(@NotNull String pluginName, boolean includeDependencies) + { + Connection con; + try + { + con = this.db.getConnection(); + + PreparedStatement statement = + con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + statement.setString(1, pluginName); + + ResultSet resultSet = statement.executeQuery(); + + if (!resultSet.next()) + return null; + + String name = resultSet.getString("name"); + long installedAt = resultSet.getLong("installed_at"); + InstallOperator installedBy = InstallOperator.valueOf(resultSet.getString("installed_by")); + String resolveQuery = resultSet.getString("resolve_query"); + boolean isDependency = resultSet.getInt("is_dependency") == 1; + + statement = con.prepareStatement("SELECT version FROM plugin WHERE name = ?"); + + statement.setString(1, pluginName); + + resultSet = statement.executeQuery(); + + if (!resultSet.next()) + return null; + + String version = resultSet.getString("version"); + + List dependedBy = new ArrayList<>(); + List dependsOn = new ArrayList<>(); + if (includeDependencies) + { + dependedBy = this.getDependedBy(pluginName); + dependsOn = this.getDependOn(pluginName); + } + + return new PluginMeta( + name, + version, + installedBy, + isDependency, + resolveQuery, + installedAt, + dependedBy, + dependsOn + ); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + /** * 依存関係ツリーを保存します。 * @@ -571,13 +619,23 @@ public void buildDependencyTree(@NotNull Plugin plugin) { String pluginName = plugin.getName(); - List dependencies = this.getDependOn(pluginName); - List softDependencies = this.getDependOn(pluginName); - List loadBefore = this.getLoadBeforeBy(pluginName); + List dependencies = this.getDependOn(pluginName); + List softDependencies = this.getDependOn(pluginName); + List loadBefore = this.getLoadBeforeBy(pluginName); + + softDependencies.removeIf(item -> dependencies.stream().parallel() + .map(DependencyNode::getDependsOn) + .anyMatch(item.getDependsOn()::equals)); - List dependencyNodes = createDependencyNodes(pluginName, dependencies, softDependencies, loadBefore); + loadBefore.removeIf(item -> Stream.concat(dependencies.stream(), softDependencies.stream()) + .parallel() + .map(DependencyNode::getDependsOn) + .anyMatch(item.getDependsOn()::equals)); - this.saveDependencyTree(dependencyNodes); + dependencies.addAll(softDependencies); + dependencies.addAll(loadBefore); + + this.saveDependencyTree(dependencies); } /** @@ -619,6 +677,37 @@ public void thinDependencyTree(@NotNull String pluginName) } } + public List getUnusedPlugins() + { + Connection con; + try + { + con = this.db.getConnection(); + + PreparedStatement statement = + con.prepareStatement( + "WITH RECURSIVE cte AS (" + + "SELECT name FROM plugin WHERE name NOT IN (SELECT parent FROM dependency_tree)" + + "UNION ALL " + + "SELECT dependency_tree.name FROM dependency_tree INNER JOIN cte ON dependency_tree.parent = cte.name" + + ")" + + "SELECT name FROM cte" + ); + + ResultSet resultSet = statement.executeQuery(); + List unusedPlugins = new ArrayList<>(); + + while (resultSet.next()) + unusedPlugins.add(resultSet.getString("name")); + + return unusedPlugins; + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + private void initializeTables() { try (Connection con = this.db.getConnection()) @@ -688,9 +777,19 @@ private HikariDataSource createConnection(@NotNull Path databasePath) return new HikariDataSource(config); } - private List getListFromTable(String tableName, String name, String field) + private List getDependDataFromTable(String tableName, String name, String field, DependType type, boolean baseReversed) { - return this.getListFromTable(tableName, name, "name", field); + List depString = this.getListFromTable(tableName, name, baseReversed ? field: "name", baseReversed ? "name": field); + + if (baseReversed) + return depString.stream() + .map(item -> new DependencyNode(item, name, type)) + .collect(Collectors.toList()); + else + return depString.stream() + .map(item -> new DependencyNode(name, item, type)) + .collect(Collectors.toList()); + } @SuppressWarnings("SqlResolve") diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java index 15f1deb3..53322c66 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java @@ -1,22 +1,16 @@ package net.kunmc.lab.teamkunpluginmanager.utils; -import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import org.bukkit.ChatColor; import java.util.List; public class Messages { - public static String getErrorMessage() - { - if (!DependencyTree.isErrors()) - return ""; - return ChatColor.RED + "重大なエラーが検出されました。/kpm fix で修正を行ってください。"; - } public static String getUnInstallableMessage() { - List rmble = DependencyTree.unusedPlugins(); + List rmble = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().getUnusedPlugins(); if (rmble.isEmpty()) return ""; From 3b274f76bb4db13e1cd2c6ecbf83d8fa63fcea09 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 12:10:57 +0900 Subject: [PATCH 301/745] fix: Wrong dependency tree building --- .../plugin/meta/PluginMetaManager.java | 2 +- .../plugin/meta/PluginMetaProvider.java | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index 2e2a6787..b12d490b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -96,7 +96,7 @@ public void onDisable(PluginDisableEvent event) this.onUninstalled(pluginNameFull); System.out.println("依存関係ツリーを構築しています ..."); - this.provider.thinDependencyTree(pluginNameFull); + this.provider.deleteFromDependencyTree(pluginNameFull); } /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 65edd592..70cede7b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -445,10 +445,10 @@ public void removePluginMeta(@NotNull String pluginName) /** * プラグインのデータを削除します。 * - * @param pluginName プラグインの名前 - * @param thinDependencyTree 依存関係ツリーを構築するかどうか + * @param pluginName プラグインの名前 + * @param buildDependencyTree 依存関係ツリーを構築するかどうか */ - public void removePluginData(@NotNull String pluginName, boolean thinDependencyTree) + public void removePluginData(@NotNull String pluginName, boolean buildDependencyTree) { Connection con = null; try @@ -478,8 +478,8 @@ public void removePluginData(@NotNull String pluginName, boolean thinDependencyT con.commit(); - if (thinDependencyTree) - this.thinDependencyTree(pluginName); + if (buildDependencyTree) + this.deleteFromDependencyTree(pluginName); } catch (SQLException e) { @@ -643,7 +643,7 @@ public void buildDependencyTree(@NotNull Plugin plugin) * * @param pluginName プラグインの名前 */ - public void thinDependencyTree(@NotNull String pluginName) + public void deleteFromDependencyTree(@NotNull String pluginName) { Connection con = null; try @@ -651,12 +651,11 @@ public void thinDependencyTree(@NotNull String pluginName) con = this.db.getConnection(); PreparedStatement statement = - con.prepareStatement("DELETE FROM dependency_tree WHERE name = ? OR parent = ?"); + con.prepareStatement("DELETE FROM dependency_tree WHERE name = ?"); statement.setString(1, pluginName); - statement.setString(2, pluginName); statement.execute(); - con.createStatement().execute("COMMIT"); + con.commit(); } catch (SQLException e) { From a3eab02ae940ab102f935cde11e111168758941a Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 12:17:22 +0900 Subject: [PATCH 302/745] fix: Detecting self --- .../plugin/meta/PluginMetaManager.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index b12d490b..9df2c761 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -2,6 +2,7 @@ import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; @@ -66,7 +67,8 @@ public void preparePluginModify(@NotNull Plugin plugin) public void onPluginEnable(PluginEnableEvent event) { Plugin plugin = event.getPlugin(); - if (this.checkNoAutoCreateMetadata(plugin)) + if (plugin.getName().equals(TeamKunPluginManager.getPlugin().getName()) || + this.checkNoAutoCreateMetadata(plugin)) return; String pluginNameFull = PluginUtil.getPluginString(plugin); @@ -85,7 +87,8 @@ public void onPluginEnable(PluginEnableEvent event) public void onDisable(PluginDisableEvent event) { Plugin plugin = event.getPlugin(); - if (this.checkNoAutoCreateMetadata(plugin)) + if (plugin.getName().equals(TeamKunPluginManager.getPlugin().getName()) || + this.checkNoAutoCreateMetadata(plugin)) return; String pluginNameFull = PluginUtil.getPluginString(plugin); From ad938fcab49d09a5ade43dfd7b2e6aef578ef74a Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 12:20:35 +0900 Subject: [PATCH 303/745] fix: Table doesn't commit --- .../teamkunpluginmanager/plugin/meta/PluginMetaProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 70cede7b..9ff2cebc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -755,6 +755,8 @@ private void initializeTables() "depend_type NOT NULL" + ")" ); + + con.commit(); } catch (SQLException e) { From 06ed245dd63d1dbb995bd58dde09c1532482b85e Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 12:33:00 +0900 Subject: [PATCH 304/745] docs: collect javadocs --- .../plugin/meta/PluginMetaProvider.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 9ff2cebc..7b456ec4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -228,6 +228,12 @@ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) } } + /** + * プラグインの解決クエリを更新します。 + * + * @param pluginName プラグインの名前 + * @param query 解決クエリ + */ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query) { Connection con = null; @@ -676,6 +682,11 @@ public void deleteFromDependencyTree(@NotNull String pluginName) } } + /** + * 使用されていないプラグインのリストを取得します。 + * + * @return 使用されていないプラグインのリスト + */ public List getUnusedPlugins() { Connection con; From 1f447c0c1a0708a2a0ca8954425b66f2f81feef9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 12:40:25 +0900 Subject: [PATCH 305/745] feat: Initialize meta --- .../TeamKunPluginManager.java | 3 ++ .../plugin/meta/PluginMetaProvider.java | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index afc9374a..1a5c3aef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -58,6 +58,9 @@ private void setupDependencyTree() Paths.get(plugin.getDataFolder().toURI()).resolve("plugins.db") ); + System.out.println("プラグインメタデータを取得中 ..."); + this.pluginMetaManager.getProvider().crawlAll(); + KnownPlugins.initialization(this.getPluginConfig().getString("resolvePath")); if (KnownPlugins.isLegacy()) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 7b456ec4..e8303845 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -17,6 +17,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -366,6 +367,27 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) } } + /** + * プラグインのメタデータが存在しているかどうかを返します。 + * + * @param pluginName プラグインの名前 + * @return プラグインのメタデータが存在しているかどうか + */ + public boolean isPluginMetaExists(@NotNull String pluginName) + { + try (Connection con = this.db.getConnection()) + { + PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + statement.setString(1, pluginName); + + return statement.executeQuery().next(); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + /** * プラグインのメタデータを保存します。 * @@ -718,6 +740,38 @@ public List getUnusedPlugins() } } + /** + * すべてのプラグインのデータをクロールします。 + */ + public void crawlAll() + { + Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); + + for (Plugin plugin : plugins) + { + if (this.isPluginMetaExists(plugin.getName())) + continue; + + this.savePluginData(plugin, false); + + List dummy = Collections.emptyList(); + this.savePluginMeta( + new PluginMeta( + plugin.getName(), + plugin.getDescription().getVersion(), + InstallOperator.SERVER_ADMIN, + false, // Dummy value + null, + System.currentTimeMillis(), + dummy, + dummy + ) + ); + + this.buildDependencyTree(plugin); + } + } + private void initializeTables() { try (Connection con = this.db.getConnection()) From 85d1383d584a6022b63788d7c750a286002724d0 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 12:42:55 +0900 Subject: [PATCH 306/745] fix: Wrong table name --- .../plugin/meta/PluginMetaProvider.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index e8303845..bc4a1ecb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -97,7 +97,7 @@ public List getLoadBefore(@NotNull String pluginName) */ public List getDependedBy(@NotNull String pluginName) { - return getDependDataFromTable("dependency_tree", pluginName, "dependency", + return getDependDataFromTable("depend", pluginName, "dependency", DependType.HARD_DEPEND, true ); } @@ -110,7 +110,7 @@ public List getDependedBy(@NotNull String pluginName) */ public List getSoftDependedBy(@NotNull String pluginName) { - return getDependDataFromTable("dependency_tree", pluginName, "soft_dependency", + return getDependDataFromTable("soft_depend", pluginName, "soft_dependency", DependType.SOFT_DEPEND, true ); } @@ -124,7 +124,7 @@ public List getSoftDependedBy(@NotNull String pluginName) */ public List getLoadBeforeBy(@NotNull String pluginName) { - return getDependDataFromTable("dependency_tree", pluginName, "load_before", + return getDependDataFromTable("load_before", pluginName, "load_before", DependType.LOAD_BEFORE, true ); } From 7ea43b7e0c7ab330944a1f63608b7b95b6f52bd9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 13:47:45 +0900 Subject: [PATCH 307/745] fix: SQL Connection leak --- .../plugin/meta/PluginMetaProvider.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index bc4a1ecb..02140da5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -276,6 +276,21 @@ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query } throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** @@ -365,6 +380,21 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) } throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** @@ -429,6 +459,21 @@ public void savePluginMeta(@NotNull PluginMeta meta) throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** @@ -468,6 +513,21 @@ public void removePluginMeta(@NotNull String pluginName) throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** @@ -526,6 +586,21 @@ public void removePluginData(@NotNull String pluginName, boolean buildDependency throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** @@ -636,6 +711,21 @@ public void saveDependencyTree(@NotNull List dependencyNodes) throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** @@ -702,6 +792,21 @@ public void deleteFromDependencyTree(@NotNull String pluginName) throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** From b0e8fd4f16b15ab2fbfac945d054354b33ddc42c Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 13:54:38 +0900 Subject: [PATCH 308/745] fix: Clearing --- .../plugin/meta/PluginMetaProvider.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 02140da5..48a86720 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * プラグインのメタデータを提供するクラスです。 @@ -741,15 +740,6 @@ public void buildDependencyTree(@NotNull Plugin plugin) List softDependencies = this.getDependOn(pluginName); List loadBefore = this.getLoadBeforeBy(pluginName); - softDependencies.removeIf(item -> dependencies.stream().parallel() - .map(DependencyNode::getDependsOn) - .anyMatch(item.getDependsOn()::equals)); - - loadBefore.removeIf(item -> Stream.concat(dependencies.stream(), softDependencies.stream()) - .parallel() - .map(DependencyNode::getDependsOn) - .anyMatch(item.getDependsOn()::equals)); - dependencies.addAll(softDependencies); dependencies.addAll(loadBefore); From b6e18d6cc9207d5aa1d8c885c6ed6e13d2e352dd Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 18:46:52 +0900 Subject: [PATCH 309/745] fix: Wrong softDependencies source --- .../teamkunpluginmanager/plugin/meta/PluginMetaProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 48a86720..be8c947a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -69,7 +69,7 @@ public List getDependOn(@NotNull String pluginName) */ public List getSoftDependOn(@NotNull String pluginName) { - return getDependDataFromTable("soft_depend", pluginName, "soft_depend", + return getDependDataFromTable("soft_depend", pluginName, "soft_dependency", DependType.SOFT_DEPEND, false ); } @@ -737,7 +737,7 @@ public void buildDependencyTree(@NotNull Plugin plugin) String pluginName = plugin.getName(); List dependencies = this.getDependOn(pluginName); - List softDependencies = this.getDependOn(pluginName); + List softDependencies = this.getSoftDependOn(pluginName); List loadBefore = this.getLoadBeforeBy(pluginName); dependencies.addAll(softDependencies); From de722e6b9b7e99922f607c1254cb6370aae81bbf Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 21:19:22 +0900 Subject: [PATCH 310/745] fix: Invalid primary key --- .../teamkunpluginmanager/plugin/meta/PluginMetaProvider.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index be8c947a..580e3640 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -910,9 +910,10 @@ private void initializeTables() ); statement.execute("CREATE TABLE IF NOT EXISTS dependency_tree(" + - "name TEXT NOT NULL PRIMARY KEY," + + "name TEXT NOT NULL," + "parent TEXT," + - "depend_type NOT NULL" + + "depend_type TEXT," + + "PRIMARY KEY (name, parent)" + ")" ); From 856f71e728e436a8b5febef6a30de82b38979bf6 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 21:27:19 +0900 Subject: [PATCH 311/745] fix: SQL Connection leak 2 --- .../plugin/meta/PluginMetaProvider.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 580e3640..d0f5148b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -806,7 +806,7 @@ public void deleteFromDependencyTree(@NotNull String pluginName) */ public List getUnusedPlugins() { - Connection con; + Connection con = null; try { con = this.db.getConnection(); @@ -833,6 +833,21 @@ public List getUnusedPlugins() { throw new RuntimeException(e); } + finally + { + if (con != null) + { + try + { + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } } /** From 54894f34068cd9b306d6eba8fcbfd53dc13f3d3b Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 19 Sep 2022 21:57:10 +0900 Subject: [PATCH 312/745] feat: Apply install dependency tree building --- .../tasks/install/PluginsInstallResult.java | 28 ++++++++++++--- .../tasks/install/PluginsInstallTask.java | 34 +++++++++++++------ 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java index fe464043..1e0bcf8b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java @@ -2,9 +2,13 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; + /** * プラグインのインストール結果を表すクラスです。 */ @@ -17,15 +21,29 @@ public class PluginsInstallResult extends TaskResult collectedDependencies; + + public PluginsInstallResult(boolean success, @NotNull PluginsInstallState state, @Nullable PluginsInstallErrorCause errorCause) { - this(success, taskState, errorCause, null); + this(success, state, errorCause, null, null, new ArrayList<>()); } - public PluginsInstallResult(boolean success, @NotNull PluginsInstallState taskState, - @Nullable PluginsInstallErrorCause errorCause, @Nullable String failedPluginName) + public PluginsInstallResult(boolean success, @NotNull PluginsInstallState state, @Nullable PluginsInstallErrorCause errorCause, @Nullable String failedPluginName, @Nullable Plugin installedPlugin, @NotNull List collectedDependencies) { - super(success, taskState, errorCause); + super(success, state, errorCause); this.failedPluginName = failedPluginName; + this.installedPlugin = installedPlugin; + this.collectedDependencies = collectedDependencies; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index 5523e4ec..93e7aeb3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -11,6 +11,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.InstallOperator; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; @@ -81,18 +82,22 @@ private static void patchPluginCommands(List targets) PluginDescriptionFile pluginDescription = dependency.getPluginDescription(); Path path = dependency.getPluginPath(); - PluginsInstallResult result = this.installOne(path, pluginDescription, installedPlugins); - if (result != null) // installOne returns null if installation is failed + PluginsInstallResult result = this.installOne(path, pluginDescription, installedPlugins, true); + if (!result.isSuccess()) // installOne returns null if installation is failed return result; } + for (Plugin plugin : installedPlugins) + TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().buildDependencyTree(plugin); + // Install plugin after dependencies installed - PluginsInstallResult result = - this.installOne(arguments.getPluginPath(), arguments.getPluginDescription(), installedPlugins); - if (result != null) // installOne returns null if installation is failed - return result; - else - return new PluginsInstallResult(true, this.state, null); + + PluginsInstallResult result = this.installOne(arguments.getPluginPath(), arguments.getPluginDescription(), installedPlugins, false); + + if (result.isSuccess() && result.getInstalledPlugin() != null) + TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().buildDependencyTree(result.getInstalledPlugin()); + + return result; } finally { @@ -100,9 +105,9 @@ private static void patchPluginCommands(List targets) } } - @Nullable + @NotNull private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription, - @NotNull List installedPlugins) + @NotNull List installedPlugins, boolean isDependency) { this.postSignal(new PluginInstallingSignal(path, pluginDescription)); @@ -153,6 +158,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr } // Enable plugin + TeamKunPluginManager.getPlugin().getPluginMetaManager().preparePluginModify(target); this.state = PluginsInstallState.PLUGIN_ENABLING; this.postSignal(new PluginEnablingSignal.Pre(target)); PLUGIN_MANAGER.enablePlugin(target); @@ -160,7 +166,13 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr installedPlugins.add(target); - return null; // Success + TeamKunPluginManager.getPlugin().getPluginMetaManager().onInstalled( + target, + isDependency ? InstallOperator.KPM_DEPENDENCY_RESOLVER: InstallOperator.SERVER_ADMIN, + null + ); + + return new PluginsInstallResult(true, this.state, null, null, target, installedPlugins); } @Nullable From e1add71a9327fb109cc17d0a1e84e65d8d8044c3 Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 20 Sep 2022 22:38:25 +0900 Subject: [PATCH 313/745] refactor: Migrate plugin data to meta --- .../tasks/install/PluginsInstallTask.java | 3 +- .../plugin/meta/PluginMeta.java | 11 +- .../plugin/meta/PluginMetaManager.java | 26 +- .../plugin/meta/PluginMetaProvider.java | 308 ++++++------------ 4 files changed, 123 insertions(+), 225 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index 93e7aeb3..729fc9ec 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -169,7 +169,8 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr TeamKunPluginManager.getPlugin().getPluginMetaManager().onInstalled( target, isDependency ? InstallOperator.KPM_DEPENDENCY_RESOLVER: InstallOperator.SERVER_ADMIN, - null + null, + isDependency ); return new PluginsInstallResult(true, this.state, null, null, target, installedPlugins); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java index 3ebee886..591776bf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.meta; import lombok.Value; +import org.bukkit.plugin.PluginLoadOrder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,6 +23,11 @@ public class PluginMeta */ @NotNull String version; + /** + * プラグインのロードタイミングです。 + */ + @NotNull + PluginLoadOrder loadTiming; /** * プラグインのインストール者です。 @@ -44,14 +50,13 @@ public class PluginMeta long installedAt; /** - * 依存しているプラグインのリストです。 + * 依存されているプラグインのリストです。 */ @NotNull List dependedBy; /** - * + * 依存しているプラグインのリストです。 */ @NotNull List dependsOn; - } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index 9df2c761..a3354853 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -76,7 +76,7 @@ public void onPluginEnable(PluginEnableEvent event) System.out.println("プラグインの追加が検出されました: " + pluginNameFull); System.out.println("プラグインのメタデータを作成してします ..."); - this.onInstalled(plugin, InstallOperator.SERVER_ADMIN, null); + this.onInstalled(plugin, InstallOperator.SERVER_ADMIN, null, false); System.out.println("依存関係ツリーを構築しています ..."); this.provider.buildDependencyTree(plugin); @@ -110,22 +110,15 @@ public void onDisable(PluginDisableEvent event) * @param resolveQuery インストール時に使用したプラグイン解決クエリ * @param installedAt インストールされた時刻 */ - public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, long installedAt) + public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, long installedAt, boolean isDependency) { - this.provider.savePluginData(plugin, false); - List dummy = Collections.emptyList(); this.provider.savePluginMeta( - new PluginMeta( - plugin.getName(), - plugin.getDescription().getVersion(), - operator, - false, // Dummy value - resolveQuery, - installedAt, - dummy, - dummy - ) + plugin, + operator, + installedAt, + resolveQuery, + isDependency ); } @@ -136,9 +129,9 @@ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operato * @param operator インストールした操作者 * @param resolveQuery インストール時に使用したプラグイン解決クエリ */ - public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery) + public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, boolean isDependency) { - onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis()); + onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis(), isDependency); } /** @@ -148,7 +141,6 @@ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operato */ public void onUninstalled(@NotNull String pluginName) { - this.provider.removePluginData(pluginName, false); this.provider.removePluginMeta(pluginName); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index d0f5148b..cb29eb22 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -7,6 +7,7 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginLoadOrder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,7 +18,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -160,7 +160,7 @@ public InstallOperator getInstalledBy(@NotNull String pluginName) { try (Connection con = this.db.getConnection()) { - PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); ResultSet resultSet = statement.executeQuery(); @@ -187,7 +187,7 @@ public boolean isDependency(@NotNull String pluginName) { try (Connection con = this.db.getConnection()) { - PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); ResultSet resultSet = statement.executeQuery(); @@ -214,7 +214,7 @@ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) try (Connection con = this.db.getConnection()) { con.createStatement().execute("BEGIN TRANSACTION"); - PreparedStatement statement = con.prepareStatement("UPDATE meta SET is_dependency = ? WHERE name = ?"); + PreparedStatement statement = con.prepareStatement("UPDATE plugin_meta SET is_dependency = ? WHERE name = ?"); statement.setInt(1, isDependency ? 0: 1); statement.setString(2, pluginName); @@ -242,7 +242,7 @@ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query con = this.db.getConnection(); con.createStatement().execute("BEGIN TRANSACTION"); // Check if the plugin exists - PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); if (!statement.executeQuery().next()) @@ -251,7 +251,7 @@ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query throw new IllegalArgumentException("Plugin does not exist"); } - statement = con.prepareStatement("UPDATE meta SET resolve_query = ? WHERE name = ?"); + statement = con.prepareStatement("UPDATE plugin_meta SET resolve_query = ? WHERE name = ?"); statement.setString(1, query); statement.setString(2, pluginName); @@ -292,13 +292,7 @@ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query } } - /** - * プラグインデータを保存します。 - * - * @param plugin プラグイン - * @param buildDependencyTree 依存関係ツリーを構築するかどうか - */ - public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) + private void savePluginRelationalData(Connection connection, Plugin plugin) throws SQLException { PluginDescriptionFile description = plugin.getDescription(); @@ -311,89 +305,43 @@ public void savePluginData(@NotNull Plugin plugin, boolean buildDependencyTree) List softDependencies = description.getSoftDepend(); List loadBefore = description.getLoadBefore(); - Connection con = null; - try + PreparedStatement statement = + connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); + statement.setString(1, name); + + for (String author : authors) { - con = this.db.getConnection(); - PreparedStatement statement = - con.prepareStatement("INSERT INTO plugin(name, version, load_timing) VALUES(?, ?, ?)"); - statement.setString(1, name); - statement.setString(2, version); - statement.setString(3, loadTiming); + statement.setString(2, author); statement.execute(); + } - statement = con.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); - statement.setString(1, name); - - for (String author : authors) - { - statement.setString(2, author); - statement.execute(); - } - - statement = con.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); - statement.setString(1, name); - - for (String dependency : dependencies) - { - statement.setString(2, dependency); - statement.execute(); - } - - statement = con.prepareStatement("INSERT INTO soft_depend(name, soft_dependency) VALUES(?, ?)"); - statement.setString(1, name); - - for (String softDependency : softDependencies) - { - statement.setString(2, softDependency); - statement.execute(); - } - - statement = con.prepareStatement("INSERT INTO load_before(name, load_before) VALUES(?, ?)"); - statement.setString(1, name); + statement = connection.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); + statement.setString(1, name); - for (String load : loadBefore) - { - statement.setString(2, load); - statement.execute(); - } + for (String dependency : dependencies) + { + statement.setString(2, dependency); + statement.execute(); + } - con.commit(); + statement = connection.prepareStatement("INSERT INTO soft_depend(name, soft_dependency) VALUES(?, ?)"); + statement.setString(1, name); - if (buildDependencyTree) - this.buildDependencyTree(plugin); - } - catch (SQLException e) + for (String softDependency : softDependencies) { - if (con != null) - { - try - { - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } - } - throw new RuntimeException(e); + statement.setString(2, softDependency); + statement.execute(); } - finally + + statement = connection.prepareStatement("INSERT INTO load_before(name, load_before) VALUES(?, ?)"); + statement.setString(1, name); + + for (String load : loadBefore) { - if (con != null) - { - try - { - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } + statement.setString(2, load); + statement.execute(); } + } /** @@ -406,7 +354,7 @@ public boolean isPluginMetaExists(@NotNull String pluginName) { try (Connection con = this.db.getConnection()) { - PreparedStatement statement = con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); return statement.executeQuery().next(); @@ -420,25 +368,42 @@ public boolean isPluginMetaExists(@NotNull String pluginName) /** * プラグインのメタデータを保存します。 * - * @param meta メタデータ + * @param plugin プラグイン + * @param installedBy プラグインのインストール者 + * @param installedAt プラグインのインストール日時 + * @param resolveQuery プラグインの解決クエリ + * @param isDependency プラグインが依存関係かどうか */ - public void savePluginMeta(@NotNull PluginMeta meta) + public void savePluginMeta(@NotNull Plugin plugin, + @NotNull InstallOperator installedBy, + long installedAt, + @Nullable String resolveQuery, + boolean isDependency) + { + Connection con = null; try { con = this.db.getConnection(); PreparedStatement statement = - con.prepareStatement("INSERT INTO meta(name, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?)"); - statement.setString(1, meta.getName()); - statement.setLong(2, meta.getInstalledAt()); - statement.setString(3, meta.getInstalledBy().name()); - statement.setString(4, meta.getResolveQuery()); - statement.setInt(5, meta.isDependency() ? 1: 0); + con.prepareStatement("INSERT INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)"); + + PluginDescriptionFile description = plugin.getDescription(); + + statement.setString(1, description.getName()); + statement.setString(2, description.getVersion()); + statement.setString(3, description.getLoad().name()); + statement.setLong(4, installedAt); + statement.setString(5, installedBy.name()); + statement.setString(6, resolveQuery); + statement.setInt(7, isDependency ? 1: 0); statement.executeUpdate(); + this.savePluginRelationalData(con, plugin); + con.commit(); } catch (SQLException e) @@ -487,12 +452,15 @@ public void removePluginMeta(@NotNull String pluginName) { con = this.db.getConnection(); + this.removePluginRelationalData(con, pluginName); + PreparedStatement statement = - con.prepareStatement("DELETE FROM meta WHERE name = ?"); + con.prepareStatement("DELETE FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); statement.executeUpdate(); + con.commit(); } catch (SQLException e) @@ -529,77 +497,28 @@ public void removePluginMeta(@NotNull String pluginName) } } - /** - * プラグインのデータを削除します。 - * - * @param pluginName プラグインの名前 - * @param buildDependencyTree 依存関係ツリーを構築するかどうか - */ - public void removePluginData(@NotNull String pluginName, boolean buildDependencyTree) + private void removePluginRelationalData(Connection connection, String pluginName) throws SQLException { - Connection con = null; - try - { - con = this.db.getConnection(); - - PreparedStatement statement = - con.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); - statement.setString(1, pluginName); - statement.execute(); - - statement = con.prepareStatement("DELETE FROM depend WHERE name = ?"); - statement.setString(1, pluginName); - statement.execute(); - - statement = con.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); - statement.setString(1, pluginName); - statement.execute(); - - statement = con.prepareStatement("DELETE FROM load_before WHERE name = ?"); - statement.setString(1, pluginName); - statement.execute(); - - statement = con.prepareStatement("DELETE FROM plugin WHERE name = ?"); - statement.setString(1, pluginName); - statement.execute(); - - con.commit(); - - if (buildDependencyTree) - this.deleteFromDependencyTree(pluginName); - } - catch (SQLException e) - { - if (con != null) - { - try - { - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } - } - - throw new RuntimeException(e); - } - finally - { - if (con != null) - { - try - { - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } - } + PreparedStatement statement = + connection.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); + statement.setString(1, pluginName); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM depend WHERE name = ?"); + statement.setString(1, pluginName); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM soft_depend WHERE name = ?"); + statement.setString(1, pluginName); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM load_before WHERE name = ?"); + statement.setString(1, pluginName); + statement.execute(); + + statement = connection.prepareStatement("DELETE FROM plugin_meta WHERE name = ?"); + statement.setString(1, pluginName); + statement.execute(); } /** @@ -617,7 +536,7 @@ public void removePluginData(@NotNull String pluginName, boolean buildDependency con = this.db.getConnection(); PreparedStatement statement = - con.prepareStatement("SELECT * FROM meta WHERE name = ?"); + con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); ResultSet resultSet = statement.executeQuery(); @@ -626,22 +545,13 @@ public void removePluginData(@NotNull String pluginName, boolean buildDependency return null; String name = resultSet.getString("name"); + String version = resultSet.getString("version"); + PluginLoadOrder loadTiming = PluginLoadOrder.valueOf(resultSet.getString("load_timing")); long installedAt = resultSet.getLong("installed_at"); InstallOperator installedBy = InstallOperator.valueOf(resultSet.getString("installed_by")); String resolveQuery = resultSet.getString("resolve_query"); boolean isDependency = resultSet.getInt("is_dependency") == 1; - statement = con.prepareStatement("SELECT version FROM plugin WHERE name = ?"); - - statement.setString(1, pluginName); - - resultSet = statement.executeQuery(); - - if (!resultSet.next()) - return null; - - String version = resultSet.getString("version"); - List dependedBy = new ArrayList<>(); List dependsOn = new ArrayList<>(); if (includeDependencies) @@ -653,6 +563,7 @@ public void removePluginData(@NotNull String pluginName, boolean buildDependency return new PluginMeta( name, version, + loadTiming, installedBy, isDependency, resolveQuery, @@ -814,7 +725,7 @@ public List getUnusedPlugins() PreparedStatement statement = con.prepareStatement( "WITH RECURSIVE cte AS (" + - "SELECT name FROM plugin WHERE name NOT IN (SELECT parent FROM dependency_tree)" + + "SELECT name FROM plugin_meta WHERE name NOT IN (SELECT parent FROM dependency_tree)" + "UNION ALL " + "SELECT dependency_tree.name FROM dependency_tree INNER JOIN cte ON dependency_tree.parent = cte.name" + ")" + @@ -862,20 +773,12 @@ public void crawlAll() if (this.isPluginMetaExists(plugin.getName())) continue; - this.savePluginData(plugin, false); - - List dummy = Collections.emptyList(); this.savePluginMeta( - new PluginMeta( - plugin.getName(), - plugin.getDescription().getVersion(), - InstallOperator.SERVER_ADMIN, - false, // Dummy value - null, - System.currentTimeMillis(), - dummy, - dummy - ) + plugin, + InstallOperator.SERVER_ADMIN, + System.currentTimeMillis(), + null, + false ); this.buildDependencyTree(plugin); @@ -887,27 +790,24 @@ private void initializeTables() try (Connection con = this.db.getConnection()) { Statement statement = con.createStatement(); - statement.execute("CREATE TABLE IF NOT EXISTS plugin(" + - "name TEXT NOT NULL PRIMARY KEY, " + + + statement.execute("CREATE TABLE IF NOT EXISTS plugin_meta(" + + "name TEXT NOT NULL PRIMARY KEY," + "version TEXT NOT NULL," + - "load_timing TEXT NOT NULL" + + "load_timing TEXT NOT NULL," + + "installed_at INTEGER NOT NULL," + + "installed_by TEXT NOT NULL," + + "resolve_query TEXT," + + "is_dependency INTEGER(1) NOT NULL" + ")" ); + statement.execute("CREATE TABLE IF NOT EXISTS plugin_author(" + "name TEXT NOT NULL UNIQUE," + "author TEXT NOT NULL" + ")" ); - statement.execute("CREATE TABLE IF NOT EXISTS meta(" + - "name TEXT NOT NULL PRIMARY KEY, " + - "installed_at INTEGER NOT NULL," + - "installed_by TEXT NOT NULL," + - "resolve_query TEXT," + - "is_dependency INTEGER(1) NOT NULL" + - ")" - ); - statement.execute("CREATE TABLE IF NOT EXISTS depend(" + "name TEXT NOT NULL," + "dependency TEXT" + From 1c7ddb929350f1b87a9ee20cd8b5853439c30aad Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 22 Sep 2022 23:23:43 +0900 Subject: [PATCH 314/745] feat: Dependency debug --- .../commands/CommandDebug.java | 3 + .../commands/debug/CommandDepTreeDebug.java | 49 +++++++++++++ .../CommandMarkAsDependencyCommand.java | 72 +++++++++++++++++++ .../plugin/meta/PluginMetaProvider.java | 2 +- 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java index e7d618b1..2a8261df 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java @@ -2,6 +2,8 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandDepTreeDebug; import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandInstallDebug; import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandUninstallDebug; import net.kyori.adventure.text.TextComponent; @@ -21,6 +23,7 @@ public class CommandDebug extends SubCommandWith COMMANDS = new HashMap<>(); COMMANDS.put("installDebug", new CommandInstallDebug()); COMMANDS.put("uninstallDebug", new CommandUninstallDebug()); + COMMANDS.put("depTree", new CommandDepTreeDebug(TeamKunPluginManager.getPlugin().getPluginMetaManager())); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java new file mode 100644 index 00000000..eeb55d0c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java @@ -0,0 +1,49 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.debug; + +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; +import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandMarkAsDependencyCommand; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +public class CommandDepTreeDebug extends SubCommandWith +{ + private final HashMap COMMANDS; + + public CommandDepTreeDebug(PluginMetaManager manager) + { + COMMANDS = new HashMap<>(); + + COMMANDS.put("markAsDependency", new CommandMarkAsDependencyCommand(manager.getProvider())); + } + + @Override + protected String getName() + { + return "depTree"; + } + + @Override + protected Map getSubCommands(@NotNull CommandSender sender) + { + return COMMANDS; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.debug.deptree"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("依存関係ツリーのデバッグコマンドです。"); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java new file mode 100644 index 00000000..c4570f26 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java @@ -0,0 +1,72 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@AllArgsConstructor +public class CommandMarkAsDependencyCommand extends CommandBase +{ + private final PluginMetaProvider provider; + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 2)) + return; + + String pluginName = args[0]; + boolean isDependency = Boolean.parseBoolean(args[1]); + + + if (!provider.isPluginMetaExists(pluginName)) + { + terminal.error("Cannot find plugin meta of " + pluginName); + return; + } + + provider.setDependencyFlag(pluginName, isDependency); + + terminal.success("Marked " + pluginName + " as " + (isDependency ? "dependency": "not dependency")); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName) + .collect(Collectors.toList()); + } + + @Override + public @Nullable String getPermission() + { + return "kpm.debug.deptree.markAsDependency"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("プラグインを依存関係としてマークします。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("pluginName", "Plugin"), + required("isDependency", "boolean"), + }; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index cb29eb22..4e126253 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -725,7 +725,7 @@ public List getUnusedPlugins() PreparedStatement statement = con.prepareStatement( "WITH RECURSIVE cte AS (" + - "SELECT name FROM plugin_meta WHERE name NOT IN (SELECT parent FROM dependency_tree)" + + "SELECT name FROM plugin_meta WHERE name NOT IN (SELECT parent FROM dependency_tree) AND is_dependency = 1 " + "UNION ALL " + "SELECT dependency_tree.name FROM dependency_tree INNER JOIN cte ON dependency_tree.parent = cte.name" + ")" + From a8dd8d0484fae46d36c78f6f9910007811a46971 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 23 Sep 2022 15:41:05 +0900 Subject: [PATCH 315/745] feat: mark as dependency --- .../CommandMarkAsDependencyCommand.java | 18 +- .../plugin/meta/PluginMetaProvider.java | 233 ++++++++---------- 2 files changed, 122 insertions(+), 129 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java index c4570f26..59a0236f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java @@ -23,19 +23,27 @@ public class CommandMarkAsDependencyCommand extends CommandBase @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (indicateArgsLengthInvalid(terminal, args, 2)) + if (indicateArgsLengthInvalid(terminal, args, 1)) return; String pluginName = args[0]; - boolean isDependency = Boolean.parseBoolean(args[1]); - - if (!provider.isPluginMetaExists(pluginName)) { terminal.error("Cannot find plugin meta of " + pluginName); return; } + + if (args.length < 2) + { + boolean isDependency = provider.getPluginMeta(pluginName, false).isDependency(); + terminal.success("Plugin " + pluginName + " is " + (isDependency ? "dependency": "not dependency")); + + return; + } + + boolean isDependency = Boolean.parseBoolean(args[1]); + provider.setDependencyFlag(pluginName, isDependency); terminal.success("Marked " + pluginName + " as " + (isDependency ? "dependency": "not dependency")); @@ -66,7 +74,7 @@ public String[] getArguments() { return new String[]{ required("pluginName", "Plugin"), - required("isDependency", "boolean"), + optional("isDependency", "boolean"), }; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 4e126253..5c66d3d8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -199,6 +199,7 @@ public boolean isDependency(@NotNull String pluginName) } catch (SQLException e) { + e.printStackTrace(); return false; } } @@ -211,21 +212,47 @@ public boolean isDependency(@NotNull String pluginName) */ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) { - try (Connection con = this.db.getConnection()) + Connection con = null; + try { - con.createStatement().execute("BEGIN TRANSACTION"); + con = this.db.getConnection(); PreparedStatement statement = con.prepareStatement("UPDATE plugin_meta SET is_dependency = ? WHERE name = ?"); - statement.setInt(1, isDependency ? 0: 1); + statement.setInt(1, isDependency ? 1: 0); statement.setString(2, pluginName); statement.executeUpdate(); - con.createStatement().execute("COMMIT TRANSACTION"); + con.commit(); + } catch (SQLException e) { + try + { + if (con != null) + con.rollback(); + } + catch (SQLException e1) + { + System.out.println("Failed to rollback"); + e1.printStackTrace(); + } + throw new RuntimeException(e); } + finally + { + try + { + if (con != null) + con.close(); + } + catch (SQLException e) + { + System.out.println("Failed to close connection"); + e.printStackTrace(); + } + } } /** @@ -240,14 +267,13 @@ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query try { con = this.db.getConnection(); - con.createStatement().execute("BEGIN TRANSACTION"); // Check if the plugin exists PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); if (!statement.executeQuery().next()) { - con.createStatement().execute("ROLLBACK TRANSACTION"); + con.rollback(); throw new IllegalArgumentException("Plugin does not exist"); } @@ -257,37 +283,34 @@ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query statement.executeUpdate(); - con.createStatement().execute("COMMIT TRANSACTION"); + con.commit(); } catch (SQLException e) { - if (con != null) + try { - try - { + if (con != null) con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } + throw new RuntimeException(e); } finally { - if (con != null) + try { - try - { + if (con != null) con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); } } } @@ -408,34 +431,30 @@ public void savePluginMeta(@NotNull Plugin plugin, } catch (SQLException e) { - if (con != null) + try { - try - { + if (con != null) con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); } throw new RuntimeException(e); } finally { - if (con != null) + try { - try - { + if (con != null) con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); } } } @@ -460,39 +479,34 @@ public void removePluginMeta(@NotNull String pluginName) statement.executeUpdate(); - con.commit(); } catch (SQLException e) { - if (con != null) + try { - try - { + if (con != null) con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); } throw new RuntimeException(e); } finally { - if (con != null) + try { - try - { + if (con != null) con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); } } } @@ -528,13 +542,10 @@ private void removePluginRelationalData(Connection connection, String pluginName * @param includeDependencies 依存関係を含めるかどうか * @return プラグインのメタデータ */ - public @Nullable PluginMeta getPluginMeta(@NotNull String pluginName, boolean includeDependencies) + public @NotNull PluginMeta getPluginMeta(@NotNull String pluginName, boolean includeDependencies) { - Connection con; - try + try (Connection con = this.db.getConnection()) { - con = this.db.getConnection(); - PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); statement.setString(1, pluginName); @@ -542,7 +553,7 @@ private void removePluginRelationalData(Connection connection, String pluginName ResultSet resultSet = statement.executeQuery(); if (!resultSet.next()) - return null; + throw new IllegalArgumentException("Plugin " + pluginName + " is not exists"); String name = resultSet.getString("name"); String version = resultSet.getString("version"); @@ -586,7 +597,6 @@ private void removePluginRelationalData(Connection connection, String pluginName public void saveDependencyTree(@NotNull List dependencyNodes) { Connection con = null; - try { con = this.db.getConnection(); @@ -606,34 +616,30 @@ public void saveDependencyTree(@NotNull List dependencyNodes) } catch (SQLException e) { - if (con != null) + try { - try - { + if (con != null) con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); } throw new RuntimeException(e); } finally { - if (con != null) + try { - try - { + if (con != null) con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); } } } @@ -678,34 +684,31 @@ public void deleteFromDependencyTree(@NotNull String pluginName) } catch (SQLException e) { - if (con != null) + try { - try - { + if (con != null) con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); } throw new RuntimeException(e); } finally { - if (con != null) + try { - try - { + + if (con != null) con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); } } } @@ -717,11 +720,8 @@ public void deleteFromDependencyTree(@NotNull String pluginName) */ public List getUnusedPlugins() { - Connection con = null; - try + try (Connection con = this.db.getConnection()) { - con = this.db.getConnection(); - PreparedStatement statement = con.prepareStatement( "WITH RECURSIVE cte AS (" + @@ -744,21 +744,6 @@ public List getUnusedPlugins() { throw new RuntimeException(e); } - finally - { - if (con != null) - { - try - { - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } - } } /** From 455814b6fc46790c416163eb09a359c79dca061c Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 23 Sep 2022 15:50:04 +0900 Subject: [PATCH 316/745] fix: AutoRemove stops server thread --- .../commands/CommandAutoRemove.java | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index c582b426..3c3fafe2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -2,6 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; @@ -11,7 +12,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -23,12 +23,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (checkPermission(sender, terminal, "kpm.autoremove")) sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - if (!TeamKunPluginManager.getPlugin().getSession().lock()) - { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); - return; - } - AtomicInteger removed = new AtomicInteger(); sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); @@ -43,23 +37,13 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } - try - { - TeamKunPluginManager.getPlugin().getInstallManager().runUninstall( - terminal, - new UninstallArgument(removables.toArray(new String[0])) - ); - } - catch (IOException e) - { - sender.sendMessage(ChatColor.RED + "E: プラグインの削除に失敗しました。"); - sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); - sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - return; - } + Runner.runAsync(() -> + TeamKunPluginManager.getPlugin().getInstallManager().runUninstall( + terminal, + new UninstallArgument(removables.toArray(new String[0])) + ) + ); - TeamKunPluginManager.getPlugin().getSession().unlock(); } @Override From 26b917f90a3d25288a2d845e04aa8e51ded01910 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 23 Sep 2022 16:44:39 +0900 Subject: [PATCH 317/745] refactor: Fix code coverage --- .../plugin/meta/PluginMetaManager.java | 2 -- .../plugin/meta/PluginMetaProvider.java | 22 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index a3354853..71b2cd54 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -15,7 +15,6 @@ import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -112,7 +111,6 @@ public void onDisable(PluginDisableEvent event) */ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, long installedAt, boolean isDependency) { - List dummy = Collections.emptyList(); this.provider.savePluginMeta( plugin, operator, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 5c66d3d8..d9fb6145 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -238,7 +238,7 @@ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) e1.printStackTrace(); } - throw new RuntimeException(e); + throw new IllegalStateException(e); } finally { @@ -298,7 +298,7 @@ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query ex.printStackTrace(); } - throw new RuntimeException(e); + throw new IllegalStateException(e); } finally { @@ -384,7 +384,7 @@ public boolean isPluginMetaExists(@NotNull String pluginName) } catch (SQLException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -442,7 +442,7 @@ public void savePluginMeta(@NotNull Plugin plugin, ex.printStackTrace(); } - throw new RuntimeException(e); + throw new IllegalStateException(e); } finally { @@ -494,7 +494,7 @@ public void removePluginMeta(@NotNull String pluginName) ex.printStackTrace(); } - throw new RuntimeException(e); + throw new IllegalStateException(e); } finally { @@ -585,7 +585,7 @@ private void removePluginRelationalData(Connection connection, String pluginName } catch (SQLException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -627,7 +627,7 @@ public void saveDependencyTree(@NotNull List dependencyNodes) ex.printStackTrace(); } - throw new RuntimeException(e); + throw new IllegalStateException(e); } finally { @@ -695,7 +695,7 @@ public void deleteFromDependencyTree(@NotNull String pluginName) ex.printStackTrace(); } - throw new RuntimeException(e); + throw new IllegalStateException(e); } finally { @@ -742,7 +742,7 @@ public List getUnusedPlugins() } catch (SQLException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -821,7 +821,7 @@ private void initializeTables() } catch (SQLException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -872,7 +872,7 @@ private List getListFromTable(String tableName, String name, String quer } catch (SQLException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } return depends; From be8127e2856dc0acff02489a3e0881cff34b3d3a Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 23 Sep 2022 20:10:32 +0900 Subject: [PATCH 318/745] refactor: crawlAll to PluginMetaManager --- .../TeamKunPluginManager.java | 2 +- .../plugin/meta/PluginMetaManager.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 1a5c3aef..695dfda8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -59,7 +59,7 @@ private void setupDependencyTree() ); System.out.println("プラグインメタデータを取得中 ..."); - this.pluginMetaManager.getProvider().crawlAll(); + this.pluginMetaManager.crawlAll(); KnownPlugins.initialization(this.getPluginConfig().getString("resolvePath")); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index 71b2cd54..92aa3527 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -132,6 +132,30 @@ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operato onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis(), isDependency); } + /** + * すべてのプラグインのデータをクロールします。 + */ + public void crawlAll() + { + Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); + + for (Plugin plugin : plugins) + { + if (this.provider.isPluginMetaExists(plugin.getName())) + continue; + + this.provider.savePluginMeta( + plugin, + InstallOperator.SERVER_ADMIN, + System.currentTimeMillis(), + null, + false + ); + + this.provider.buildDependencyTree(plugin); + } + } + /** * プラグインがアンインストールされたときに呼び出します。 * From 5b46fa05089bc6f7ea791fc3538b6a80a746fe70 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 23 Sep 2022 20:12:28 +0900 Subject: [PATCH 319/745] fix: missing tab complete --- ...ncyCommand.java => CommandMarkAsDependency.java} | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/{CommandMarkAsDependencyCommand.java => CommandMarkAsDependency.java} (85%) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java index 59a0236f..b7224835 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependencyCommand.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; @AllArgsConstructor -public class CommandMarkAsDependencyCommand extends CommandBase +public class CommandMarkAsDependency extends CommandBase { private final PluginMetaProvider provider; @@ -52,9 +52,14 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, @Override public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() - .map(Plugin::getName) - .collect(Collectors.toList()); + if (args.length == 1) + return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName) + .collect(Collectors.toList()); + else if (args.length == 2) + return Arrays.asList("true", "false"); + + return null; } @Override From aef395a91c16a0fbb1773cfe7cd0b3563b74dd6d Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 23 Sep 2022 20:13:04 +0900 Subject: [PATCH 320/745] refactor: Remove unused method --- .../plugin/meta/PluginMetaProvider.java | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index d9fb6145..294bb36c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -746,30 +746,6 @@ public List getUnusedPlugins() } } - /** - * すべてのプラグインのデータをクロールします。 - */ - public void crawlAll() - { - Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); - - for (Plugin plugin : plugins) - { - if (this.isPluginMetaExists(plugin.getName())) - continue; - - this.savePluginMeta( - plugin, - InstallOperator.SERVER_ADMIN, - System.currentTimeMillis(), - null, - false - ); - - this.buildDependencyTree(plugin); - } - } - private void initializeTables() { try (Connection con = this.db.getConnection()) From 8bdec2f10392b0228cde060964b47beb9c561a59 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 23 Sep 2022 21:53:29 +0900 Subject: [PATCH 321/745] feat: CommandRelation --- .../commands/debug/CommandDepTreeDebug.java | 6 +- .../debug/deptree/CommandRelation.java | 143 ++++++++++++++++++ .../plugin/meta/PluginMetaProvider.java | 107 +++++++++++++ 3 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java index eeb55d0c..b34c7306 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java @@ -2,7 +2,8 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; -import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandMarkAsDependencyCommand; +import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandMarkAsDependency; +import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandRelation; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -20,7 +21,8 @@ public CommandDepTreeDebug(PluginMetaManager manager) { COMMANDS = new HashMap<>(); - COMMANDS.put("markAsDependency", new CommandMarkAsDependencyCommand(manager.getProvider())); + COMMANDS.put("markAsDependency", new CommandMarkAsDependency(manager.getProvider())); + COMMANDS.put("relation", new CommandRelation(manager.getProvider())); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java new file mode 100644 index 00000000..cddade25 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java @@ -0,0 +1,143 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree; + +import com.google.common.base.Enums; +import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependType; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependencyNode; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMeta; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@AllArgsConstructor +public class CommandRelation extends CommandBase +{ + private final PluginMetaProvider provider; + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 1)) + return; + + String pluginName = args[0]; + if (!provider.isPluginMetaExists(pluginName)) + { + terminal.error("Cannot find plugin meta of " + pluginName); + return; + } + + if (args.length < 2) + { + List dependencies = provider.getPluginMeta(pluginName, false).getDependsOn(); + terminal.success("Plugin " + pluginName + " depends on " + + dependencies.stream() + .map(DependencyNode::getDependsOn) + .sorted() + .collect(Collectors.joining(", "))); + return; + } + + Optional type = Enums.getIfPresent(DependType.class, args[1].toUpperCase()).toJavaUtil(); + if (!type.isPresent()) + { + terminal.error("Invalid relational type: " + args[1]); + return; + } + + PluginMeta meta = provider.getPluginMeta(pluginName, true); + if (args.length < 3) + { + List dependencies = meta.getDependsOn(); + terminal.success("Plugin " + pluginName + " depends on " + + dependencies.stream() + .filter(d -> d.getDependType() == type.get()) + .map(DependencyNode::getDependsOn) + .sorted() + .collect(Collectors.joining(", "))); + return; + } + + String targetPluginName = args[2]; + if (!provider.isPluginMetaExists(targetPluginName)) + { + terminal.error("Cannot find plugin meta of " + targetPluginName); + return; + } + + + DependencyNode node = meta.getDependsOn().stream() + .filter(d -> d.getDependsOn().equals(targetPluginName)) + .findFirst() + .orElse(null); + + boolean addMode = !meta.getDependsOn().removeIf(d -> d.getDependsOn().equals(targetPluginName)); + + if (addMode) + { + meta.getDependsOn().add(new DependencyNode(pluginName, targetPluginName, type.get())); + terminal.success("Added dependency " + targetPluginName + " to " + pluginName + " with type " + type.get()); + + provider.savePluginMeta(meta); + } + else + { + assert node != null; + terminal.success("Removed dependency " + targetPluginName + " from " + pluginName + " with type " + node.getDependType()); + + provider.savePluginMeta(meta); + } + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + switch (args.length) + { + case 1: + case 3: + return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName) + .collect(Collectors.toList()); + case 2: + return Arrays.stream(DependType.values()).parallel() + .map(DependType::name) + .collect(Collectors.toList()); + default: + return null; + } + } + + @Override + public @Nullable String getPermission() + { + return "kpm.debug.deptree.relation"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("プラグインの依存関係を変更します。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("plugin", "Plugin"), + optional("depend_type", "DependType"), + optional("depend_plugin", "Plugin") + }; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 294bb36c..56079faa 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -367,6 +367,54 @@ private void savePluginRelationalData(Connection connection, Plugin plugin) thro } + private static List getStringDependsOn(List nodes, DependType type) + { + return nodes.stream().parallel() + .filter(node -> node.getDependType() == type) + .map(DependencyNode::getDependsOn) + .collect(Collectors.toList()); + } + + private static void deleteAndSaveDepends(Connection connection, String tableName, String fieldName, String name, + List depends) throws SQLException + { + PreparedStatement statement = connection.prepareStatement("DELETE FROM " + tableName + " WHERE name = ?"); + statement.setString(1, name); + statement.executeUpdate(); + + statement = connection.prepareStatement("INSERT INTO " + tableName + "(name, " + fieldName + ") VALUES(?, ?)"); + statement.setString(1, name); + + for (String depend : depends) + { + statement.setString(2, depend); + statement.executeUpdate(); + } + } + + private void savePluginRelationalData(Connection connection, PluginMeta meta) throws SQLException + { + String name = meta.getName(); + String version = meta.getVersion(); + // TODO: List authors = meta.getAuthors(); + String loadTiming = meta.getLoadTiming().name(); + + List dependsOn = meta.getDependsOn(); + List dependencies = getStringDependsOn(dependsOn, DependType.HARD_DEPEND); + List softDependencies = getStringDependsOn(dependsOn, DependType.SOFT_DEPEND); + List loadBefore = getStringDependsOn(dependsOn, DependType.LOAD_BEFORE); + + deleteAndSaveDepends(connection, "depend", "dependency", name, dependencies); + deleteAndSaveDepends(connection, "soft_depend", "soft_dependency", name, softDependencies); + deleteAndSaveDepends(connection, "load_before", "load_before", name, loadBefore); + + PreparedStatement statement = connection.prepareStatement("UPDATE plugin_meta SET version = ?, load_timing = ? WHERE name = ?"); + statement.setString(1, version); + statement.setString(2, loadTiming); + statement.setString(3, name); + statement.executeUpdate(); + } + /** * プラグインのメタデータが存在しているかどうかを返します。 * @@ -459,6 +507,59 @@ public void savePluginMeta(@NotNull Plugin plugin, } } + public void savePluginMeta(@NotNull PluginMeta meta) + { + Connection con = null; + try + { + con = this.db.getConnection(); + + PreparedStatement statement = + con.prepareStatement("INSERT OR REPLACE INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)"); + statement.setString(1, meta.getName()); + statement.setString(2, meta.getVersion()); + statement.setString(3, meta.getLoadTiming().name()); + statement.setLong(4, meta.getInstalledAt()); + statement.setString(5, meta.getInstalledBy().name()); + statement.setString(6, meta.getResolveQuery()); + statement.setInt(7, meta.isDependency() ? 1: 0); + + statement.executeUpdate(); + + this.savePluginRelationalData(con, meta); + + con.commit(); + } + catch (SQLException e) + { + try + { + if (con != null) + con.rollback(); + } + catch (SQLException ex) + { + System.err.println("Failed to rollback transaction"); + ex.printStackTrace(); + } + + throw new IllegalStateException(e); + } + finally + { + try + { + if (con != null) + con.close(); + } + catch (SQLException e) + { + System.err.println("Failed to close connection"); + e.printStackTrace(); + } + } + } + /** * プラグインのメタデータを削除します。 * @@ -569,6 +670,12 @@ private void removePluginRelationalData(Connection connection, String pluginName { dependedBy = this.getDependedBy(pluginName); dependsOn = this.getDependOn(pluginName); + + dependedBy.addAll(this.getSoftDependedBy(pluginName)); + dependsOn.addAll(this.getSoftDependOn(pluginName)); + + dependedBy.addAll(this.getLoadBeforeBy(pluginName)); + dependsOn.addAll(this.getLoadBefore(pluginName)); } return new PluginMeta( From 43d61262bd3b392a40d16ea89b2493f109ef050a Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 28 Sep 2022 23:18:57 +0900 Subject: [PATCH 322/745] fix: Debug relation error --- .../debug/deptree/CommandRelation.java | 4 +++ .../plugin/meta/PluginMetaProvider.java | 26 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java index cddade25..7c4f7105 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java @@ -98,6 +98,10 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, provider.savePluginMeta(meta); } + + provider.deleteFromDependencyTree(pluginName); + provider.deleteFromDependencyTree(targetPluginName); + provider.buildDependencyTree(pluginName); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 56079faa..f3242339 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -758,8 +758,16 @@ public void saveDependencyTree(@NotNull List dependencyNodes) */ public void buildDependencyTree(@NotNull Plugin plugin) { - String pluginName = plugin.getName(); + this.buildDependencyTree(plugin.getName()); + } + /** + * 依存関係ツリーを構築します。 + * + * @param pluginName プラグイン + */ + public void buildDependencyTree(@NotNull String pluginName) + { List dependencies = this.getDependOn(pluginName); List softDependencies = this.getSoftDependOn(pluginName); List loadBefore = this.getLoadBeforeBy(pluginName); @@ -831,12 +839,20 @@ public List getUnusedPlugins() { PreparedStatement statement = con.prepareStatement( - "WITH RECURSIVE cte AS (" + - "SELECT name FROM plugin_meta WHERE name NOT IN (SELECT parent FROM dependency_tree) AND is_dependency = 1 " + + // Source: dependency_tree + // Recursive: + // 1. Select plugins that plugin_meta.is_dependency = 1 and is no plugin depends on it. + // 2. Select plugins that step 1's plugins depends on and plugin_meta.is_dependency = 1. + + "WITH RECURSIVE unused_plugins(name) AS (" + + "SELECT name FROM plugin_meta WHERE is_dependency = 1 AND name NOT IN (" + + "SELECT parent FROM dependency_tree" + + ")" + "UNION ALL " + - "SELECT dependency_tree.name FROM dependency_tree INNER JOIN cte ON dependency_tree.parent = cte.name" + + "SELECT dependency_tree.name FROM dependency_tree, unused_plugins WHERE 0 = 1 AND dependency_tree.parent = unused_plugins.name " + + "AND dependency_tree.name IN(SELECT name FROM plugin_meta WHERE is_dependency = 1)" + ")" + - "SELECT name FROM cte" + "SELECT name FROM unused_plugins" ); ResultSet resultSet = statement.executeQuery(); From 06cc066b48c1deea600ee7f0428f340418c61f37 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 1 Oct 2022 23:39:41 +0900 Subject: [PATCH 323/745] feat: Recursive unused MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit やっとうごいた!!!!!!!!!!!最初はこういうのSQLのワンライナーでやろうと思ったんだけどなにせSQLあんまなれてないからうまくいかんのよね。SQLで無理やりしようとしてたときは再帰クエリ使ってたんだけど、最初はWITH RECURSIVEで初めてたの。これだとなんかちょっと無理だったから SELECT ... WHERE NOT EXISTS(WITH...)ってしてみた。それで1日くらい溶かしたんだけど、やっぱアプローチが違う気がするんだよね。そもそもRECURSIVEの非再帰の部分にis_dependency = 1 してたんだけど、これもしかして逆かなーって思って逆にしてみたんだけど、やっぱだめだった。。。ただ、ただ、あと一歩の部分まで行けた版があって、とりあえず前のアプローチ試しつつ、INNER JOINとか使ってみたら、とりあえず基本的には動いたんだよね。でも依存関係のチェーンが3ノードを超えるとうまく動かなったりで。。。あ、でも今回のフルJava版はちゃんと動いてるから安心してね。このたった20行くらいに見えるコードに4日分んの努力詰まってるから。これRedmineの作業内容書こうかな。。。いいや。とりあえずあとでこれをフルSQLで書き直ししたいんだけどどうしたものか。StackOverflowとかで質問しようかな...なんて。でもハードル高いんだよねあれ。もちろんなんたらtailよりは低いよ。あそこはこわいよ。。。このコミットのコメントとかもミュートしとかなきゃ。。。そもそもテーブルの設計が少々特殊でね。あ、そういえばSQLiteにもINSERT時に他のテーブルに突っ込む機能ほしいな。いや、それはどうでもよくって、テーブルの設計が少々特殊なんだよこれ。いや元はと言えば誰が悪いかというと私なんだけど。。。あ、この話もちょっと違うね。まあ何はともあれうまく動いたからとりあえずコミット。 --- .../plugin/meta/PluginMetaProvider.java | 116 ++++++++++++++---- 1 file changed, 92 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index f3242339..d39b3825 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -829,44 +829,112 @@ public void deleteFromDependencyTree(@NotNull String pluginName) } /** - * 使用されていないプラグインのリストを取得します。 + * 使われていない依存関係のリストを取得します。 + *

    + * (プラグインが依存関係であるかどうかは、plugin_meta.is_dependencyを使用して確認できます) + * 関係はdependency_treeテーブルに格納されています。 + *

    + * + *

    + * 例:サーバにインストールされているプラグイン: + * PluginAは依存関係 + * PluginBは依存関係 + * PluginCは依存関係ではない + *

    + * + *

    + * 例1: + *

      + *
    • PluginAはPluginBに依存している
    • + *
    • PluginBとPluginCの間には依存関係はない
    • + *
    + * この場合、このメソッドはPluginAとPluginBを返します。 + * なぜなら、PluginBはPluginAによって使用されていますが、PluginAはどのプラグインにも使用されていないからです。 + *

    + * + *

    + * 例2: + *

      + *
    • PluginCはPluginAに依存している
    • + *
    • PluginAはPluginBに依存している
    • + *
    + * この場合、このメソッドはどのプラグインも返しません。 + * なぜなら、PluginAはPluginCによって使用されていますが、PluginCは依存関係ではなく、サーバがこのプラグインを使用しているためです。 + *

    * * @return 使用されていないプラグインのリスト */ public List getUnusedPlugins() { + List unusedPlugins = new ArrayList<>(); + try (Connection con = this.db.getConnection()) { - PreparedStatement statement = - con.prepareStatement( - // Source: dependency_tree - // Recursive: - // 1. Select plugins that plugin_meta.is_dependency = 1 and is no plugin depends on it. - // 2. Select plugins that step 1's plugins depends on and plugin_meta.is_dependency = 1. - - "WITH RECURSIVE unused_plugins(name) AS (" + - "SELECT name FROM plugin_meta WHERE is_dependency = 1 AND name NOT IN (" + - "SELECT parent FROM dependency_tree" + - ")" + - "UNION ALL " + - "SELECT dependency_tree.name FROM dependency_tree, unused_plugins WHERE 0 = 1 AND dependency_tree.parent = unused_plugins.name " + - "AND dependency_tree.name IN(SELECT name FROM plugin_meta WHERE is_dependency = 1)" + - ")" + - "SELECT name FROM unused_plugins" - ); - - ResultSet resultSet = statement.executeQuery(); - List unusedPlugins = new ArrayList<>(); + Statement statement = con.createStatement(); + ResultSet resultSet = statement.executeQuery("SELECT name FROM plugin_meta WHERE is_dependency = 1"); while (resultSet.next()) - unusedPlugins.add(resultSet.getString("name")); - - return unusedPlugins; + { + String name = resultSet.getString("name"); + int checkUnused = this.isUnusedRecursive(con, name, 0); + if (checkUnused == 0) // 0 = unused + unusedPlugins.add(name); + } } catch (SQLException e) { throw new IllegalStateException(e); } + + return unusedPlugins; + } + + // -1: Error + // 0: Unused + // 1: Used + private int isUnusedRecursive(Connection con, @NotNull String pluginName, int depth) throws SQLException + { + if (depth > 10) + return -1; + + PreparedStatement statement = con.prepareStatement("SELECT name, parent FROM dependency_tree WHERE parent = ?"); + PreparedStatement checkIsDependency = + con.prepareStatement("SELECT COUNT(name) FROM plugin_meta WHERE name = ? AND is_dependency = 1"); + statement.setString(1, pluginName); + ResultSet resultSet = statement.executeQuery(); + + if (isNotDependencyInternal(con, checkIsDependency, pluginName)) + return 0; + + while (resultSet.next()) + { + String name = resultSet.getString("name"); + String parent = resultSet.getString("parent"); + + if (isNotDependencyInternal(con, checkIsDependency, name)) + return 1; + + int checkUnused = this.isUnusedRecursive(con, name, depth + 1); + if (checkUnused == 1) + return 1; + } + + return 0; + } + + private boolean isNotDependencyInternal(Connection con, PreparedStatement stmt, String target) throws SQLException + { + stmt.setString(1, target); + ResultSet resultSet = stmt.executeQuery(); + if (resultSet.next()) + { + int count = resultSet.getInt(1); + resultSet.close(); + return count == 0; + } + + resultSet.close(); + return false; } private void initializeTables() From ba7980d0520056954859ebd83c48bbd831b8ddf0 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 00:01:51 +0900 Subject: [PATCH 324/745] fix: Exception on plugin not found --- .../teamkunpluginmanager/commands/CommandInfo.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index b3590609..1fda6fd0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependType; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMeta; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; @@ -90,15 +91,17 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (indicateArgsLengthInvalid(terminal, args, 1, 1)) return; - if (!PluginUtil.isPluginLoaded(args[0])) + terminal.info("依存関係ツリーを読み込み中..."); + + PluginMetaProvider provider = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider(); + + if (provider.isPluginMetaExists(args[0])) { terminal.error("プラグインが見つかりませんでした。"); return; } - terminal.info("依存関係ツリーを読み込み中..."); - - PluginMeta meta = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().getPluginMeta( + PluginMeta meta = provider.getPluginMeta( args[0], true ); From 64a2fee19fbbea619486d79df56fe1597089c4cb Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 00:10:19 +0900 Subject: [PATCH 325/745] feat: Meta on --- .../commands/CommandInfo.java | 4 +-- .../deptree/CommandMarkAsDependency.java | 2 +- .../debug/deptree/CommandRelation.java | 4 +-- .../plugin/meta/PluginMeta.java | 5 +++ .../plugin/meta/PluginMetaProvider.java | 34 ++++++++++++++++--- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index 1fda6fd0..b0ff44c6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -102,7 +102,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, } PluginMeta meta = provider.getPluginMeta( - args[0], true + args[0], true, true ); terminal.info("情報を読み込み中..."); @@ -117,7 +117,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, File file = PluginUtil.getFile(plugin); terminal.writeLine(Messages.keyValue("名前", meta.getName())); - terminal.writeLine(Messages.keyValue("作成者", String.join(", ", plugin.getDescription().getAuthors()))); + terminal.writeLine(Messages.keyValue("作成者", String.join(", ", meta.getAuthors()))); terminal.writeLine(Messages.keyValue("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); terminal.writeLine(Messages.keyValue("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); terminal.writeLine(Messages.keyValueYesNo( diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java index b7224835..03fcb988 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java @@ -36,7 +36,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (args.length < 2) { - boolean isDependency = provider.getPluginMeta(pluginName, false).isDependency(); + boolean isDependency = provider.getPluginMeta(pluginName, false, false).isDependency(); terminal.success("Plugin " + pluginName + " is " + (isDependency ? "dependency": "not dependency")); return; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java index 7c4f7105..18c9f8a2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java @@ -40,7 +40,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (args.length < 2) { - List dependencies = provider.getPluginMeta(pluginName, false).getDependsOn(); + List dependencies = provider.getPluginMeta(pluginName, false, false).getDependsOn(); terminal.success("Plugin " + pluginName + " depends on " + dependencies.stream() .map(DependencyNode::getDependsOn) @@ -56,7 +56,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } - PluginMeta meta = provider.getPluginMeta(pluginName, true); + PluginMeta meta = provider.getPluginMeta(pluginName, true, false); if (args.length < 3) { List dependencies = meta.getDependsOn(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java index 591776bf..abced700 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMeta.java @@ -48,6 +48,11 @@ public class PluginMeta * プラグインがいつインストールされたかを表します。 */ long installedAt; + /** + * プラグインの作者のリストです。 + */ + @NotNull + List authors; /** * 依存されているプラグインのリストです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index d39b3825..4a1fddc3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -375,6 +375,7 @@ private static List getStringDependsOn(List nodes, Depen .collect(Collectors.toList()); } + @SuppressWarnings("SqlResolve") private static void deleteAndSaveDepends(Connection connection, String tableName, String fieldName, String name, List depends) throws SQLException { @@ -396,19 +397,28 @@ private void savePluginRelationalData(Connection connection, PluginMeta meta) th { String name = meta.getName(); String version = meta.getVersion(); - // TODO: List authors = meta.getAuthors(); String loadTiming = meta.getLoadTiming().name(); - + List authors = meta.getAuthors(); List dependsOn = meta.getDependsOn(); List dependencies = getStringDependsOn(dependsOn, DependType.HARD_DEPEND); List softDependencies = getStringDependsOn(dependsOn, DependType.SOFT_DEPEND); List loadBefore = getStringDependsOn(dependsOn, DependType.LOAD_BEFORE); + PreparedStatement statement = + connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); + statement.setString(1, name); + + for (String author : authors) + { + statement.setString(2, author); + statement.execute(); + } + deleteAndSaveDepends(connection, "depend", "dependency", name, dependencies); deleteAndSaveDepends(connection, "soft_depend", "soft_dependency", name, softDependencies); deleteAndSaveDepends(connection, "load_before", "load_before", name, loadBefore); - PreparedStatement statement = connection.prepareStatement("UPDATE plugin_meta SET version = ?, load_timing = ? WHERE name = ?"); + statement = connection.prepareStatement("UPDATE plugin_meta SET version = ?, load_timing = ? WHERE name = ?"); statement.setString(1, version); statement.setString(2, loadTiming); statement.setString(3, name); @@ -643,7 +653,7 @@ private void removePluginRelationalData(Connection connection, String pluginName * @param includeDependencies 依存関係を含めるかどうか * @return プラグインのメタデータ */ - public @NotNull PluginMeta getPluginMeta(@NotNull String pluginName, boolean includeDependencies) + public @NotNull PluginMeta getPluginMeta(@NotNull String pluginName, boolean includeDependencies, boolean includeAuthors) { try (Connection con = this.db.getConnection()) { @@ -678,6 +688,10 @@ private void removePluginRelationalData(Connection connection, String pluginName dependsOn.addAll(this.getLoadBefore(pluginName)); } + List authors = new ArrayList<>(); + if (includeAuthors) + authors = this.getAuthors(pluginName); + return new PluginMeta( name, version, @@ -686,6 +700,7 @@ private void removePluginRelationalData(Connection connection, String pluginName isDependency, resolveQuery, installedAt, + authors, dependedBy, dependsOn ); @@ -696,6 +711,17 @@ private void removePluginRelationalData(Connection connection, String pluginName } } + /** + * プラグインのメタデータを取得します。 + * + * @param pluginName プラグインの名前 + * @return プラグインのメタデータ + */ + public @NotNull PluginMeta getPluginMeta(@NotNull String pluginName) + { + return this.getPluginMeta(pluginName, true, true); + } + /** * 依存関係ツリーを保存します。 * From 1917eb8f1a69fb1323078ab8b64f972107d92fb8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 01:27:29 +0900 Subject: [PATCH 326/745] feat: Transaction Helper --- .../plugin/meta/MetaSQLUtil.java | 64 ++ .../plugin/meta/PluginMetaProvider.java | 573 ++++------------- .../utils/Transaction.java | 585 ++++++++++++++++++ 3 files changed, 774 insertions(+), 448 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/MetaSQLUtil.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/MetaSQLUtil.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/MetaSQLUtil.java new file mode 100644 index 00000000..278a3527 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/MetaSQLUtil.java @@ -0,0 +1,64 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.meta; + +import com.zaxxer.hikari.HikariDataSource; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +class MetaSQLUtil +{ + static List getStringDependsOn(List nodes, DependType type) + { + return nodes.stream().parallel() + .filter(node -> node.getDependType() == type) + .map(DependencyNode::getDependsOn) + .collect(Collectors.toList()); + } + + @SuppressWarnings("SqlResolve") + static void deleteAndSaveDepends(Connection connection, String tableName, String fieldName, String name, + List depends) throws SQLException + { + PreparedStatement statement = connection.prepareStatement("DELETE FROM " + tableName + " WHERE name = ?"); + statement.setString(1, name); + statement.executeUpdate(); + + statement = connection.prepareStatement("INSERT INTO " + tableName + "(name, " + fieldName + ") VALUES(?, ?)"); + statement.setString(1, name); + + for (String depend : depends) + { + statement.setString(2, depend); + statement.executeUpdate(); + } + } + + @SuppressWarnings("SqlResolve") + static List getListFromTable(HikariDataSource source, String tableName, String name, String queryField, String field) + { + List result = new ArrayList<>(); + + try (Connection con = source.getConnection()) + { + PreparedStatement statement = + con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + queryField + " = ?"); + statement.setString(1, name); + + ResultSet resultSet = statement.executeQuery(); + + while (resultSet.next()) + result.add(resultSet.getString(field)); + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + + return result; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 4a1fddc3..793058b8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -3,6 +3,7 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; @@ -136,7 +137,7 @@ public List getLoadBeforeBy(@NotNull String pluginName) */ public List getAuthors(@NotNull String pluginName) { - return getListFromTable("plugin_author", pluginName, "name", "author"); + return MetaSQLUtil.getListFromTable(this.db, "plugin_author", pluginName, "name", "author"); } /** @@ -147,7 +148,7 @@ public List getAuthors(@NotNull String pluginName) */ public List getPluginsByAuthor(@NotNull String author) { - return getListFromTable("plugin_author", author, "author", "name"); + return MetaSQLUtil.getListFromTable(this.db, "plugin_author", author, "author", "name"); } /** @@ -212,47 +213,11 @@ public boolean isDependency(@NotNull String pluginName) */ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) { - Connection con = null; - try - { - con = this.db.getConnection(); - PreparedStatement statement = con.prepareStatement("UPDATE plugin_meta SET is_dependency = ? WHERE name = ?"); - statement.setInt(1, isDependency ? 1: 0); - statement.setString(2, pluginName); - - statement.executeUpdate(); - - con.commit(); - - } - catch (SQLException e) - { - try - { - if (con != null) - con.rollback(); - } - catch (SQLException e1) - { - System.out.println("Failed to rollback"); - e1.printStackTrace(); - } + Transaction.create(this.db, "UPDATE plugin_meta SET is_dependency = ? WHERE name = ?") + .setInteger(1, isDependency ? 1: 0) + .setString(2, pluginName) + .executeUpdate(); - throw new IllegalStateException(e); - } - finally - { - try - { - if (con != null) - con.close(); - } - catch (SQLException e) - { - System.out.println("Failed to close connection"); - e.printStackTrace(); - } - } } /** @@ -263,56 +228,16 @@ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) */ public void updateResolveQuery(@NotNull String pluginName, @NotNull String query) { - Connection con = null; - try - { - con = this.db.getConnection(); - // Check if the plugin exists - PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); - statement.setString(1, pluginName); - - if (!statement.executeQuery().next()) - { - con.rollback(); - throw new IllegalArgumentException("Plugin does not exist"); - } + Transaction transaction = Transaction.create(this.db, "SELECT * FROM plugin_meta WHERE name = ?") + .setString(1, pluginName); - statement = con.prepareStatement("UPDATE plugin_meta SET resolve_query = ? WHERE name = ?"); - statement.setString(1, query); - statement.setString(2, pluginName); - - statement.executeUpdate(); - - con.commit(); - } - catch (SQLException e) - { - try - { - if (con != null) - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } + if (!transaction.isExists()) + return; - throw new IllegalStateException(e); - } - finally - { - try - { - if (con != null) - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } + transaction.renew("UPDATE plugin_meta SET resolve_query = ? WHERE name = ?") + .setString(1, query) + .setString(2, pluginName) + .executeUpdate(); } private void savePluginRelationalData(Connection connection, Plugin plugin) throws SQLException @@ -367,32 +292,6 @@ private void savePluginRelationalData(Connection connection, Plugin plugin) thro } - private static List getStringDependsOn(List nodes, DependType type) - { - return nodes.stream().parallel() - .filter(node -> node.getDependType() == type) - .map(DependencyNode::getDependsOn) - .collect(Collectors.toList()); - } - - @SuppressWarnings("SqlResolve") - private static void deleteAndSaveDepends(Connection connection, String tableName, String fieldName, String name, - List depends) throws SQLException - { - PreparedStatement statement = connection.prepareStatement("DELETE FROM " + tableName + " WHERE name = ?"); - statement.setString(1, name); - statement.executeUpdate(); - - statement = connection.prepareStatement("INSERT INTO " + tableName + "(name, " + fieldName + ") VALUES(?, ?)"); - statement.setString(1, name); - - for (String depend : depends) - { - statement.setString(2, depend); - statement.executeUpdate(); - } - } - private void savePluginRelationalData(Connection connection, PluginMeta meta) throws SQLException { String name = meta.getName(); @@ -400,29 +299,29 @@ private void savePluginRelationalData(Connection connection, PluginMeta meta) th String loadTiming = meta.getLoadTiming().name(); List authors = meta.getAuthors(); List dependsOn = meta.getDependsOn(); - List dependencies = getStringDependsOn(dependsOn, DependType.HARD_DEPEND); - List softDependencies = getStringDependsOn(dependsOn, DependType.SOFT_DEPEND); - List loadBefore = getStringDependsOn(dependsOn, DependType.LOAD_BEFORE); + List dependencies = MetaSQLUtil.getStringDependsOn(dependsOn, DependType.HARD_DEPEND); + List softDependencies = MetaSQLUtil.getStringDependsOn(dependsOn, DependType.SOFT_DEPEND); + List loadBefore = MetaSQLUtil.getStringDependsOn(dependsOn, DependType.LOAD_BEFORE); - PreparedStatement statement = - connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); - statement.setString(1, name); + Transaction transaction = + Transaction.create(connection, "INSERT INTO plugin_author(name, author) VALUES(?, ?)") + .setString(1, name); for (String author : authors) { - statement.setString(2, author); - statement.execute(); + transaction.setString(2, author); + transaction.executeUpdate(false); } - deleteAndSaveDepends(connection, "depend", "dependency", name, dependencies); - deleteAndSaveDepends(connection, "soft_depend", "soft_dependency", name, softDependencies); - deleteAndSaveDepends(connection, "load_before", "load_before", name, loadBefore); + MetaSQLUtil.deleteAndSaveDepends(connection, "depend", "dependency", name, dependencies); + MetaSQLUtil.deleteAndSaveDepends(connection, "soft_depend", "soft_dependency", name, softDependencies); + MetaSQLUtil.deleteAndSaveDepends(connection, "load_before", "load_before", name, loadBefore); - statement = connection.prepareStatement("UPDATE plugin_meta SET version = ?, load_timing = ? WHERE name = ?"); - statement.setString(1, version); - statement.setString(2, loadTiming); - statement.setString(3, name); - statement.executeUpdate(); + Transaction.create(connection, "UPDATE plugin_meta SET version = ?, load_timing = ? WHERE name = ?") + .setString(1, version) + .setString(2, loadTiming) + .setString(3, name) + .executeUpdate(); } /** @@ -433,17 +332,9 @@ private void savePluginRelationalData(Connection connection, PluginMeta meta) th */ public boolean isPluginMetaExists(@NotNull String pluginName) { - try (Connection con = this.db.getConnection()) - { - PreparedStatement statement = con.prepareStatement("SELECT * FROM plugin_meta WHERE name = ?"); - statement.setString(1, pluginName); - - return statement.executeQuery().next(); - } - catch (SQLException e) - { - throw new IllegalStateException(e); - } + return Transaction.create(this.db, "SELECT * FROM plugin_meta WHERE name = ?") + .setString(1, pluginName) + .isExists(); } /** @@ -463,111 +354,37 @@ public void savePluginMeta(@NotNull Plugin plugin, { - Connection con = null; - try - { - con = this.db.getConnection(); - - PreparedStatement statement = - con.prepareStatement("INSERT INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)"); - - PluginDescriptionFile description = plugin.getDescription(); - - statement.setString(1, description.getName()); - statement.setString(2, description.getVersion()); - statement.setString(3, description.getLoad().name()); - statement.setLong(4, installedAt); - statement.setString(5, installedBy.name()); - statement.setString(6, resolveQuery); - statement.setInt(7, isDependency ? 1: 0); - - statement.executeUpdate(); - - this.savePluginRelationalData(con, plugin); - - con.commit(); - } - catch (SQLException e) - { - try - { - if (con != null) - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } - - throw new IllegalStateException(e); - } - finally - { - try - { - if (con != null) - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } + PluginDescriptionFile description = plugin.getDescription(); + Transaction.create( + this.db, + "INSERT INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)" + ) + .setString(1, description.getName()) + .setString(2, description.getVersion()) + .setString(3, description.getLoad().name()) + .setLong(4, installedAt) + .setString(5, installedBy.name()) + .setString(6, resolveQuery) + .setInteger(7, isDependency ? 1: 0) + .beforeCommit(tr -> this.savePluginRelationalData(tr.getConnection(), plugin)) + .executeUpdate(); } public void savePluginMeta(@NotNull PluginMeta meta) { - Connection con = null; - try - { - con = this.db.getConnection(); - - PreparedStatement statement = - con.prepareStatement("INSERT OR REPLACE INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)"); - statement.setString(1, meta.getName()); - statement.setString(2, meta.getVersion()); - statement.setString(3, meta.getLoadTiming().name()); - statement.setLong(4, meta.getInstalledAt()); - statement.setString(5, meta.getInstalledBy().name()); - statement.setString(6, meta.getResolveQuery()); - statement.setInt(7, meta.isDependency() ? 1: 0); - - statement.executeUpdate(); - - this.savePluginRelationalData(con, meta); - - con.commit(); - } - catch (SQLException e) - { - try - { - if (con != null) - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } - - throw new IllegalStateException(e); - } - finally - { - try - { - if (con != null) - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } + Transaction.create( + this.db, + "INSERT OR REPLACE INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)" + ) + .setString(1, meta.getName()) + .setString(2, meta.getVersion()) + .setString(3, meta.getLoadTiming().name()) + .setLong(4, meta.getInstalledAt()) + .setString(5, meta.getInstalledBy().name()) + .setString(6, meta.getResolveQuery()) + .setInteger(7, meta.isDependency() ? 1: 0) + .beforeCommit(tr -> this.savePluginRelationalData(tr.getConnection(), meta)) + .executeUpdate(); } /** @@ -577,49 +394,9 @@ public void savePluginMeta(@NotNull PluginMeta meta) */ public void removePluginMeta(@NotNull String pluginName) { - Connection con = null; - try - { - con = this.db.getConnection(); - - this.removePluginRelationalData(con, pluginName); - - PreparedStatement statement = - con.prepareStatement("DELETE FROM plugin_meta WHERE name = ?"); - statement.setString(1, pluginName); - - statement.executeUpdate(); - - con.commit(); - } - catch (SQLException e) - { - try - { - if (con != null) - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } - - throw new IllegalStateException(e); - } - finally - { - try - { - if (con != null) - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } + Transaction.create(this.db, "DELETE FROM plugin_meta WHERE name = ?") + .setString(1, pluginName) + .executeUpdate(); } private void removePluginRelationalData(Connection connection, String pluginName) throws SQLException @@ -729,52 +506,21 @@ private void removePluginRelationalData(Connection connection, String pluginName */ public void saveDependencyTree(@NotNull List dependencyNodes) { - Connection con = null; - try - { - con = this.db.getConnection(); - - PreparedStatement statement = - con.prepareStatement("INSERT INTO dependency_tree(name, parent, depend_type) VALUES(?, ?, ?)"); - - for (DependencyNode node : dependencyNodes) - { - statement.setString(1, node.getPlugin()); - statement.setString(2, node.getDependsOn()); - statement.setString(3, node.getDependType().name()); - statement.execute(); - } - - con.commit(); - } - catch (SQLException e) - { - try - { - if (con != null) - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } + Transaction transaction = Transaction.create( + this.db, + "INSERT INTO dependency_tree(name, parent, depend_type) VALUES(?, ?, ?)" + ); - throw new IllegalStateException(e); - } - finally + for (DependencyNode node : dependencyNodes) { - try - { - if (con != null) - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } + transaction + .setString(1, node.getPlugin()) + .setString(2, node.getDependsOn()) + .setString(3, node.getDependType().name()) + .executeUpdate(false); } + + transaction.finishManually(); } /** @@ -811,47 +557,9 @@ public void buildDependencyTree(@NotNull String pluginName) */ public void deleteFromDependencyTree(@NotNull String pluginName) { - Connection con = null; - try - { - con = this.db.getConnection(); - - PreparedStatement statement = - con.prepareStatement("DELETE FROM dependency_tree WHERE name = ?"); - statement.setString(1, pluginName); - statement.execute(); - - con.commit(); - } - catch (SQLException e) - { - try - { - if (con != null) - con.rollback(); - } - catch (SQLException ex) - { - System.err.println("Failed to rollback transaction"); - ex.printStackTrace(); - } - - throw new IllegalStateException(e); - } - finally - { - try - { - - if (con != null) - con.close(); - } - catch (SQLException e) - { - System.err.println("Failed to close connection"); - e.printStackTrace(); - } - } + Transaction.create(this.db, "DELETE FROM dependency_tree WHERE name = ?") + .setString(1, pluginName) + .executeUpdate(); } /** @@ -965,57 +673,51 @@ private boolean isNotDependencyInternal(Connection con, PreparedStatement stmt, private void initializeTables() { - try (Connection con = this.db.getConnection()) - { - Statement statement = con.createStatement(); - - statement.execute("CREATE TABLE IF NOT EXISTS plugin_meta(" + - "name TEXT NOT NULL PRIMARY KEY," + - "version TEXT NOT NULL," + - "load_timing TEXT NOT NULL," + - "installed_at INTEGER NOT NULL," + - "installed_by TEXT NOT NULL," + - "resolve_query TEXT," + - "is_dependency INTEGER(1) NOT NULL" + - ")" - ); - - statement.execute("CREATE TABLE IF NOT EXISTS plugin_author(" + - "name TEXT NOT NULL UNIQUE," + - "author TEXT NOT NULL" + - ")" - ); - - statement.execute("CREATE TABLE IF NOT EXISTS depend(" + - "name TEXT NOT NULL," + - "dependency TEXT" + - ")" - ); - statement.execute("CREATE TABLE IF NOT EXISTS soft_depend(" + - "name TEXT NOT NULL," + - "soft_dependency TEXT" + - ")" - ); - statement.execute("CREATE TABLE IF NOT EXISTS load_before(" + - "name TEXT NOT NULL," + - "load_before TEXT" + - ")" - ); - - statement.execute("CREATE TABLE IF NOT EXISTS dependency_tree(" + - "name TEXT NOT NULL," + - "parent TEXT," + - "depend_type TEXT," + - "PRIMARY KEY (name, parent)" + - ")" - ); - - con.commit(); - } - catch (SQLException e) - { - throw new IllegalStateException(e); - } + Transaction.create(this.db) + .doTransaction((tr) -> { + Statement statement = tr.getConnection().createStatement(); + + statement.execute("CREATE TABLE IF NOT EXISTS plugin_meta(" + + "name TEXT NOT NULL PRIMARY KEY," + + "version TEXT NOT NULL," + + "load_timing TEXT NOT NULL," + + "installed_at INTEGER NOT NULL," + + "installed_by TEXT NOT NULL," + + "resolve_query TEXT," + + "is_dependency INTEGER(1) NOT NULL" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS plugin_author(" + + "name TEXT NOT NULL UNIQUE," + + "author TEXT NOT NULL" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS depend(" + + "name TEXT NOT NULL," + + "dependency TEXT" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS soft_depend(" + + "name TEXT NOT NULL," + + "soft_dependency TEXT" + + ")" + ); + statement.execute("CREATE TABLE IF NOT EXISTS load_before(" + + "name TEXT NOT NULL," + + "load_before TEXT" + + ")" + ); + + statement.execute("CREATE TABLE IF NOT EXISTS dependency_tree(" + + "name TEXT NOT NULL," + + "parent TEXT," + + "depend_type TEXT," + + "PRIMARY KEY (name, parent)" + + ")" + ); + }); } private HikariDataSource createConnection(@NotNull Path databasePath) @@ -1034,7 +736,7 @@ private HikariDataSource createConnection(@NotNull Path databasePath) private List getDependDataFromTable(String tableName, String name, String field, DependType type, boolean baseReversed) { - List depString = this.getListFromTable(tableName, name, baseReversed ? field: "name", baseReversed ? "name": field); + List depString = MetaSQLUtil.getListFromTable(this.db, tableName, name, baseReversed ? field: "name", baseReversed ? "name": field); if (baseReversed) return depString.stream() @@ -1046,29 +748,4 @@ private List getDependDataFromTable(String tableName, String nam .collect(Collectors.toList()); } - - @SuppressWarnings("SqlResolve") - private List getListFromTable(String tableName, String name, String queryField, String field) - { - List depends = new ArrayList<>(); - - try (Connection con = this.db.getConnection()) - { - PreparedStatement statement = - con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + queryField + " = ?"); - statement.setString(1, name); - - ResultSet resultSet = statement.executeQuery(); - - while (resultSet.next()) - depends.add(resultSet.getString(field)); - } - catch (SQLException e) - { - throw new IllegalStateException(e); - } - - return depends; - } - } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java new file mode 100644 index 00000000..92aa93c1 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java @@ -0,0 +1,585 @@ +package net.kunmc.lab.teamkunpluginmanager.utils; + +import com.zaxxer.hikari.HikariDataSource; +import lombok.Getter; +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * DBのトランザクションを簡単に行うためのクラスです。 + */ +public class Transaction +{ + /** + * Dbのコネクションです。 + */ + @Getter + private final Connection connection; + + @Nullable + private final PreparedStatement preparedStatement; + + private TransactionRun beforeCommit; + + private Transaction(Connection connection, String query) throws SQLException + { + this.connection = connection; + this.connection.setAutoCommit(false); + + if (query != null) + this.preparedStatement = this.connection.prepareStatement(query); + else + this.preparedStatement = null; + } + + /** + * トランザクションを開始します。 + * + * @param dataSource データソース + * @param sql SQL文 + * @return トランザクション + */ + public static Transaction create(@NotNull HikariDataSource dataSource, @Nullable @Language("sql") String sql) + { + try + { + return new Transaction(dataSource.getConnection(), sql); + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * トランザクションを開始します。 + * + * @param connection コネクション + * @param sql SQL文 + * @return トランザクション + */ + public static Transaction create(@NotNull Connection connection, @Nullable @Language("sql") String sql) + { + try + { + return new Transaction(connection, sql); + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * トランザクションを開始します。 + * + * @param transaction 既存のトランザクション + * @param sql SQL文 + * @return トランザクション + */ + public static Transaction create(@NotNull Transaction transaction, @Nullable @Language("sql") String sql) + { + try + { + return new Transaction(transaction.getConnection(), sql); + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * トランザクションを開始します。 + * + * @param dataSource データソース + * @return トランザクション + */ + public static Transaction create(@NotNull HikariDataSource dataSource) + { + return create(dataSource, null); + } + + /** + * トランザクションを再生成します。 + * + * @param newQuery 新しいSQL文 + * @return トランザクション + */ + public Transaction renew(@Language("sql") @NotNull String newQuery) + { + return create(this, newQuery); + } + + /** + * コミット前に実行する処理を登録します。 + * + * @param beforeCommit コミット前に実行する処理 + * @return トランザクション + */ + public Transaction beforeCommit(TransactionRun beforeCommit) + { + this.beforeCommit = beforeCommit; + return this; + } + + private boolean checkPrepareCondition() + { + return this.preparedStatement != null; + } + + /** + * SQL文に文字列値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setString(int index, @Nullable String value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setString(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + + } + + /** + * SQL文に32ビット整数値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setInteger(int index, int value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setInt(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文に真偽値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setBoolean(int index, boolean value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setBoolean(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文に64ビット整数値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setLong(int index, long value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setLong(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文に64ビット浮動小数点数値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setDouble(int index, double value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setDouble(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文に32ビット浮動小数点数値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setFloat(int index, float value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setFloat(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文にバイナリ値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setByte(int index, byte value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setByte(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文に16ビット整数値をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setShort(int index, short value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setShort(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文にバイト配列をセットします。 + * + * @param index インデックス + * @param value 値 + * @return トランザクション + */ + public Transaction setBytes(int index, byte[] value) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setBytes(index, value); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * SQL文にNULL値をセットします。 + * + * @param index インデックス + * @param type 型 + * @return トランザクション + */ + public Transaction setNull(int index, int type) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + this.preparedStatement.setNull(index, type); + return this; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * 更新系SQL文を実行します。 + * + * @param autoFinish 自動終了するかどうか + * @return 更新件数 + */ + public int executeUpdate(boolean autoFinish) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + int result = this.preparedStatement.executeUpdate(); + + if (autoFinish) + { + if (this.beforeCommit != null) + this.beforeCommit.run(this); + + this.connection.commit(); + } + + return result; + } + catch (SQLException e) + { + try + { + this.connection.rollback(); + } + catch (SQLException e1) + { + throw new IllegalStateException(e1); + } + + throw new IllegalStateException(e); + } + finally + { + + if (autoFinish) + try + { + this.connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + /** + * 更新系SQL文を実行します。 + * + * @return 更新件数 + */ + public int executeUpdate() + { + return executeUpdate(true); + } + + /** + * クエリ系SQL文を実行します。 + * + * @param resultRun 結果を処理する関数 + */ + public void executeQuery(QueryResultConsumer resultRun) + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + this.doTransaction((con) -> { + ResultSet resultSet = this.preparedStatement.executeQuery(); + + resultRun.accept(resultSet); + + resultSet.close(); + }); + } + + /** + * トランザクションを実行し、コミットします。 + * + * @param transactionRun トランザクションを処理する関数 + */ + public void doTransaction(TransactionRun transactionRun) + { + try + { + transactionRun.run(this); + + if (this.beforeCommit != null) + this.beforeCommit.run(this); + this.connection.commit(); + } + catch (SQLException e) + { + try + { + this.connection.rollback(); + } + catch (SQLException e1) + { + throw new IllegalStateException(e1); + } + + throw new IllegalStateException(e); + } + finally + { + try + { + this.connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + /** + * 手動でトランザクションをコミットし終了します。 + */ + public void finishManually() + { + try + { + if (this.beforeCommit != null) + this.beforeCommit.run(this); + this.connection.commit(); + } + catch (SQLException e) + { + try + { + this.connection.rollback(); + } + catch (SQLException e1) + { + throw new IllegalStateException(e1); + } + + throw new IllegalStateException(e); + } + + try + { + this.connection.close(); + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * 手動でトランザクションをロールバックし終了します。 + */ + public void abortManually() + { + try + { + this.connection.rollback(); + this.connection.close(); + } + catch (SQLException e1) + { + throw new IllegalStateException(e1); + } + } + + /** + * DBにレコードが存在するかどうかを確認します。 + * + * @return 存在するかどうか + */ + public boolean isExists() + { + if (!checkPrepareCondition()) + throw new IllegalStateException("This TransactionHelper is not prepared."); + + try + { + ResultSet resultSet = this.preparedStatement.executeQuery(); + + boolean result = resultSet.next(); + + resultSet.close(); + + return result; + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * クエリ更新系SQL文を実行した時に、結果を処理する関数です。 + */ + @FunctionalInterface + public interface QueryResultConsumer + { + void accept(ResultSet result) throws SQLException; + } + + /** + * トランザクションを実行する汎用関数です。 + */ + @FunctionalInterface + public interface TransactionRun + { + void run(Transaction transaction) throws SQLException; + } +} From 607e3439ee7c84879386cdfa2d0a96ff525be0af Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 01:31:04 +0900 Subject: [PATCH 327/745] refactor: Unity set methods of Transaction --- .../plugin/meta/PluginMetaProvider.java | 60 +++++++++---------- .../utils/Transaction.java | 18 +++--- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 793058b8..d6ceb628 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -214,8 +214,8 @@ public boolean isDependency(@NotNull String pluginName) public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) { Transaction.create(this.db, "UPDATE plugin_meta SET is_dependency = ? WHERE name = ?") - .setInteger(1, isDependency ? 1: 0) - .setString(2, pluginName) + .set(1, isDependency ? 1: 0) + .set(2, pluginName) .executeUpdate(); } @@ -229,14 +229,14 @@ public void setDependencyFlag(@NotNull String pluginName, boolean isDependency) public void updateResolveQuery(@NotNull String pluginName, @NotNull String query) { Transaction transaction = Transaction.create(this.db, "SELECT * FROM plugin_meta WHERE name = ?") - .setString(1, pluginName); + .set(1, pluginName); if (!transaction.isExists()) return; transaction.renew("UPDATE plugin_meta SET resolve_query = ? WHERE name = ?") - .setString(1, query) - .setString(2, pluginName) + .set(1, query) + .set(2, pluginName) .executeUpdate(); } @@ -305,11 +305,11 @@ private void savePluginRelationalData(Connection connection, PluginMeta meta) th Transaction transaction = Transaction.create(connection, "INSERT INTO plugin_author(name, author) VALUES(?, ?)") - .setString(1, name); + .set(1, name); for (String author : authors) { - transaction.setString(2, author); + transaction.set(2, author); transaction.executeUpdate(false); } @@ -318,9 +318,9 @@ private void savePluginRelationalData(Connection connection, PluginMeta meta) th MetaSQLUtil.deleteAndSaveDepends(connection, "load_before", "load_before", name, loadBefore); Transaction.create(connection, "UPDATE plugin_meta SET version = ?, load_timing = ? WHERE name = ?") - .setString(1, version) - .setString(2, loadTiming) - .setString(3, name) + .set(1, version) + .set(2, loadTiming) + .set(3, name) .executeUpdate(); } @@ -333,7 +333,7 @@ private void savePluginRelationalData(Connection connection, PluginMeta meta) th public boolean isPluginMetaExists(@NotNull String pluginName) { return Transaction.create(this.db, "SELECT * FROM plugin_meta WHERE name = ?") - .setString(1, pluginName) + .set(1, pluginName) .isExists(); } @@ -359,13 +359,13 @@ public void savePluginMeta(@NotNull Plugin plugin, this.db, "INSERT INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)" ) - .setString(1, description.getName()) - .setString(2, description.getVersion()) - .setString(3, description.getLoad().name()) - .setLong(4, installedAt) - .setString(5, installedBy.name()) - .setString(6, resolveQuery) - .setInteger(7, isDependency ? 1: 0) + .set(1, description.getName()) + .set(2, description.getVersion()) + .set(3, description.getLoad().name()) + .set(4, installedAt) + .set(5, installedBy.name()) + .set(6, resolveQuery) + .set(7, isDependency ? 1: 0) .beforeCommit(tr -> this.savePluginRelationalData(tr.getConnection(), plugin)) .executeUpdate(); } @@ -376,13 +376,13 @@ public void savePluginMeta(@NotNull PluginMeta meta) this.db, "INSERT OR REPLACE INTO plugin_meta(name, version, load_timing, installed_at, installed_by, resolve_query, is_dependency) VALUES(?, ?, ?, ?, ?, ?, ?)" ) - .setString(1, meta.getName()) - .setString(2, meta.getVersion()) - .setString(3, meta.getLoadTiming().name()) - .setLong(4, meta.getInstalledAt()) - .setString(5, meta.getInstalledBy().name()) - .setString(6, meta.getResolveQuery()) - .setInteger(7, meta.isDependency() ? 1: 0) + .set(1, meta.getName()) + .set(2, meta.getVersion()) + .set(3, meta.getLoadTiming().name()) + .set(4, meta.getInstalledAt()) + .set(5, meta.getInstalledBy().name()) + .set(6, meta.getResolveQuery()) + .set(7, meta.isDependency() ? 1: 0) .beforeCommit(tr -> this.savePluginRelationalData(tr.getConnection(), meta)) .executeUpdate(); } @@ -395,7 +395,7 @@ public void savePluginMeta(@NotNull PluginMeta meta) public void removePluginMeta(@NotNull String pluginName) { Transaction.create(this.db, "DELETE FROM plugin_meta WHERE name = ?") - .setString(1, pluginName) + .set(1, pluginName) .executeUpdate(); } @@ -514,9 +514,9 @@ public void saveDependencyTree(@NotNull List dependencyNodes) for (DependencyNode node : dependencyNodes) { transaction - .setString(1, node.getPlugin()) - .setString(2, node.getDependsOn()) - .setString(3, node.getDependType().name()) + .set(1, node.getPlugin()) + .set(2, node.getDependsOn()) + .set(3, node.getDependType().name()) .executeUpdate(false); } @@ -558,7 +558,7 @@ public void buildDependencyTree(@NotNull String pluginName) public void deleteFromDependencyTree(@NotNull String pluginName) { Transaction.create(this.db, "DELETE FROM dependency_tree WHERE name = ?") - .setString(1, pluginName) + .set(1, pluginName) .executeUpdate(); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java index 92aa93c1..85d4b8e0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java @@ -141,7 +141,7 @@ private boolean checkPrepareCondition() * @param value 値 * @return トランザクション */ - public Transaction setString(int index, @Nullable String value) + public Transaction set(int index, @Nullable String value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -165,7 +165,7 @@ public Transaction setString(int index, @Nullable String value) * @param value 値 * @return トランザクション */ - public Transaction setInteger(int index, int value) + public Transaction set(int index, int value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -188,7 +188,7 @@ public Transaction setInteger(int index, int value) * @param value 値 * @return トランザクション */ - public Transaction setBoolean(int index, boolean value) + public Transaction set(int index, boolean value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -211,7 +211,7 @@ public Transaction setBoolean(int index, boolean value) * @param value 値 * @return トランザクション */ - public Transaction setLong(int index, long value) + public Transaction set(int index, long value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -234,7 +234,7 @@ public Transaction setLong(int index, long value) * @param value 値 * @return トランザクション */ - public Transaction setDouble(int index, double value) + public Transaction set(int index, double value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -257,7 +257,7 @@ public Transaction setDouble(int index, double value) * @param value 値 * @return トランザクション */ - public Transaction setFloat(int index, float value) + public Transaction set(int index, float value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -280,7 +280,7 @@ public Transaction setFloat(int index, float value) * @param value 値 * @return トランザクション */ - public Transaction setByte(int index, byte value) + public Transaction set(int index, byte value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -303,7 +303,7 @@ public Transaction setByte(int index, byte value) * @param value 値 * @return トランザクション */ - public Transaction setShort(int index, short value) + public Transaction set(int index, short value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -326,7 +326,7 @@ public Transaction setShort(int index, short value) * @param value 値 * @return トランザクション */ - public Transaction setBytes(int index, byte[] value) + public Transaction set(int index, byte[] value) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); From 4da40670a3a0ac928454eae93945a316d6b5e565 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 12:58:04 +0900 Subject: [PATCH 328/745] fix: Plugin not found error not occurrs --- .../kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index b0ff44c6..3f4a7d54 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -95,7 +95,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, PluginMetaProvider provider = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider(); - if (provider.isPluginMetaExists(args[0])) + if (!provider.isPluginMetaExists(args[0])) { terminal.error("プラグインが見つかりませんでした。"); return; From b10c75af9204738edacbb040277c330dc482897d Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 12:58:32 +0900 Subject: [PATCH 329/745] fix: SQLite Connection leak --- .../plugin/meta/PluginMetaProvider.java | 2 +- .../lab/teamkunpluginmanager/utils/Transaction.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index d6ceb628..312067f5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -321,7 +321,7 @@ private void savePluginRelationalData(Connection connection, PluginMeta meta) th .set(1, version) .set(2, loadTiming) .set(3, name) - .executeUpdate(); + .executeUpdate(false); } /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java index 85d4b8e0..514485f5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java @@ -563,6 +563,17 @@ public boolean isExists() { throw new IllegalStateException(e); } + finally + { + try + { + this.connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } } /** From 33d5bd43a1695efa81fab3e9625d73a399250533 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 13:17:32 +0900 Subject: [PATCH 330/745] feat: InstallOperator#UNKNOWN --- .../teamkunpluginmanager/plugin/meta/InstallOperator.java | 6 +++++- .../teamkunpluginmanager/plugin/meta/PluginMetaManager.java | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java index 89c36335..277fc613 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/InstallOperator.java @@ -20,5 +20,9 @@ public enum InstallOperator /** * その他の方法でインストールされたことを表します。 */ - OTHER + OTHER, + /** + * 未知の方法でインストールされたことを表します。 + */ + UNKNOWN } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java index 92aa3527..dbec313a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaManager.java @@ -75,7 +75,7 @@ public void onPluginEnable(PluginEnableEvent event) System.out.println("プラグインの追加が検出されました: " + pluginNameFull); System.out.println("プラグインのメタデータを作成してします ..."); - this.onInstalled(plugin, InstallOperator.SERVER_ADMIN, null, false); + this.onInstalled(plugin, InstallOperator.UNKNOWN, null, false); System.out.println("依存関係ツリーを構築しています ..."); this.provider.buildDependencyTree(plugin); @@ -146,7 +146,7 @@ public void crawlAll() this.provider.savePluginMeta( plugin, - InstallOperator.SERVER_ADMIN, + InstallOperator.UNKNOWN, System.currentTimeMillis(), null, false From f2a70b3d0ecbe9c94e784bd262eb28ed1fc2fe7f Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 13:38:28 +0900 Subject: [PATCH 331/745] feat: vague search of info command --- .../commands/CommandInfo.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index 3f4a7d54..67798b0c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -95,17 +95,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, PluginMetaProvider provider = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider(); - if (!provider.isPluginMetaExists(args[0])) - { - terminal.error("プラグインが見つかりませんでした。"); - return; - } - PluginMeta meta = provider.getPluginMeta( - args[0], true, true - ); - - terminal.info("情報を読み込み中..."); JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(args[0]); if (plugin == null) @@ -114,6 +104,17 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } + if (!provider.isPluginMetaExists(plugin.getName())) + { + terminal.error("プラグインが見つかりませんでした。"); + return; + } + + PluginMeta meta = provider.getPluginMeta( + plugin.getName(), true, true + ); + + terminal.info("情報を読み込み中..."); File file = PluginUtil.getFile(plugin); terminal.writeLine(Messages.keyValue("名前", meta.getName())); From 4f09be6b6f54dccbaf63b7b574768300b33fcb65 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 13:47:17 +0900 Subject: [PATCH 332/745] feat: Purge command --- .../commands/debug/CommandDepTreeDebug.java | 2 + .../commands/debug/deptree/CommandPurge.java | 81 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java index b34c7306..067cdfcf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java @@ -3,6 +3,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandMarkAsDependency; +import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandPurge; import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandRelation; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; import net.kyori.adventure.text.TextComponent; @@ -23,6 +24,7 @@ public CommandDepTreeDebug(PluginMetaManager manager) COMMANDS.put("markAsDependency", new CommandMarkAsDependency(manager.getProvider())); COMMANDS.put("relation", new CommandRelation(manager.getProvider())); + COMMANDS.put("purge", new CommandPurge(manager.getProvider())); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java new file mode 100644 index 00000000..f04dc2a6 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java @@ -0,0 +1,81 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@AllArgsConstructor +public class CommandPurge extends CommandBase +{ + private final PluginMetaProvider provider; + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 1)) + return; + + String pluginName = args[0]; + + if (pluginName.equalsIgnoreCase("all")) + { + Arrays.stream(Bukkit.getPluginManager().getPlugins()) + .forEach(plugin -> { + provider.deleteFromDependencyTree(pluginName); + provider.removePluginMeta(pluginName); + + terminal.success("Purged " + pluginName); + }); + } + + if (!provider.isPluginMetaExists(pluginName)) + { + terminal.error("Cannot find plugin meta of " + pluginName); + return; + } + + provider.deleteFromDependencyTree(pluginName); + provider.removePluginMeta(pluginName); + + terminal.success("Purged " + pluginName); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName) + .collect(Collectors.toList()); + } + + @Override + public @Nullable String getPermission() + { + return "kpm.debug.deptree.purge"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("プラグインの情報を開放します。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("plugin", "Plugin") + }; + } +} From f1e743f63060fb2ab85dfddb60fb0c7c225519d8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 15:53:13 +0900 Subject: [PATCH 333/745] fix: Plugin author doesn't remove --- .../lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 312067f5..13673019 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -396,6 +396,7 @@ public void removePluginMeta(@NotNull String pluginName) { Transaction.create(this.db, "DELETE FROM plugin_meta WHERE name = ?") .set(1, pluginName) + .beforeCommit(tr -> this.removePluginRelationalData(tr.getConnection(), pluginName)) .executeUpdate(); } From c98cb0bcb843e81265191600acd9be786e5a860a Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 17:24:07 +0900 Subject: [PATCH 334/745] feat: Query detecting --- .../installer/impls/install/PluginInstaller.java | 2 +- .../impls/uninstall/PluginUninstaller.java | 2 +- .../task/tasks/dependencies/DependencyElement.java | 13 +++++++++---- .../dependencies/collector/DependsCollectTask.java | 7 ++++++- .../task/tasks/install/PluginsInstallArgument.java | 6 ++++++ .../task/tasks/install/PluginsInstallTask.java | 14 ++++++++++---- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index 4459b42e..ac599f64 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -141,7 +141,7 @@ public InstallResult execute(@NotNull InstallArgument argument) th .bridgeArgument(result -> new DependsComputeOrderArgument(result.getCollectedPlugins())) .then(InstallTasks.INSTALLING_PLUGINS, new PluginsInstallTask(progress, signalHandler)) .bridgeArgument(result -> new PluginsInstallArgument( - pluginFilePath, pluginDescription, result.getOrder() + pluginFilePath, pluginDescription, query, result.getOrder() )) .submitAll(new DependsCollectArgument(pluginDescription)); // endregion diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index 7afa267e..b74343ed 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -123,7 +123,7 @@ public InstallResult execute(@NotNull UninstallArgument argument String name = descriptionFile.getName(); Path path = PluginUtil.getFile(pl).toPath(); - return new DependencyElement(name, path, descriptionFile); + return new DependencyElement(name, path, descriptionFile, null); }) .collect(Collectors.toList()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java index 2201981c..720ff7ac 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java @@ -1,11 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies; -import com.google.gson.annotations.Expose; import lombok.AllArgsConstructor; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; @@ -19,13 +19,11 @@ public class DependencyElement /** * 依存関係の名前です。 */ - @Expose @NotNull String pluginName; /** * 依存関係プラグインがあるのパスです。 */ - @Expose @NotNull Path pluginPath; @@ -35,10 +33,17 @@ public class DependencyElement @NotNull PluginDescriptionFile pluginDescription; - public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath) + /** + * 依存関係の解決に使用したクエリです。 + */ + @Nullable + String query; + + public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath, @NotNull String query) { this.pluginName = pluginName; this.pluginPath = pluginPath; + this.query = query; try { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 1dc2cdc8..945becf8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -124,7 +124,12 @@ public DependsCollectTask(@NotNull InstallProgress progress, @NotNull Sign Path pluginPath = downloadResults.get(actualName).getPath(); assert pluginPath != null; - this.status.onCollect(exceptedName, new DependencyElement(exceptedName, pluginPath, entry.getValue())); + this.status.onCollect( + exceptedName, + new DependencyElement(exceptedName, pluginPath, + entry.getValue(), exceptedName + ) + ); }); //------------------------ diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java index a98cad97..a5513eee 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java @@ -6,6 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.List; @@ -27,6 +28,11 @@ public class PluginsInstallArgument extends TaskArgument */ @NotNull PluginDescriptionFile pluginDescription; + /** + * プラグインの解決に使用したクエリです。 + */ + @Nullable + String query; /** * 依存関係の要素です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index 729fc9ec..450633d3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -82,7 +82,10 @@ private static void patchPluginCommands(List targets) PluginDescriptionFile pluginDescription = dependency.getPluginDescription(); Path path = dependency.getPluginPath(); - PluginsInstallResult result = this.installOne(path, pluginDescription, installedPlugins, true); + PluginsInstallResult result = + this.installOne(path, pluginDescription, dependency.getQuery(), + installedPlugins, true + ); if (!result.isSuccess()) // installOne returns null if installation is failed return result; } @@ -92,7 +95,10 @@ private static void patchPluginCommands(List targets) // Install plugin after dependencies installed - PluginsInstallResult result = this.installOne(arguments.getPluginPath(), arguments.getPluginDescription(), installedPlugins, false); + PluginsInstallResult result = + this.installOne(arguments.getPluginPath(), arguments.getPluginDescription(), + arguments.getQuery(), installedPlugins, false + ); if (result.isSuccess() && result.getInstalledPlugin() != null) TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().buildDependencyTree(result.getInstalledPlugin()); @@ -107,7 +113,7 @@ private static void patchPluginCommands(List targets) @NotNull private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription, - @NotNull List installedPlugins, boolean isDependency) + @Nullable String query, @NotNull List installedPlugins, boolean isDependency) { this.postSignal(new PluginInstallingSignal(path, pluginDescription)); @@ -169,7 +175,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr TeamKunPluginManager.getPlugin().getPluginMetaManager().onInstalled( target, isDependency ? InstallOperator.KPM_DEPENDENCY_RESOLVER: InstallOperator.SERVER_ADMIN, - null, + query, isDependency ); From c6c5f7c8a200a2f5d89e7227bb892bbb650cf742 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 17:38:03 +0900 Subject: [PATCH 335/745] fix: Degrade of /clean command(Stops server thread) --- .../kunmc/lab/teamkunpluginmanager/commands/CommandClean.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index bedacb98..6c85645a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -63,7 +63,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, terminal.writeLine(ChatColor.AQUA + String.join(", ", removable)); String[] finalRemovable = removable; - Runner.run(() -> { + Runner.runAsync(() -> { QuestionResult result = terminal.getInput(). showQuestion("本当に続行しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) .waitAndGetResult(); From a8535b21204de924eb5ec50a97ab37e244e3f3c7 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 18:03:09 +0900 Subject: [PATCH 336/745] feat: Enchanted info command --- .../commands/CommandInfo.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index 67798b0c..f4e2b8b7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -4,6 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependType; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.InstallOperator; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMeta; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; @@ -22,7 +23,9 @@ import org.jetbrains.annotations.Nullable; import java.io.File; +import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -85,6 +88,28 @@ private static Component commandList(Map> command) return component; } + private static String epochToString(long epoch) + { + return new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date(epoch)); + } + + private static String getInstalledByString(InstallOperator operator) + { + switch (operator) + { + case SERVER_ADMIN: + return ChatColor.GREEN + "サーバー管理者"; + case KPM_PLUGIN_UPDATER: + return ChatColor.AQUA + "KPMプラグインアップデーター"; + case KPM_DEPENDENCY_RESOLVER: + return ChatColor.DARK_AQUA + "KPM依存関係解決機能"; + case OTHER: + return ChatColor.RED + "その他"; + default: + return ChatColor.GRAY + "不明"; + } + } + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -141,6 +166,15 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, terminal.writeLine(Messages.keyValue("ダウンロードサイズ", Utils.roundSizeUnit(file.length()))); } + terminal.writeLine(""); + terminal.writeLine(Messages.keyValue( + "インストール者", + getInstalledByString(meta.getInstalledBy()) + )); + terminal.writeLine(Messages.keyValueYesNo("依存関係?", meta.isDependency())); + terminal.writeLine(Messages.keyValue("インストール日時", epochToString(meta.getInstalledAt()))); + + terminal.writeLine(""); terminal.write(dependTree("依存関係", meta.getDependsOn().stream() .map(dep -> { From 2f390cb750c3b4c8815ecf3beea9488ff3e97186 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 2 Oct 2022 18:03:21 +0900 Subject: [PATCH 337/745] chore: v3.0.0-v4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3537b293..49117b54 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kunmc.lab TeamKunPluginManager - 3.0.0-pre3 + 3.0.0-pre4 jar TeamKunPluginManager From e7f393780c9b3b422d769f8b7ed1693d679e1e01 Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 5 Oct 2022 21:05:31 +0900 Subject: [PATCH 338/745] refactor: Make DownloadResult#path @NotNull --- .../installer/task/tasks/download/DownloadResult.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java index a31fd6e9..8b2071a7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java @@ -22,7 +22,7 @@ public class DownloadResult extends TaskResult Date: Wed, 5 Oct 2022 21:15:03 +0900 Subject: [PATCH 339/745] feat: Alias provider --- .../plugin/alias/Alias.java | 25 ++++ .../plugin/alias/AliasProvider.java | 139 ++++++++++++++++++ .../plugin/alias/AliasSource.java | 44 ++++++ 3 files changed, 208 insertions(+) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/Alias.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasSource.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/Alias.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/Alias.java new file mode 100644 index 00000000..5c549516 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/Alias.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.alias; + +import lombok.Value; + +/** + * プラグインのエイリアスです。 + */ +@Value +public class Alias +{ + /** + * 正式名です。。 + */ + String name; + + /** + * エイリアスです。 + */ + String alias; + /** + * エイリアスのソースです。 + */ + String source; + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java new file mode 100644 index 00000000..dd32674d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java @@ -0,0 +1,139 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.alias; + +import com.zaxxer.hikari.HikariDataSource; +import net.kunmc.lab.teamkunpluginmanager.utils.ResultRow; +import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; +import java.sql.Statement; + +/** + * プラグインのエイリアスを提供するクラスです。 + */ +public class AliasProvider +{ + private final HikariDataSource db; + + public AliasProvider(@NotNull Path path) + { + this.db = Transaction.createDataSource(path); + + this.initializeTables(); + } + + private void initializeTables() + { + Transaction.create(this.db) + .doTransaction((tr) -> { + Statement stmt = tr.getConnection().createStatement(); + + stmt.execute("CREATE TABLE IF NOT EXISTS alias(" + + "name TEXT NOT NULL, " + + "alias TEXT NOT NULL PRIMARY KEY," + + "source_id TEXT NOT NULL" + + ")"); + + stmt.execute("CREATE TABLE IF NOT EXISTS source(" + + "name TEXT PRIMARY KEY NOT NULL, " + + "source TEXT NOT NULL," + + "type TEXT NOT NULL" + + ")"); + }); + } + + public void close() + { + this.db.close(); + } + + public void addAlias(@NotNull String name, @NotNull String alias, @NotNull String sourceId) + { + Transaction.create(this.db, "INSERT INTO alias(name, alias, source_id) VALUES(?, ?, ?)") + .set(1, name) + .set(2, alias) + .set(3, sourceId) + .executeUpdate(true); + } + + public void addSource(@NotNull String name, @NotNull String source, @NotNull AliasSource.SourceType type) + { + + if (hasSource(name)) + throw new IllegalArgumentException("The source already exists."); + + Transaction.create(this.db, "INSERT INTO source(name, source, type) VALUES(?, ?, ?)") + .set(1, name) + .set(2, source) + .set(3, type.name()) + .executeUpdate(true); + } + + public void removeAlias(@NotNull String name) + { + Transaction.create(this.db, "DELETE FROM alias WHERE name = ?") + .set(1, name) + .executeUpdate(); + } + + public void removeSource(String id) + { + Transaction.create(this.db, "DELETE FROM source WHERE name = ?") + .set(1, id) + .executeUpdate(); + } + + public boolean hasAlias(@NotNull String name) + { + return Transaction.create(this.db, "SELECT COUNT(*) FROM alias WHERE name = ?") + .set(1, name) + .isExists(); + } + + public boolean hasSource(String id) + { + return Transaction.create(this.db, "SELECT COUNT(*) FROM source WHERE name = ?") + .set(1, id) + .isExists(); + } + + public AliasSource getSource(int id) + { + try (ResultRow row = Transaction.create(this.db, "SELECT * FROM source WHERE name = ?") + .set(1, id) + .executeQuery() + .stream() + .findFirst().orElse(null)) + { + if (row == null) + return null; + + return new AliasSource( + row.getString("name"), + row.getString("source"), + AliasSource.SourceType.valueOf(row.getString("type")) + ); + } + } + + public Alias getAlias(String name) + { + try (ResultRow row = Transaction.create(this.db, "SELECT * FROM alias WHERE name = ?") + .set(1, name) + .executeQuery() + .stream() + .findFirst().orElse(null)) + { + if (row == null) + return null; + + return new Alias( + row.getString("name"), + row.getString("alias"), + row.getString("source_id") + ); + } + } + + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasSource.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasSource.java new file mode 100644 index 00000000..a05f9f82 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasSource.java @@ -0,0 +1,44 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.alias; + +import lombok.Value; +import org.jetbrains.annotations.NotNull; + +/** + * エイリアスのソースを表すクラスです。 + */ +@Value +public class AliasSource +{ + /** + * 人間が読めるエイリアスの名前です。 + */ + @NotNull + String name; + /** + * エイリアスのソースです。 + */ + @NotNull + String source; + + /** + * ソースの種類です。 + */ + @NotNull + SourceType type; + + public enum SourceType + { + /** + * Webサーバがソースです。 + */ + WEB_SERVER, + /** + * ローカルで定義されたソースです。 + */ + LOCAL_DEFINITIONS, + /** + * 動的に追加されたソースです。 + */ + DYNAMIC + } +} From 161b5da957a98ff5e523412dc5bb42fe0418be81 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 7 Oct 2022 20:20:58 +0900 Subject: [PATCH 340/745] feat: More transaction --- .../teamkunpluginmanager/utils/ResultRow.java | 191 ++++++++++++++++ .../utils/Transaction.java | 208 +++++++++++++++++- 2 files changed, 393 insertions(+), 6 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java new file mode 100644 index 00000000..1c4918fb --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java @@ -0,0 +1,191 @@ +package net.kunmc.lab.teamkunpluginmanager.utils; + +import lombok.AllArgsConstructor; + +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; + +/** + * {@link Transaction} で取得した {@link ResultSet} の行を表すクラスです。 + */ +@SuppressWarnings("unused") +@AllArgsConstructor +public class ResultRow implements AutoCloseable +{ + private final ResultSet result; + private final boolean closeConnectionOnException; + + private void handleException() + { + if (this.closeConnectionOnException) + { + try + { + this.result.getStatement().getConnection().close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + @Override + public void close() + { + try + { + this.result.close(); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + + public void closeAll() + { + try + { + this.result.getStatement().getConnection().close(); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + + public String getString(String columnLabel) + { + try + { + return this.result.getString(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public int getInt(String columnLabel) + { + try + { + return this.result.getInt(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public long getLong(String columnLabel) + { + try + { + return this.result.getLong(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public float getFloat(String columnLabel) + { + try + { + return this.result.getFloat(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public double getDouble(String columnLabel) + { + try + { + return this.result.getDouble(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public boolean getBoolean(String columnLabel) + { + try + { + return this.result.getBoolean(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public Date getDate(String columnLabel) + { + try + { + return this.result.getDate(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public Time getTime(String columnLabel) + { + try + { + return this.result.getTime(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public Timestamp getTimestamp(String columnLabel) + { + try + { + return this.result.getTimestamp(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + + public Object getObject(String columnLabel) + { + try + { + return this.result.getObject(columnLabel); + } + catch (SQLException e) + { + handleException(); + throw new IllegalStateException(e); + } + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java index 514485f5..23982010 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java @@ -1,15 +1,24 @@ package net.kunmc.lab.teamkunpluginmanager.utils; +import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import lombok.AllArgsConstructor; import lombok.Getter; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; /** * DBのトランザクションを簡単に行うためのクラスです。 @@ -106,6 +115,26 @@ public static Transaction create(@NotNull HikariDataSource dataSource) return create(dataSource, null); } + /** + * SQLIte データソースを作成します。 + * + * @param databasePath データベースのパス + * @return データソース + */ + public static HikariDataSource createDataSource(@NotNull Path databasePath) + { + HikariConfig config = new HikariConfig(); + + config.setDriverClassName("org.sqlite.JDBC"); + config.setJdbcUrl("jdbc:sqlite:" + databasePath); + + config.setMaximumPoolSize(20); + config.setLeakDetectionThreshold(300000); + config.setAutoCommit(false); + + return new HikariDataSource(config); + } + /** * トランザクションを再生成します。 * @@ -431,20 +460,33 @@ public int executeUpdate() /** * クエリ系SQL文を実行します。 * - * @param resultRun 結果を処理する関数 + * @param 戻り値の型 */ - public void executeQuery(QueryResultConsumer resultRun) + public QueryResult executeQuery() { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); - this.doTransaction((con) -> { + try + { ResultSet resultSet = this.preparedStatement.executeQuery(); - resultRun.accept(resultSet); + return new QueryResult<>(resultSet); + } + catch (SQLException e) + { + try + { + this.connection.rollback(); + this.connection.close(); + } + catch (SQLException e1) + { + throw new IllegalStateException(e1); + } - resultSet.close(); - }); + throw new IllegalStateException(e); + } } /** @@ -576,6 +618,12 @@ public boolean isExists() } } + public void close() throws Exception + { + if (!this.connection.isClosed()) + this.connection.close(); + } + /** * クエリ更新系SQL文を実行した時に、結果を処理する関数です。 */ @@ -593,4 +641,152 @@ public interface TransactionRun { void run(Transaction transaction) throws SQLException; } + + private static class QueryResultSpliterator implements Spliterator + { + private final ResultSet result; + private final boolean closeConnectionOnException; + + public QueryResultSpliterator(ResultSet result, boolean closeConnectionOnException) + { + this.result = result; + this.closeConnectionOnException = closeConnectionOnException; + } + + @Override + public boolean tryAdvance(Consumer action) + { + try + { + if (this.result.next()) + { + action.accept(new ResultRow(this.result, this.closeConnectionOnException)); + return true; + } + else + return false; + } + catch (SQLException e) + { + if (this.closeConnectionOnException) + { + try + { + this.result.getStatement().getConnection().close(); + } + catch (SQLException e1) + { + e1.printStackTrace(); + } + } + throw new IllegalStateException(e); + } + } + + @Override + public Spliterator trySplit() + { + return null; + } + + @Override + public long estimateSize() + { + return Long.MAX_VALUE; + } + + @Override + public int characteristics() + { + return ORDERED; + } + } + + /** + * クエリの実行結果を表すクラスです。 + */ + @AllArgsConstructor + public class QueryResult + { + private final ResultSet result; + + /** + * ResultSetをそのまま取得します。 + * + * @return ResultSet + */ + public ResultSet getResult() + { + return this.result; + } + + /** + * この結果を解放します。 + */ + public void close() throws SQLException + { + this.result.close(); + Transaction.this.connection.close(); + } + + /** + * Listに変換します。 + * + * @param resultMapper マッピング関数 + * @param max 最大件数 + * @return 変換されたList + */ + public ArrayList mapToList(Function resultMapper, long max) + { + ArrayList list = new ArrayList<>(); + + try + { + while (this.result.next() && !(max == -1 || list.size() >= max)) + list.add(resultMapper.apply(this.result)); + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + + return list; + } + + /** + * Listに変換します。 + * + * @param resultMapper マッピング関数 + * @return 変換されたList + */ + public ArrayList mapToList(Function resultMapper) + { + return mapToList(resultMapper, -1); + } + + /** + * Streamに変換します。 + * + * @return 変換されたStream + */ + public Stream stream(boolean closeConnectionOnException) + { + return StreamSupport.stream( + new QueryResultSpliterator(this.result, closeConnectionOnException), + false + ); + } + + /** + * Streamに変換します。 + * + * @return 変換されたStream + */ + public Stream stream() + { + return this.stream(true); + } + } + + } From fab5e75cd98239a8b424832f9d0202eafdbc1a15 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 7 Oct 2022 22:18:01 +0900 Subject: [PATCH 341/745] fix: Exception throws under Windows envs --- .../utils/TokenStore.java | 52 +++++++++++++------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java index 18d3bfa3..dc232e8d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java @@ -60,25 +60,23 @@ private static SecretKeySpec getKeySpec(String key) } } - private byte[] getkey(Path keyPath) throws IOException + @SuppressWarnings("ResultOfMethodCallIgnored") + private static void setPermission(Path path) { - if (Files.exists(keyPath)) - return Files.readAllBytes(keyPath); - try { - KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); - keyGenerator.init(256); - SecretKey key = keyGenerator.generateKey(); - byte[] keyBytes = key.getEncoded(); - Files.write(keyPath, keyBytes); - Files.setPosixFilePermissions(keyPath, PosixFilePermissions.fromString("rw-------")); - - return keyBytes; + if (System.getProperty("os.name").toLowerCase().contains("win")) + { + File f = path.toFile(); + f.setReadable(true, false); + f.setWritable(true, false); + } + else + Files.setPosixFilePermissions(path, PosixFilePermissions.fromString("rw-------")); } - catch (NoSuchAlgorithmException e) + catch (IOException e) { - throw new IllegalStateException("Failed to generate key.", e); + throw new RuntimeException(e); } } @@ -119,6 +117,29 @@ private String decryptToken(byte[] encryptedToken) } } + private byte[] getkey(Path keyPath) throws IOException + { + if (Files.exists(keyPath)) + return Files.readAllBytes(keyPath); + + try + { + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); + keyGenerator.init(256); + SecretKey key = keyGenerator.generateKey(); + byte[] keyBytes = key.getEncoded(); + Files.write(keyPath, keyBytes); + + setPermission(keyPath); + + return keyBytes; + } + catch (NoSuchAlgorithmException e) + { + throw new IllegalStateException("Failed to generate key.", e); + } + } + public void storeToken(String token) throws IOException { byte[] tokenBytes = encryptToken(token); @@ -131,7 +152,8 @@ public void storeToken(String token) throws IOException ); Files.write(tokenPath, tokenString.getBytes()); - Files.setPosixFilePermissions(tokenPath, PosixFilePermissions.fromString("rw-------")); + + setPermission(tokenPath); this.tokenCache = token; } From 2c873bff6d205342de117146cf9b465a34fed094 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 8 Oct 2022 00:59:01 +0900 Subject: [PATCH 342/745] refactor: Make Transaction#renew(String <- nullable --- .../net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java index 23982010..e4f8a25c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java @@ -141,7 +141,7 @@ public static HikariDataSource createDataSource(@NotNull Path databasePath) * @param newQuery 新しいSQL文 * @return トランザクション */ - public Transaction renew(@Language("sql") @NotNull String newQuery) + public Transaction renew(@Language("sql") @Nullable String newQuery) { return create(this, newQuery); } From 4d0a2888a0c5e3bc2787382602606317c5bf0370 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 8 Oct 2022 21:40:09 +0900 Subject: [PATCH 343/745] feat: Alias update tool --- .../TeamKunPluginManager.java | 61 ++++---- .../plugin/KnownPluginEntry.java | 11 -- .../plugin/KnownPlugins.java | 148 ------------------ .../plugin/alias/AliasProvider.java | 38 +---- .../plugin/alias/AliasUpdater.java | 79 ++++++++++ .../installer/impls/update/AliasUpdater.java | 55 +++++++ .../impls/update/UpdateArgument.java | 22 +++ .../impls/update/UpdateErrorCause.java | 8 + .../installer/impls/update/UpdateTasks.java | 16 ++ .../update/signals/UpdateFinishedSignal.java | 22 +++ .../download/SourceDownloadArgument.java | 21 +++ .../download/SourceDownloadErrorCause.java | 12 ++ .../source/download/SourceDownloadResult.java | 42 +++++ .../source/download/SourceDownloadState.java | 20 +++ .../source/download/SourceDownloadTask.java | 121 ++++++++++++++ .../download/signals/InvalidRemoteSignal.java | 39 +++++ .../download/signals/MalformedURLSignal.java | 12 ++ .../signals/SourceDownloadFailedSignal.java | 15 ++ .../signals/UnsupportedProtocolSignal.java | 23 +++ .../alias/update/UpdateAliasesArgument.java | 24 +++ .../alias/update/UpdateAliasesErrorCause.java | 12 ++ .../alias/update/UpdateAliasesResult.java | 36 +++++ .../alias/update/UpdateAliasesState.java | 16 ++ .../tasks/alias/update/UpdateAliasesTask.java | 135 ++++++++++++++++ .../update/signals/AliasUpdateSignal.java | 35 +++++ .../update/signals/InvalidSourceSignal.java | 42 +++++ .../update/signals/SourcePreparedSignal.java | 25 +++ .../alias/update/signals/SourceSignal.java | 28 ++++ .../plugin/meta/PluginMetaProvider.java | 17 +- .../resolver/impl/KnownPluginsResolver.java | 12 +- .../utils/Transaction.java | 35 +++-- 31 files changed, 921 insertions(+), 261 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateTasks.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/signals/UpdateFinishedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourceSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 695dfda8..9fa61ce8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -14,7 +14,7 @@ import net.kunmc.lab.teamkunpluginmanager.commands.CommandStatus; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUninstall; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; -import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; +import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasProvider; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallManager; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; @@ -31,14 +31,14 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; @Getter public final class TeamKunPluginManager extends JavaPlugin { - public static final String DATABASE_PATH = "plugins/TeamKunPluginManager/database/"; @Getter private static TeamKunPluginManager plugin; @@ -50,6 +50,7 @@ public final class TeamKunPluginManager extends JavaPlugin private CommandManager commandManager; private InstallManager installManager; private PluginMetaManager pluginMetaManager; + private AliasProvider aliasProvider; private void setupDependencyTree() { @@ -61,14 +62,13 @@ private void setupDependencyTree() System.out.println("プラグインメタデータを取得中 ..."); this.pluginMetaManager.crawlAll(); - KnownPlugins.initialization(this.getPluginConfig().getString("resolvePath")); + Path aliasFile = Paths.get(plugin.getDataFolder().toURI()).resolve("aliases.db"); + boolean isFirstTime = !Files.exists(aliasFile); - if (KnownPlugins.isLegacy()) - { - this.getLogger().warning("プラグイン定義ファイルの形式が古いです。更新しています..."); - KnownPlugins.migration(); + this.aliasProvider = new AliasProvider(aliasFile); + + if (isFirstTime && isTokenAvailable()) // Do update new CommandUpdate().onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); - } } private static void setupResolver(TeamKunPluginManager plugin) @@ -88,9 +88,8 @@ private static void setupResolver(TeamKunPluginManager plugin) @Override public void onDisable() { - pluginMetaManager.getProvider().close(); - if (KnownPlugins.dataSource != null) - KnownPlugins.dataSource.close(); + this.pluginMetaManager.getProvider().close(); + this.aliasProvider.close(); } public boolean isTokenAvailable() @@ -113,23 +112,8 @@ public static void registerCommands(CommandManager commandManager) commandManager.registerCommand("debug", new CommandDebug()); } - @Override - public void onEnable() + private void setupToken() { - session = new Session(); - saveDefaultConfig(); - plugin = this; - pluginConfig = getConfig(); - resolver = new PluginResolver(); - commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); - installManager = new InstallManager(this); - new PluginLoader(); // Initialize plugin loader - - setupDependencyTree(); - registerCommands(commandManager); - - setupResolver(this); - tokenStore = new TokenStore( this.getDataFolder().toPath().resolve("token.dat"), this.getDataFolder().toPath().resolve("token_key.dat") @@ -150,13 +134,30 @@ public void onEnable() System.out.println("トークンの読み込みに失敗しました。"); } - if (!new File(DATABASE_PATH).exists()) - new CommandUpdate().onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); String tokenEnv = System.getenv("TOKEN"); if (tokenEnv != null && !tokenEnv.isEmpty()) tokenStore.fromEnv(); + + } + + @Override + public void onEnable() + { + session = new Session(); + saveDefaultConfig(); + plugin = this; + pluginConfig = getConfig(); + resolver = new PluginResolver(); + commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); + installManager = new InstallManager(this); + new PluginLoader(); // Initialize plugin loader + + registerCommands(commandManager); + setupResolver(this); + setupToken(); + setupDependencyTree(); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java deleted file mode 100644 index 0c081b43..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPluginEntry.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin; - -import lombok.Value; - -@Value -public class KnownPluginEntry -{ - String name; - String url; - String source; -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java deleted file mode 100644 index 9cc7b250..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/KnownPlugins.java +++ /dev/null @@ -1,148 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin; - -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import org.apache.commons.lang.StringUtils; - -import java.io.File; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Statement; - -public class KnownPlugins -{ - public static HikariDataSource dataSource; - - public static void del(String source) - { - try (Connection con = dataSource.getConnection(); - PreparedStatement pstmt = con.prepareStatement("DELETE FROM PLUGIN WHERE SOURCE=?")) - { - pstmt.setString(1, source); - pstmt.execute(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - public static void initialization(String fileName) - { - HikariConfig config = new HikariConfig(); - config.setDriverClassName("org.sqlite.JDBC"); - - config.setJdbcUrl("jdbc:sqlite:" + new File(TeamKunPluginManager.getPlugin().getDataFolder().getPath(), fileName).getAbsolutePath()); - - config.setMaximumPoolSize(20); - config.setLeakDetectionThreshold(300000); - - dataSource = new HikariDataSource(config); - if (isLegacy()) - return; - initTables(); - } - - public static boolean isLegacy() - { - try (Connection connection = dataSource.getConnection()) - { - DatabaseMetaData meta = connection.getMetaData(); - ResultSet set = meta.getTables(null, null, "DEPEND", null); - return set.next(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - public static void migration() - { - if (!isLegacy()) - return; - - try (Connection connection = dataSource.getConnection(); - Statement stmt = connection.createStatement()) - { - stmt.execute("DROP TABLE DEPEND"); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - initTables(); - - } - - private static void initTables() - { - try (Connection connection = dataSource.getConnection(); - Statement stmt = connection.createStatement()) - { - stmt.execute("CREATE TABLE IF NOT EXISTS PLUGIN(" + - "NAME TEXT, " + - "URL TEXT, " + - "SOURCE TEXT)"); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - public static KnownPluginEntry getKnown(String name) - { - String[] org = StringUtils.split(name, "/"); - String query = "SELECT * FROM PLUGIN WHERE " + - "NAME=? "; - if (org.length == 2) - query += "AND SOURCE=?"; - - try (Connection connection = dataSource.getConnection(); - PreparedStatement pstmt = connection.prepareStatement(query)) - { - pstmt.setString(1, org[0]); - if (org.length == 2) - pstmt.setString(2, org[1]); - - ResultSet set = pstmt.executeQuery(); - - if (!set.next()) - return null; - - return new KnownPluginEntry( - set.getString("NAME"), - set.getString("URL"), - set.getString("SOURCE")); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - public static boolean isKnown(String name) - { - return getKnown(name) != null; - } - - public static void addKnownPlugin(KnownPluginEntry entry) - { - try (Connection connection = dataSource.getConnection(); - PreparedStatement pstmt = connection.prepareStatement("INSERT INTO PLUGIN VALUES (?, ?, ?)")) - { - pstmt.setString(1, entry.getName()); - pstmt.setString(2, entry.getUrl()); - pstmt.setString(3, entry.getSource()); - pstmt.execute(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java index dd32674d..6d8bdfd5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java @@ -1,6 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.alias; import com.zaxxer.hikari.HikariDataSource; +import lombok.AccessLevel; +import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.utils.ResultRow; import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; import org.jetbrains.annotations.NotNull; @@ -13,6 +15,7 @@ */ public class AliasProvider { + @Getter(AccessLevel.PACKAGE) private final HikariDataSource db; public AliasProvider(@NotNull Path path) @@ -47,40 +50,9 @@ public void close() this.db.close(); } - public void addAlias(@NotNull String name, @NotNull String alias, @NotNull String sourceId) + public AliasUpdater createUpdater(@NotNull String sourceName, @NotNull String sourceURL) { - Transaction.create(this.db, "INSERT INTO alias(name, alias, source_id) VALUES(?, ?, ?)") - .set(1, name) - .set(2, alias) - .set(3, sourceId) - .executeUpdate(true); - } - - public void addSource(@NotNull String name, @NotNull String source, @NotNull AliasSource.SourceType type) - { - - if (hasSource(name)) - throw new IllegalArgumentException("The source already exists."); - - Transaction.create(this.db, "INSERT INTO source(name, source, type) VALUES(?, ?, ?)") - .set(1, name) - .set(2, source) - .set(3, type.name()) - .executeUpdate(true); - } - - public void removeAlias(@NotNull String name) - { - Transaction.create(this.db, "DELETE FROM alias WHERE name = ?") - .set(1, name) - .executeUpdate(); - } - - public void removeSource(String id) - { - Transaction.create(this.db, "DELETE FROM source WHERE name = ?") - .set(1, id) - .executeUpdate(); + return new AliasUpdater(sourceName, sourceURL, this); } public boolean hasAlias(@NotNull String name) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java new file mode 100644 index 00000000..b963af92 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java @@ -0,0 +1,79 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.alias; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; + +public class AliasUpdater +{ + private final String sourceName; + private final String sourceURL; + private final Transaction transaction; + + @Getter + private long aliasesCount; + + public AliasUpdater(String sourceName, String sourceURL, AliasProvider provider) + { + this.sourceName = sourceName; + this.sourceURL = sourceURL; + this.transaction = Transaction.create(provider.getDb()); + + this.aliasesCount = 0; + + this.createCheckTable(sourceName); + } + + private void createCheckTable(String sourceName) + { + if (!this.transaction.renew("SELECT name FROM source WHERE name = ?") + .isExists()) + return; + + this.transaction.renew("CREATE TABLE v_exists_alias AS SELECT name FROM alias WHERE source_id = ?") + .set(1, sourceName) + .executeUpdate(false); + } + + private void dropCheckTable() + { + this.transaction.renew("DROP TABLE IF EXISTS v_exists_alias") + .executeUpdate(false); + } + + public void update(String name, String alias) + { + this.transaction.renew("INSERT OR REPLACE INTO alias (name, alias, source_id) VALUES (?, ?, ?)") + .set(1, name) + .set(2, alias) + .set(3, sourceName) + .executeUpdate(false); + + this.aliasesCount++; + } + + private void deleteRemovedAlias() + { + this.transaction.renew("DELETE FROM alias WHERE name IN " + + "(SELECT name FROM v_exists_alias EXCEPT SELECT name FROM alias WHERE source_id = ?)") + .set(1, sourceName) + .executeUpdate(false); + } + + public void done() + { + transaction.renew("INSERT OR REPLACE INTO source (name, source, type) VALUES (?, ?, ?)") + .set(1, sourceName) + .set(2, sourceURL) + .set(3, AliasSource.SourceType.WEB_SERVER.name()) + .executeUpdate(false); + + this.deleteRemovedAlias(); + this.dropCheckTable(); + this.transaction.finishManually(); + } + + public void cancel() + { + this.transaction.abortManually(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java new file mode 100644 index 00000000..bb946e72 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java @@ -0,0 +1,55 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.signals.UpdateFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.SourceDownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.SourceDownloadTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.UpdateAliasesArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.UpdateAliasesResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.UpdateAliasesTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.HashMap; + +/** + * プラグインをエイリアスのアップデートするインストーラーの実装です。 + * エイリアスのアップデートは主に以下の流れで動作します。 + * + *
      + *
    1. {@link UpdateTasks#} - エイリアスのアップデート対象のプラグインを検索する。
    2. + *
    + */ +public class AliasUpdater extends AbstractInstaller +{ + public AliasUpdater(SignalHandleManager signalHandler) throws IOException + { + super(signalHandler); + } + + @Override + public InstallResult execute(@NotNull UpdateArgument argument) throws TaskFailedException + { + HashMap remotes = argument.getRemotes(); + + UpdateAliasesResult result = + (UpdateAliasesResult) this.submitter( + UpdateTasks.DOWNLOADING_SOURCES, + new SourceDownloadTask(this.progress, this.signalHandler) + ) + .then( + UpdateTasks.UPDATING_ALIASES, + new UpdateAliasesTask(this.progress, this.signalHandler) + ) + .bridgeArgument(sourceDownloadResult -> + new UpdateAliasesArgument(sourceDownloadResult.getDownloadedSources())) + .submitAll(new SourceDownloadArgument(remotes)); + + this.postSignal(new UpdateFinishedSignal(result.getAliasesCount(), result.getAliasesCountBySource())); + + return this.success(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateArgument.java new file mode 100644 index 00000000..94a18834 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateArgument.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; + +import java.util.HashMap; + +/** + * エイリアスのアップデートの引数を格納するクラスです。 + */ +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class UpdateArgument extends AbstractInstallerArgument +{ + /** + * エイリアスのソースのURLです。 + */ + HashMap remotes; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateErrorCause.java new file mode 100644 index 00000000..7582329f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateErrorCause.java @@ -0,0 +1,8 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; + +/** + * エイリアスのアップデートのエラーを表す列挙型です。 + */ +public enum UpdateErrorCause +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateTasks.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateTasks.java new file mode 100644 index 00000000..d6df4da1 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateTasks.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; + +/** + * エイリアスのアップデートのタスクを表す列挙型です。 + */ +public enum UpdateTasks +{ + /** + * ソースのダウンロードを行います。 + */ + DOWNLOADING_SOURCES, + /** + * エイリアスのアップデートを行います。 + */ + UPDATING_ALIASES, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/signals/UpdateFinishedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/signals/UpdateFinishedSignal.java new file mode 100644 index 00000000..9c3bb3d9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/signals/UpdateFinishedSignal.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +import java.util.HashMap; + +/** + * エイリアスのアップデートが完了したことを示すシグナルです。 + */ +@Value +public class UpdateFinishedSignal implements Signal +{ + /** + * エイリアスの数です。 + */ + long aliases; + /** + * エイリアスとソースのペアの数です。 + */ + HashMap aliasesBySources; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadArgument.java new file mode 100644 index 00000000..6caaf067 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadArgument.java @@ -0,0 +1,21 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; + +import java.util.HashMap; + +/** + * ソースファイルのダウンロードを行うタスクの引数です。 + */ +@Value +@EqualsAndHashCode(callSuper = false) +public class SourceDownloadArgument extends TaskArgument +{ + /** + * エイリアスのソースのURLです。 + * キーはリモートの名前、値はHTTP(S)サーバのURLです。 + */ + HashMap remotes; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java new file mode 100644 index 00000000..8873b1b9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; + +/** + * ソースファイルのダウンロードに失敗した理由を表します。 + */ +public enum SourceDownloadErrorCause +{ + /** + * すべてのダウンロードに失敗しました。 + */ + ALL_DOWNLOAD_FAILED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadResult.java new file mode 100644 index 00000000..bce3c3ae --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadResult.java @@ -0,0 +1,42 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.net.URL; +import java.nio.file.Path; +import java.util.HashMap; + +/** + * ソースファイルのダウンロードを行うタスクの結果です。 + */ +@Value +@EqualsAndHashCode(callSuper = true) +public class SourceDownloadResult extends TaskResult +{ + /** + * ダウンロードしたソースの名前とパスのマップです。 + */ + HashMap> downloadedSources; + + public SourceDownloadResult(boolean success, @NotNull SourceDownloadState state, + @Nullable SourceDownloadErrorCause errorCause, HashMap> downloadedSources) + { + super(success, state, errorCause); + this.downloadedSources = downloadedSources; + } + + public SourceDownloadResult(boolean success, @NotNull SourceDownloadState state, @Nullable SourceDownloadErrorCause errorCause) + { + this(success, state, errorCause, null); + } + + public SourceDownloadResult(boolean success, @NotNull SourceDownloadState state, HashMap> downloadedSources) + { + this(success, state, null, downloadedSources); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadState.java new file mode 100644 index 00000000..1c773e23 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadState.java @@ -0,0 +1,20 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; + +/** + * ソースファイルのダウンロードの状態を表します。 + */ +public enum SourceDownloadState +{ + /** + * ソースファイルのダウンロードが初期化されたことを示します。 + */ + INITIALIZED, + /** + * URLの解析中であることを示します。 + */ + ANALYZING_URLS, + /** + * ソースをダウンロード中であることを示します。 + */ + DOWNLOADING_SOURCES, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java new file mode 100644 index 00000000..119985c2 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java @@ -0,0 +1,121 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.SourceDownloadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.UnsupportedProtocolSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import org.jetbrains.annotations.NotNull; + +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Path; +import java.util.HashMap; + +/** + * ソースファイルのダウンロードを行うタスクです。 + */ +public class SourceDownloadTask extends InstallTask +{ + private final SignalHandleManager signalHandler; + private SourceDownloadState status; + + public SourceDownloadTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + { + super(progress, signalHandler); + + this.signalHandler = signalHandler; + this.status = SourceDownloadState.INITIALIZED; + } + + private static boolean isProtocolSupported(String protocolName) + { + return protocolName.equalsIgnoreCase("http") || protocolName.equalsIgnoreCase("https"); + } + + @Override + public @NotNull SourceDownloadResult runTask(@NotNull SourceDownloadArgument arguments) + { + this.status = SourceDownloadState.ANALYZING_URLS; + HashMap remotes = this.buildURLs(arguments.getRemotes()); + + this.status = SourceDownloadState.DOWNLOADING_SOURCES; + HashMap> downloadSources = this.downloadSources(remotes); + + if (downloadSources.isEmpty()) + return new SourceDownloadResult(false, this.status, SourceDownloadErrorCause.ALL_DOWNLOAD_FAILED); + + return new SourceDownloadResult(true, this.status, downloadSources); + } + + private HashMap buildURLs(HashMap sources) + { + HashMap result = new HashMap<>(); + + for (String remoteName : sources.keySet()) + { + String remoteURL = sources.get(remoteName); + + URL url; + if ((url = this.buildURL(remoteName, remoteURL)) != null) + result.put(remoteName, url); + } + + return result; + } + + private URL buildURL(String fallbackName, String urlString) + { + URL url; + try + { + url = new URL(urlString); + } + catch (MalformedURLException e) + { + this.postSignal(new MalformedURLSignal(fallbackName, urlString)); + return null; + } + + if (!isProtocolSupported(url.getProtocol())) + { + this.postSignal(new UnsupportedProtocolSignal(fallbackName, url)); + return null; + } + + return null; + } + + private HashMap> downloadSources(HashMap remotes) + { + HashMap> result = new HashMap<>(); + + for (String remoteName : remotes.keySet()) + { + URL remoteURL = remotes.get(remoteName); + + Path path; + if ((path = this.downloadSource(remoteName, remoteURL)) != null) + result.put(remoteName, new Pair<>(remoteURL, path)); + } + + return result; + } + + private Path downloadSource(String remoteName, URL remoteURL) + { + DownloadResult result = new DownloadTask(this.progress, this.signalHandler) + .runTask(new DownloadArgument(remoteURL.toString())); + boolean success = result.isSuccess(); + + if (!success) + this.postSignal(new SourceDownloadFailedSignal(remoteName, result)); + + return success ? result.getPath(): null; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java new file mode 100644 index 00000000..6dcd6526 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java @@ -0,0 +1,39 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.net.URL; + +/** + * リモートが不正だった場合に送信されるシグナルです。 + */ +@AllArgsConstructor +@Getter +public abstract class InvalidRemoteSignal implements Signal +{ + /** + * リモートの名前です。 + */ + @NotNull + private final String remoteName; + /** + * リモートのURLです。 + */ + @NotNull + private final String remoteURL; + + /** + * URLのオブジェクトです。 + */ + @Nullable + private final URL urlObject; + + public InvalidRemoteSignal(@NotNull String remoteName, @NotNull String remoteURL) + { + this(remoteName, remoteURL, null); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java new file mode 100644 index 00000000..5edf9c19 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; + +/** + * 不正なURLが指定された場合に送信されるシグナルです。 + */ +public class MalformedURLSignal extends InvalidRemoteSignal +{ + public MalformedURLSignal(String remoteName, String remoteURL) + { + super(remoteName, remoteURL); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java new file mode 100644 index 00000000..afe18fe7 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +/** + * ソースファイルのダウンロードに失敗したことを示すシグナルです。 + */ +@Value +public class SourceDownloadFailedSignal implements Signal +{ + String remoteName; + DownloadResult downloadResult; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java new file mode 100644 index 00000000..f2cd7652 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; + +import lombok.Getter; + +import java.net.URL; + +/** + * サポートされていないプロトコルが指定された場合に送信されるシグナルです。 + */ +@Getter +public class UnsupportedProtocolSignal extends InvalidRemoteSignal +{ + /** + * プロトコル名です。 + */ + private final String protocol; + + public UnsupportedProtocolSignal(String remoteName, URL remoteURL) + { + super(remoteName, remoteURL.toString(), remoteURL); + this.protocol = remoteURL.getProtocol(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesArgument.java new file mode 100644 index 00000000..29c060ad --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesArgument.java @@ -0,0 +1,24 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; + +import java.net.URL; +import java.nio.file.Path; +import java.util.HashMap; + +/** + * エイリアスのアップデートを行うタスクの引数です。 + */ +@Value +@EqualsAndHashCode(callSuper = false) +public class UpdateAliasesArgument extends TaskArgument +{ + /** + * エイリアスのソースファイルの名前とペアのマップです。 + * ペアの左辺はリモートのURL、右辺はローカルのパスです。 + */ + HashMap> sources; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java new file mode 100644 index 00000000..b8b2eb4c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; + +/** + * エイリアスのアップデートに失敗した理由を表します。 + */ +public enum UpdateAliasesErrorCause +{ + /** + * すべてのアップデートに失敗しました。 + */ + ALL_UPDATE_FAILED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesResult.java new file mode 100644 index 00000000..0ab147be --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesResult.java @@ -0,0 +1,36 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; + +/** + * エイリアスのアップデートを行うタスクの結果です。 + */ +@Value +@EqualsAndHashCode(callSuper = true) +public class UpdateAliasesResult extends TaskResult +{ + boolean warn; + long aliasesCount; + HashMap aliasesCountBySource; + + public UpdateAliasesResult(boolean success, @NotNull UpdateAliasesState state, @Nullable UpdateAliasesErrorCause errorCause, + boolean warn, long aliasesCount, HashMap aliasesCountBySource) + { + super(success, state, errorCause); + this.warn = warn; + this.aliasesCount = aliasesCount; + this.aliasesCountBySource = aliasesCountBySource; + } + + public UpdateAliasesResult(boolean success, @NotNull UpdateAliasesState state, + boolean warn, long aliasesCount, HashMap aliasesCountBySource) + { + this(success, state, null, warn, aliasesCount, aliasesCountBySource); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesState.java new file mode 100644 index 00000000..d45d7fad --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesState.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; + +/** + * エイリアスのアップデートの状態を表します。 + */ +public enum UpdateAliasesState +{ + /** + * エイリアスのアップデートが初期化されたことを示します。 + */ + INITIALIZED, + /** + * エイリアスのアップデート中であることを示します。 + */ + UPDATING, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java new file mode 100644 index 00000000..653fc972 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java @@ -0,0 +1,135 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; + +import com.google.gson.JsonSyntaxException; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasUpdater; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.AliasUpdateSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.InvalidSourceSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.SourcePreparedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import org.jetbrains.annotations.NotNull; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +/** + * エイリアスのアップデートを行うタスクです。 + */ +public class UpdateAliasesTask extends InstallTask +{ + private UpdateAliasesState status; + + public UpdateAliasesTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + { + super(progress, signalHandler); + + this.status = UpdateAliasesState.INITIALIZED; + } + + @Override + public @NotNull UpdateAliasesResult runTask(@NotNull UpdateAliasesArgument arguments) + { + HashMap> sources = arguments.getSources(); + + HashMap aliasesOfSources = new HashMap<>(); + long total = 0; + + boolean isWarn = false; + boolean anySuccess = false; + this.status = UpdateAliasesState.UPDATING; + for (Map.Entry> source : sources.entrySet()) + { + String aliasName = source.getKey(); + URL url = source.getValue().getLeft(); + Path path = source.getValue().getRight(); + + long statusOrError = this.updateAliasesFromSource(aliasName, url, path); + + if (statusOrError < 0) + { + isWarn = true; + continue; + } + + total += statusOrError; + aliasesOfSources.put(aliasName, statusOrError); + + anySuccess = true; + } + + + return new UpdateAliasesResult(anySuccess, this.status, + anySuccess ? null: UpdateAliasesErrorCause.ALL_UPDATE_FAILED, isWarn, + total, aliasesOfSources + ); + } + + private long updateAliasesFromSource(String sourceName, URL url, Path source) + { + AliasUpdater updater = TeamKunPluginManager.getPlugin().getAliasProvider().createUpdater( + sourceName, url.toString() + ); + + SourcePreparedSignal signal = new SourcePreparedSignal(sourceName, source, url.toString()); + this.postSignal(signal); + if (!signal.isSkip()) + return -1; + + try (InputStream stream = Files.newInputStream(source); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + JsonReader jsonReader = new JsonReader(reader)) + { + jsonReader.beginObject(); + while (jsonReader.hasNext()) + { + if (jsonReader.peek().equals(JsonToken.END_OBJECT)) + break; + + String aliasName = jsonReader.nextName(); + String alias = jsonReader.nextString(); + + AliasUpdateSignal updateSignal = new AliasUpdateSignal( + sourceName, url, aliasName, alias + ); + this.postSignal(updateSignal); + + if (updateSignal.isSkip()) + continue; + + updater.update(aliasName, alias); + } + + updater.done(); + } + catch (JsonSyntaxException e) + { + this.postSignal(new InvalidSourceSignal(sourceName, source, + url.toString(), InvalidSourceSignal.ErrorCause.SOURCE_FILE_MALFORMED + )); + return -1; + } + catch (Exception e) + { + this.postSignal(new InvalidSourceSignal(sourceName, source, + url.toString(), InvalidSourceSignal.ErrorCause.IO_ERROR + )); + e.printStackTrace(); + updater.cancel(); + return -1; + } + + return updater.getAliasesCount(); + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java new file mode 100644 index 00000000..2f914c4d --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java @@ -0,0 +1,35 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.jetbrains.annotations.NotNull; + +import java.net.URL; + +@Data +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class AliasUpdateSignal implements Signal +{ + @NotNull + private final String source; + @NotNull + private final URL sourceURL; + @NotNull + private final String name; + + private boolean skip; + private String alias; + + public AliasUpdateSignal(@NotNull String source, @NotNull URL sourceURL, @NotNull String name, + @NotNull String alias) + { + this.source = source; + this.sourceURL = sourceURL; + this.name = name; + + this.skip = false; + this.alias = alias; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java new file mode 100644 index 00000000..52a3b925 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java @@ -0,0 +1,42 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; + +/** + * ソースファイルが不正だった場合に送信されるシグナルです。 + */ +@Value +@EqualsAndHashCode(callSuper = true) +public class InvalidSourceSignal extends SourceSignal +{ + /** + * エラーの原因です。 + */ + ErrorCause errorCause; + + public InvalidSourceSignal(@NotNull String sourceName, @NotNull Path sourcePath, @Nullable String sourceURL, ErrorCause errorCause) + { + super(sourceName, sourcePath, sourceURL); + this.errorCause = errorCause; + } + + /** + * エラーの理由です。 + */ + public enum ErrorCause + { + /** + * ソースファイルが不正な形式です。 + */ + SOURCE_FILE_MALFORMED, + /** + * I/Oエラーが発生しました。 + */ + IO_ERROR, + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java new file mode 100644 index 00000000..674a854a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; + +import lombok.Getter; +import lombok.Setter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; + +/** + * ソースが準備されたことを示すシグナルです。 + */ +@Getter +@Setter +public class SourcePreparedSignal extends SourceSignal +{ + private boolean skip; + + public SourcePreparedSignal(@NotNull String sourceName, @NotNull Path sourcePath, @Nullable String sourceURL) + { + super(sourceName, sourcePath, sourceURL); + + this.skip = true; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourceSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourceSignal.java new file mode 100644 index 00000000..104394a3 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourceSignal.java @@ -0,0 +1,28 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; + +@Data +abstract class SourceSignal implements Signal +{ + /** + * ソースの名前です。 + */ + @NotNull + private final String sourceName; + /** + * ソースファイルのパスです。 + */ + @NotNull + private final Path sourcePath; + /** + * ソースファイルのURLです。 + */ + @Nullable + private final String sourceURL; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java index 13673019..c3a61658 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/meta/PluginMetaProvider.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.meta; -import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; @@ -32,7 +31,7 @@ public class PluginMetaProvider implements Listener public PluginMetaProvider(@NotNull Plugin plugin, @NotNull Path databasePath) { - this.db = createConnection(databasePath); + this.db = Transaction.createDataSource(databasePath); this.initializeTables(); @@ -721,20 +720,6 @@ private void initializeTables() }); } - private HikariDataSource createConnection(@NotNull Path databasePath) - { - HikariConfig config = new HikariConfig(); - - config.setDriverClassName("org.sqlite.JDBC"); - config.setJdbcUrl("jdbc:sqlite:" + databasePath); - - config.setMaximumPoolSize(20); - config.setLeakDetectionThreshold(300000); - config.setAutoCommit(false); - - return new HikariDataSource(config); - } - private List getDependDataFromTable(String tableName, String name, String field, DependType type, boolean baseReversed) { List depString = MetaSQLUtil.getListFromTable(this.db, tableName, name, baseReversed ? field: "name", baseReversed ? "name": field); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java index 9976f0d7..2ddb98c0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java @@ -1,8 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import lombok.AllArgsConstructor; -import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; -import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.alias.Alias; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; @@ -19,14 +19,14 @@ public class KnownPluginsResolver implements BaseResolver @Override public ResolveResult resolve(QueryContext query) { - KnownPluginEntry entry = KnownPlugins.getKnown(query.getQuery()); + Alias alias = TeamKunPluginManager.getPlugin().getAliasProvider().getAlias(query.getQuery()); - if (entry == null) + if (alias == null) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); try { - ResolveResult detailedResult = resolver.resolve(entry.getUrl()); + ResolveResult detailedResult = resolver.resolve(alias.getName()); if (detailedResult instanceof SuccessResult) return new SuccessResult(this, ((SuccessResult) detailedResult).getDownloadUrl(), ResolveResult.Source.LOCAL_KNOWN); else @@ -36,7 +36,7 @@ public ResolveResult resolve(QueryContext query) { } - return new SuccessResult(this, entry.getUrl(), null, null, ResolveResult.Source.LOCAL_KNOWN); + return new SuccessResult(this, alias.getName(), null, null, ResolveResult.Source.LOCAL_KNOWN); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java index e4f8a25c..676f2706 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java @@ -554,14 +554,16 @@ public void finishManually() throw new IllegalStateException(e); } - - try - { - this.connection.close(); - } - catch (SQLException e) + finally { - throw new IllegalStateException(e); + try + { + this.connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } } } @@ -573,12 +575,20 @@ public void abortManually() try { this.connection.rollback(); - this.connection.close(); } catch (SQLException e1) { throw new IllegalStateException(e1); } + + try + { + this.connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } } /** @@ -624,15 +634,6 @@ public void close() throws Exception this.connection.close(); } - /** - * クエリ更新系SQL文を実行した時に、結果を処理する関数です。 - */ - @FunctionalInterface - public interface QueryResultConsumer - { - void accept(ResultSet result) throws SQLException; - } - /** * トランザクションを実行する汎用関数です。 */ From d75c9954ccc599d7c26c6f82aac511115cdd678a Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 00:50:09 +0900 Subject: [PATCH 344/745] feat: Apply updater --- .../TeamKunPluginManager.java | 3 +- .../commands/CommandUpdate.java | 260 ++---------------- .../commands/signal/HeadSignalHandlers.java | 12 +- .../DownloadingSignalHandler.java | 2 +- .../update/UpdateAliasesSignalHandler.java | 57 ++++ .../plugin/alias/AliasUpdater.java | 4 - .../plugin/installer/InstallManager.java | 29 ++ .../source/download/SourceDownloadTask.java | 2 +- .../utils/Transaction.java | 16 +- src/main/resources/config.v2.yml | 27 ++ src/main/resources/config.yml | 1 - 11 files changed, 159 insertions(+), 254 deletions(-) rename src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/{intall => common}/DownloadingSignalHandler.java (99%) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java create mode 100644 src/main/resources/config.v2.yml diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 9fa61ce8..b871dbe0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -154,10 +154,11 @@ public void onEnable() installManager = new InstallManager(this); new PluginLoader(); // Initialize plugin loader - registerCommands(commandManager); setupResolver(this); setupToken(); setupDependencyTree(); + + registerCommands(commandManager); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 3bd7b1a9..ea8a576d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -1,252 +1,40 @@ package net.kunmc.lab.teamkunpluginmanager.commands; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPluginEntry; -import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.UpdateArgument; import net.kyori.adventure.text.TextComponent; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.net.HttpURLConnection; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -public class CommandUpdate extends CommandBase // TODO: Rewrite this +public class CommandUpdate extends CommandBase { - private static DownloadResult doDownload(Terminal terminal) - { - AtomicInteger num = new AtomicInteger(0); - Map paths = new HashMap<>(); - AtomicBoolean error = new AtomicBoolean(false); - long start = System.currentTimeMillis(); - TeamKunPluginManager.getPlugin().getPluginConfig().getMapList("config") - .forEach(s -> { - String fileName; - - int i = 0; - do - { - fileName = TeamKunPluginManager.DATABASE_PATH + (++i) + ".json"; - } - while (new File(fileName).exists()); - - String url = (String) s.get("url"); - try - { - URL urlObj = new URL(url); - HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection(); - connection.setRequestMethod("GET"); - if (Boolean.parseBoolean(s.get("auth").toString()) && (urlObj.getHost().equals("api.github.com") || - urlObj.getHost().equals("raw.githubusercontent.com"))) - connection.setRequestProperty( - "Authorization", - "token " + TeamKunPluginManager.getPlugin().getTokenStore().getToken() - ); - connection.setRequestProperty( - "User-Agent", - "Mozilla/8.10; Safari/Chrome/Opera/Edge/KungleBot-Peyang; Mobile-Desktop" - ); - connection.connect(); - if (connection.getResponseCode() != 200) - { - terminal.writeLine(ChatColor.RED + "無視:" + num.incrementAndGet() + " " + url); - terminal.writeLine(ChatColor.RED + " " + - connection.getResponseCode() + " " + - connection.getResponseMessage() + " [IP: " + - InetAddress.getByName(urlObj.getHost()).getHostAddress() + - "]"); - error.set(true); - return; - } - - File file = new File(fileName); - - String name = (String) s.get("name"); - - if (paths.containsKey(name)) - { - terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + name); - terminal.writeLine(ChatColor.RED + " エイリアスセット '" + name + "' が重複しています。"); - error.set(true); - return; - } - paths.put(name, fileName); - if (!file.createNewFile()) - { - terminal.writeLine(ChatColor.GREEN + "ヒット:" + num.incrementAndGet() + " " + url); - return; - } - try (InputStream is = connection.getInputStream(); - OutputStream os = new FileOutputStream(file)) - { - IOUtils.copy(is, os); - } - - - terminal.writeLine(ChatColor.GREEN + "取得:" + num.incrementAndGet() + - " " + url + " [" + Utils.roundSizeUnit(file.length()) + "]"); - } - catch (MalformedURLException e) - { - terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); - terminal.writeLine(ChatColor.RED + " '" + url + "' はURLではありません。"); - error.set(true); - } - catch (UnknownHostException e) - { - terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); - terminal.writeLine(ChatColor.RED + " '" + url + "' を解決できませんでした。"); - error.set(true); - } - catch (Exception e) - { - terminal.writeLine(ChatColor.RED + "エラー:" + num.incrementAndGet() + " " + url); - terminal.writeLine(ChatColor.RED + " エラー " + e.getClass().getName() + " が発生しました。"); - error.set(true); - e.printStackTrace(); - } - }); - - return new DownloadResult(paths, error.get(), System.currentTimeMillis() - start); - } - - private static void printDownloadMessage(Terminal terminal, DownloadResult result) - { - AtomicLong size = new AtomicLong(0); - - result.lists.values().stream().parallel().forEach(s -> size.addAndGet(new File(s).length())); - - double seconds = new BigDecimal(result.sec) - .divide(new BigDecimal("1000"), 2, RoundingMode.DOWN).doubleValue(); - - - terminal.writeLine( - ChatColor.LIGHT_PURPLE + - Utils.roundSizeUnit(size.get()) + - " を " + - seconds + - "秒 で取得しました (" + - Utils.roundSizeUnit(size.get() / ((long) seconds == 0 ? 1: (long) seconds)) + - "/s)" - ); - - } - - private static void doCleanUp(DownloadResult result) - { - result.lists.values().stream().parallel().forEach(s -> { - if (new File(s).exists()) - { - try - { - FileUtils.forceDelete(new File(s)); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - }); - } - - private static int doRegister(DownloadResult result) - { - AtomicInteger atomicInteger = new AtomicInteger(0); - - result.lists.entrySet().stream().parallel() - .forEach(s -> { - JsonObject obj; - try (BufferedReader reader = new BufferedReader(new FileReader(s.getValue()))) - { - obj = new Gson().fromJson(reader, JsonObject.class); - } - catch (Exception e) - { - e.printStackTrace(); - return; - } - - String source = s.getKey(); - - KnownPlugins.del(source); - for (Map.Entry a : obj.entrySet()) - { - String name = a.getKey(); - String url = a.getValue().getAsString(); - KnownPluginEntry ent = new KnownPluginEntry(name, url, source); - KnownPlugins.addKnownPlugin(ent); - atomicInteger.incrementAndGet(); - } - }); - - return atomicInteger.get(); - } - @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - if (!TeamKunPluginManager.getPlugin().getSession().lock()) - { - sender.sendMessage(ChatColor.RED + "E: TeamKunPluginManagerが多重起動しています。"); - return; - } + // TODO: Migrate to new config system + List> aliasSources = + TeamKunPluginManager.getPlugin().getPluginConfig().getMapList("config"); - if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) - { // TODO: Set level to warn - terminal.error("トークンが設定されていません!"); - terminal.info("/kpm register でトークンを発行することができます!"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - return; - } + @SuppressWarnings("unchecked") + HashMap aliasMap = aliasSources.stream() + .map(map -> (Map) map) + .map(map -> new Pair<>((String) map.get("name"), (String) map.get("url"))) + .collect(HashMap::new, (map, pair) -> map.put(pair.getLeft(), pair.getRight()), HashMap::putAll); - terminal.info("プラグインデータセットファイルのダウンロードを開始します..."); - - Runner.runAsync(() -> { - new File(TeamKunPluginManager.DATABASE_PATH).mkdirs(); - - DownloadResult downloadResult = doDownload(terminal); - printDownloadMessage(terminal, downloadResult); - sender.sendMessage(ChatColor.LIGHT_PURPLE + "リストを読み込んでいます..."); - - int aliases = doRegister(downloadResult); - - doCleanUp(downloadResult); - - if (downloadResult.errors) - terminal.warn("いくつかのエイリアスセットファイルのダウンロードに失敗しました。" + - "これらは無視されるか、古いものが代わりに使われます。"); - terminal.writeLine(ChatColor.GREEN + "項目数: " + aliases); - terminal.success("プラグイン定義ファイルのアップデートに成功しました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - }); + Runner.runAsync(() -> + TeamKunPluginManager.getPlugin().getInstallManager().runUpdate(terminal, new UpdateArgument( + aliasMap + )) + ); } @Override @@ -264,7 +52,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, @Override public TextComponent getHelpOneLine() { - return of("既知プラグインデータセットをアップデートします。"); + return of("エイリアスをアップデートします。"); } @Override @@ -272,18 +60,4 @@ public String[] getArguments() { return new String[0]; } - - private static class DownloadResult - { - public DownloadResult(Map lists, boolean errors, long sec) - { - this.lists = lists; - this.errors = errors; - this.sec = sec; - } - - public Map lists; - public boolean errors; - public long sec; - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index 2d21cab4..7d44410d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -2,9 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.CheckEnvSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.DownloadingSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.ModifySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DependenciesSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DownloadingSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.ResolverSignalHandler; @@ -12,6 +12,7 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallReadySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.update.UpdateAliasesSignalHandler; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -45,6 +46,7 @@ public static List getCommonHandlers(@NotNull Terminal terminal) { return createHandlersList( new CheckEnvSignalHandler(terminal), + new DownloadingSignalHandler(terminal), new ModifySignalHandler(terminal) ); } @@ -84,4 +86,12 @@ public static List getUninstallHandlers(@NotNull Terminal terminal) new UninstallFinishedSignalHandler(terminal) ); } + + public static List getUpdateHandlers(@NotNull Terminal terminal) + { + return createHandlersList( + getCommonHandlers(terminal), + new UpdateAliasesSignalHandler(terminal) + ); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java similarity index 99% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java rename to src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java index 65e6f9d5..81fc4a72 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DownloadingSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java new file mode 100644 index 00000000..1d9d08d8 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java @@ -0,0 +1,57 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.update; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.signals.UpdateFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.InvalidSourceSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; + +public class UpdateAliasesSignalHandler +{ + private final Terminal terminal; + + public UpdateAliasesSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onUpdateAliases(UpdateFinishedSignal signal) + { + terminal.success("エイリアスが更新されました。"); + terminal.success("登録数:%d", signal.getAliases()); + } + + @SignalHandler + public void onURLMalformed(MalformedURLSignal signal) + { + terminal.warn("不正なURLが指定されました(%s): %s", signal.getRemoteName(), signal.getRemoteURL()); + } + + @SignalHandler + public void onInvalidSources(InvalidSourceSignal signal) + { + switch (signal.getErrorCause()) + { + case IO_ERROR: + terminal.warn("不正なソースファイルが指定されました(%s):IOError", signal.getSourceName()); + break; + case SOURCE_FILE_MALFORMED: + terminal.warn("不正なソースファイルが指定されました(%s):Malformed", signal.getSourceName()); + break; + default: + terminal.warn("不正なソースファイルが指定されました(%s):Unknown", signal.getSourceName()); + } + } + + @SignalHandler + public void onInstallFinished(InstallFinishedSignal signal) + { + if (signal.getResult().isSuccess()) + terminal.success("エイリアスの更新に成功しました。"); + else + terminal.warn("エイリアスの更新に失敗しました。"); + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java index b963af92..bdb7ee09 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java @@ -25,10 +25,6 @@ public AliasUpdater(String sourceName, String sourceURL, AliasProvider provider) private void createCheckTable(String sourceName) { - if (!this.transaction.renew("SELECT name FROM source WHERE name = ?") - .isExists()) - return; - this.transaction.renew("CREATE TABLE v_exists_alias AS SELECT name FROM alias WHERE source_id = ?") .set(1, sourceName) .executeUpdate(false); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index a8130850..aa69b22c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -7,6 +7,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.AliasUpdater; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.UpdateArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; @@ -123,4 +125,31 @@ public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument runningInstall = null; } } + + public void runUpdate(@NotNull Terminal terminal, @NotNull UpdateArgument argument) + { + if (isRunning()) + { + terminal.error("他のインストーラが起動しています。"); + return; + } + + SignalHandleManager copiedHandleManager = signalHandleManager.copy(); + HeadSignalHandlers.getUpdateHandlers(terminal).forEach(copiedHandleManager::register); + + try + { + AliasUpdater updater = new AliasUpdater(copiedHandleManager); + runningInstall = updater.getProgress(); + + updater.run(argument); + } + catch (Exception e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました。"); + + runningInstall = null; + } + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java index 119985c2..bc7537dd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java @@ -88,7 +88,7 @@ private URL buildURL(String fallbackName, String urlString) return null; } - return null; + return url; } private HashMap> downloadSources(HashMap remotes) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java index 676f2706..dd964019 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java @@ -594,9 +594,10 @@ public void abortManually() /** * DBにレコードが存在するかどうかを確認します。 * + * @param closeConnection 終了時にコネクションを閉じるかどうか * @return 存在するかどうか */ - public boolean isExists() + public boolean isExists(boolean closeConnection) { if (!checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); @@ -619,7 +620,8 @@ public boolean isExists() { try { - this.connection.close(); + if (closeConnection) + this.connection.close(); } catch (SQLException e) { @@ -628,6 +630,16 @@ public boolean isExists() } } + /** + * DBにレコードが存在するかどうかを確認します。 + * + * @return 存在するかどうか + */ + public boolean isExists() + { + return isExists(true); + } + public void close() throws Exception { if (!this.connection.isClosed()) diff --git a/src/main/resources/config.v2.yml b/src/main/resources/config.v2.yml new file mode 100644 index 00000000..356d8836 --- /dev/null +++ b/src/main/resources/config.v2.yml @@ -0,0 +1,27 @@ +# 依存関係の名前解決に使用する組織名またはユーザ名 +gitHubName: [TeamKUN] + +#DBへのパス +dependPath: "/depend.db" +#名前解決へのパス +resolvePath: "/resolve.db" + +redirectLimit: 15 + +# エイリアス定義ファイル +# 形式: JSON +# 書き方: { "ExamplePlugin": "https://example.com/download/ExamplePlugin.jar" +# +# このconfigの書き方 +# - name: Example #設定の名前 +# url: https://example.com/example.json #設定のURL +# auth: true|false # 認証が必要かどうか(プライベートリポジトリの場合) +config: + - name: TeamKun HUB + url: "https://raw.githubusercontent.com/TeamKun/PluginManagerRepository/main/database.json" + auth: true +# 保護 +ignore: + - bStats #削除しないでください + - TeamKunPluginManager #削除しないでください + - PeyangPaperUtils #削除しないでください diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 356d8836..66ff9af5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -19,7 +19,6 @@ redirectLimit: 15 config: - name: TeamKun HUB url: "https://raw.githubusercontent.com/TeamKun/PluginManagerRepository/main/database.json" - auth: true # 保護 ignore: - bStats #削除しないでください From 313a7cf90f2bafa7d7c2cc212d6a1996f84496c9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 17:21:17 +0900 Subject: [PATCH 345/745] docs: fix invalid javadoc --- .../plugin/installer/impls/update/AliasUpdater.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java index bb946e72..1bdd02a8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java @@ -20,7 +20,8 @@ * エイリアスのアップデートは主に以下の流れで動作します。 * *
      - *
    1. {@link UpdateTasks#} - エイリアスのアップデート対象のプラグインを検索する。
    2. + *
    3. {@link UpdateTasks#DOWNLOADING_SOURCES} - ソースファイルをダウンロードする。
    4. + *
    5. {@link UpdateTasks#UPDATING_ALIASES} - エイリアスのアップデートを行う。
    6. *
    */ public class AliasUpdater extends AbstractInstaller From 9fc4b5dee485bfb3c265cf7750fc56e91f13ab08 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 18:29:33 +0900 Subject: [PATCH 346/745] feat: PluginUninstallSucceedResult --- .../PluginUninstallSucceedResult.java | 21 +++++++++++++++++++ .../impls/uninstall/PluginUninstaller.java | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstallSucceedResult.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstallSucceedResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstallSucceedResult.java new file mode 100644 index 00000000..e37805fc --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstallSucceedResult.java @@ -0,0 +1,21 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; + +/** + * プラグインのアンインストールの結果を表すクラスです。 + */ +@Getter +public class PluginUninstallSucceedResult extends InstallResult +{ + private final UnInstallResult result; + + public PluginUninstallSucceedResult(InstallProgress progress, UnInstallResult result) + { + super(true, progress); + this.result = result; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index b74343ed..4ca6c845 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -151,7 +151,7 @@ public InstallResult execute(@NotNull UninstallArgument argument .submitAll(new DependsComputeOrderArgument(computeOrderTarget)); // endregion - return this.success(); + return new PluginUninstallSucceedResult(this.progress, uninstallResult); } private Plugin getPlugin(String query) From 1a4c75b5a8807bbd1116981c83fce8c643c652d2 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 18:54:01 +0900 Subject: [PATCH 347/745] fix: Invalid translation --- .../signal/handlers/uninstall/UninstallReadySignalHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java index f7227aec..3772ba88 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -23,7 +23,7 @@ public UninstallReadySignalHandler(Terminal terminal) private void printUninstallInfo(List uninstallTargets) { - terminal.writeLine(ChatColor.GREEN + "以下のパッケージは「" + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); + terminal.writeLine(ChatColor.GREEN + "以下のプラグインは「" + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); terminal.writeLine(" " + uninstallTargets.stream() .map(Plugin::getName) .sorted() From 791fa0b81dc03dad46b1b85e30b4b4961b5ef32b Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 19:25:05 +0900 Subject: [PATCH 348/745] feat: AutoRemove head --- .../commands/CommandAutoRemove.java | 30 +---- .../commands/signal/HeadSignalHandlers.java | 13 ++ .../AutoRemoveFinishedSignalHandler.java | 49 ++++++++ .../AutoRemoveReadySignalHandler.java | 57 +++++++++ .../plugin/installer/AbstractInstaller.java | 11 ++ .../plugin/installer/InstallManager.java | 38 +++++- .../plugin/installer/InstallProgress.java | 80 +++++++++---- .../impls/autoremove/AutoRemoveArgument.java | 60 ++++++++++ .../autoremove/AutoRemoveErrorCause.java | 25 ++++ .../autoremove/AutoRemoveSucceedResult.java | 21 ++++ .../impls/autoremove/AutoRemoveTasks.java | 16 +++ .../impls/autoremove/PluginAutoRemover.java | 112 ++++++++++++++++++ .../signals/PluginEnumeratedSignal.java | 33 ++++++ .../signals/PluginUninstallFailedSignal.java | 18 +++ 14 files changed, 516 insertions(+), 47 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveSucceedResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveTasks.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginEnumeratedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 3c3fafe2..38cc4fb0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -4,46 +4,24 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveArgument; import net.kyori.adventure.text.TextComponent; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; public class CommandAutoRemove extends CommandBase { @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) - { // TODO: Separate frontend and backend - if (checkPermission(sender, terminal, "kpm.autoremove")) - sender.sendMessage(ChatColor.RED + "E: 権限がありません!"); - - AtomicInteger removed = new AtomicInteger(); - sender.sendMessage(ChatColor.LIGHT_PURPLE + "依存関係ツリーを読み込み中..."); - - List removables = TeamKunPluginManager.getPlugin().getPluginMetaManager() - .getProvider().getUnusedPlugins(); - if (removables.isEmpty()) - { - sender.sendMessage(ChatColor.RED + "E: 削除可能なプラグインはありません。"); - sender.sendMessage(Messages.getStatusMessage(0, removed.get(), 0)); - sender.sendMessage(ChatColor.GREEN + "S: 操作が正常に完了しました。"); - TeamKunPluginManager.getPlugin().getSession().unlock(); - return; - } + { + TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); Runner.runAsync(() -> - TeamKunPluginManager.getPlugin().getInstallManager().runUninstall( - terminal, - new UninstallArgument(removables.toArray(new String[0])) - ) + kpmInstance.getInstallManager().runAutoRemove(terminal, new AutoRemoveArgument()) ); - } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index 7d44410d..da7d0ca8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -1,6 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove.AutoRemoveFinishedSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove.AutoRemoveReadySignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.CheckEnvSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.DownloadingSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.ModifySignalHandler; @@ -94,4 +96,15 @@ public static List getUpdateHandlers(@NotNull Terminal terminal) new UpdateAliasesSignalHandler(terminal) ); } + + public static List getAutoRemoveHandlers(@NotNull Terminal terminal) + { + return createHandlersList( + getCommonHandlers(terminal), + new UninstallerSignalHandler(terminal), + new AutoRemoveFinishedSignalHandler(terminal), + new UninstallFinishedSignalHandler(terminal), + new AutoRemoveReadySignalHandler(terminal) + ); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java new file mode 100644 index 00000000..4e8f1eeb --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java @@ -0,0 +1,49 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveErrorCause; + +public class AutoRemoveFinishedSignalHandler extends InstallFinishedSignalBase +{ + public AutoRemoveFinishedSignalHandler(Terminal terminal) + { + super(terminal); + } + + @Override + protected void onSuccess(InstallResult result) + { + this.terminal.success("プラグインの自動削除が完了しました。"); + } + + private void handleAutoRemoveErrors(AutoRemoveErrorCause cause) + { + switch (cause) + { + case UNINSTALLER_INIT_FAILED: + this.terminal.warn("アンインストーラーの初期化に失敗しました。"); + break; + case UNINSTALL_FAILED: + this.terminal.warn("プラグインのアンインストールに失敗しました。"); + break; + case NO_AUTO_REMOVABLE_PLUGIN_FOUND: + this.terminal.warn("自動削除が可能なプラグインが見つかりませんでした。"); + break; + case CANCELLED: + this.terminal.warn("自動削除がキャンセルされました。"); + break; + } + } + + @Override + protected void onFail(InstallFailedInstallResult result) + { + if (result.getReason() != null && result.getReason() instanceof AutoRemoveErrorCause) + this.handleAutoRemoveErrors((AutoRemoveErrorCause) result.getReason()); + + this.terminal.error("プラグインの自動削除に失敗しました。"); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java new file mode 100644 index 00000000..68cbe89c --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java @@ -0,0 +1,57 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.utils.Utils; +import org.bukkit.ChatColor; + +import java.util.List; +import java.util.stream.Collectors; + +public class AutoRemoveReadySignalHandler +{ + private final Terminal terminal; + + public AutoRemoveReadySignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + private void printUninstallInfo(List uninstallTargets) + { + this.terminal.writeLine( + ChatColor.GREEN + "以下のプラグインが自動でインストールされましたが、もう必要とされていません:"); + this.terminal.writeLine( + ChatColor.GREEN + "以下のプラグインは「" + + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); + this.terminal.writeLine(" " + uninstallTargets.stream() + .sorted() + .collect(Collectors.joining(" "))); + Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); + } + + private boolean pollContinue() + { + try + { + QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?").waitAndGetResult(); + return result.test(QuestionAttribute.YES); + } + catch (InterruptedException e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました: " + e.getMessage()); + return false; + } + } + + @SignalHandler + public void onPluginEnumerated(PluginEnumeratedSignal signal) + { + this.printUninstallInfo(signal.getTargetPlugins()); + signal.setCancel(!this.pollContinue()); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java index 3ec8a2cd..507acdbe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java @@ -56,6 +56,17 @@ protected InstallResult

    success() return result; } + @NotNull + protected InstallResult

    success(InstallResult

    customResult) + { + if (!customResult.isSuccess()) + throw new IllegalArgumentException("customResult must be success."); + + this.postSignal(new InstallFinishedSignal(customResult)); + + return customResult; + } + public > InstallFailedInstallResult error(@NotNull T reason) { // TODO: Implement debug mode InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, reason); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index aa69b22c..a6d56a30 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -3,6 +3,8 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.commands.signal.HeadSignalHandlers; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.PluginAutoRemover; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; @@ -99,7 +101,7 @@ public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argu * @throws IllegalStateException インストールが進行中の場合 * @throws IOException 予期しない例外が発生した場合 */ - public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument argument) throws IllegalStateException, IOException + public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument argument) throws IllegalStateException { if (isRunning()) { @@ -152,4 +154,38 @@ public void runUpdate(@NotNull Terminal terminal, @NotNull UpdateArgument argume runningInstall = null; } } + + /** + * プラグインの自動削除を実行します。 + * + * @param terminal ターミナル + * @param argument 自動削除の引数 + */ + public void runAutoRemove(@NotNull Terminal terminal, @NotNull AutoRemoveArgument argument) + { + if (isRunning()) + { + terminal.error("他のインストーラが起動しています。"); + return; + } + + SignalHandleManager copiedHandleManager = signalHandleManager.copy(); + HeadSignalHandlers.getAutoRemoveHandlers(terminal).forEach(copiedHandleManager::register); + + try + { + PluginAutoRemover remover = new PluginAutoRemover(copiedHandleManager); + runningInstall = remover.getProgress(); + + remover.run(argument); + + } + catch (Exception e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました。"); + + runningInstall = null; + } + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index abedf71b..15a8bb07 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -166,16 +166,18 @@ private void removeFromAll(@NotNull String name) * プラグインがアップグレードされたとしてマークします。 * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#UPGRADE} の {@link PluginModifiedSignal} をスローします。 * - * @param pluginDescription アップグレードされたプラグインの {@link PluginDescriptionFile} + * @param pluginDescription アップグレードされたプラグインの {@link PluginDescriptionFile} + * @param postModifiedSignal {@link PluginModifiedSignal} をスローするかどうか */ - public void addUpgraded(@NotNull PluginDescriptionFile pluginDescription) + public void addUpgraded(@NotNull PluginDescriptionFile pluginDescription, boolean postModifiedSignal) { this.removeFromAll(pluginDescription.getName()); - this.signalHandler.handleSignal( - this, - new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.UPGRADE) - ); + if (postModifiedSignal) + this.signalHandler.handleSignal( + this, + new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.UPGRADE) + ); this.upgraded.add(pluginDescription.getName()); } @@ -183,18 +185,18 @@ public void addUpgraded(@NotNull PluginDescriptionFile pluginDescription) * プラグインが新規にインストールされたとしてマークします。 * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#ADD} の {@link PluginModifiedSignal} をスローします。 * - * @param pluginDescription 新規にインストールされたプラグインの {@link PluginDescriptionFile} + * @param pluginDescription 新規にインストールされたプラグインの {@link PluginDescriptionFile} + * @param postModifiedSignal {@link PluginModifiedSignal} をスローするかどうか */ - public void addInstalled(@NotNull PluginDescriptionFile pluginDescription) + public void addInstalled(@NotNull PluginDescriptionFile pluginDescription, boolean postModifiedSignal) { this.removeFromAll(pluginDescription.getName()); - this.signalHandler.handleSignal( - this, - new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.ADD) - ); - - + if (postModifiedSignal) + this.signalHandler.handleSignal( + this, + new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.ADD) + ); this.installed.add(pluginDescription.getName()); } @@ -202,19 +204,57 @@ public void addInstalled(@NotNull PluginDescriptionFile pluginDescription) * プラグインが削除されたとしてマークします。 * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#REMOVE} の {@link PluginModifiedSignal} をスローします。 * - * @param pluginDescription 削除されたプラグインの {@link PluginDescriptionFile} + * @param pluginDescription 削除されたプラグインの {@link PluginDescriptionFile} + * @param postModifiedSignal {@link PluginModifiedSignal} をスローするかどうか */ - public void addRemoved(@NotNull PluginDescriptionFile pluginDescription) + public void addRemoved(@NotNull PluginDescriptionFile pluginDescription, boolean postModifiedSignal) { this.removeFromAll(pluginDescription.getName()); - this.signalHandler.handleSignal( - this, - new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.REMOVE) - ); + if (postModifiedSignal) + this.signalHandler.handleSignal( + this, + new PluginModifiedSignal(pluginDescription, PluginModifiedSignal.ModifyType.REMOVE) + ); this.removed.add(pluginDescription.getName()); } + /** + * プラグインがアップグレードされたとしてマークします。 + * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#UPGRADE} の {@link PluginModifiedSignal} をスローします。 + * + * @param pluginDescription アップグレードされたプラグインの {@link PluginDescriptionFile} + * @see #addUpgraded(PluginDescriptionFile, boolean) + */ + public void addUpgraded(@NotNull PluginDescriptionFile pluginDescription) + { + this.addUpgraded(pluginDescription, true); + } + + /** + * プラグインが新規にインストールされたとしてマークします。 + * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#ADD} の {@link PluginModifiedSignal} をスローします。 + * + * @param pluginDescription 新規にインストールされたプラグインの {@link PluginDescriptionFile} + * @see #addInstalled(PluginDescriptionFile, boolean) + */ + public void addInstalled(@NotNull PluginDescriptionFile pluginDescription) + { + this.addInstalled(pluginDescription, true); + } + + /** + * プラグインが削除されたとしてマークします。 + * {@link PluginModifiedSignal#getModifyType()} が {@link PluginModifiedSignal.ModifyType#REMOVE} の {@link PluginModifiedSignal} をスローします。 + * + * @param pluginDescription 削除されたプラグインの {@link PluginDescriptionFile} + * @see #addRemoved(PluginDescriptionFile, boolean) + */ + public void addRemoved(@NotNull PluginDescriptionFile pluginDescription) + { + this.addRemoved(pluginDescription, true); + } + /** * プラグインが保留されたとしてマークします。 * diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveArgument.java new file mode 100644 index 00000000..171644e6 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveArgument.java @@ -0,0 +1,60 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * 自動削除の引数を格納するクラスです。 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class AutoRemoveArgument extends AbstractInstallerArgument +{ + /** + * 自動削除から除外するプラグインのリストです。 + */ + @NotNull + private final List excludePlugins; + + private AutoRemoveArgument(@NotNull List excludePlugins) + { + this.excludePlugins = excludePlugins; + } + + public AutoRemoveArgument() + { + this(new ArrayList<>()); + } + + /** + * 除外するプラグインを追加します。 + * + * @param pluginName 除外するプラグインの名前 + * @return このインスタンス + */ + public AutoRemoveArgument addExcludePlugin(@NotNull String pluginName) + { + excludePlugins.add(pluginName); + return this; + } + + /** + * 除外するプラグインを追加します。 + * + * @param plugin 除外するプラグイン + * @return このインスタンス + */ + public AutoRemoveArgument addExcludePlugin(@NotNull Plugin plugin) + { + this.addExcludePlugin(plugin.getName()); + return this; + } + + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveErrorCause.java new file mode 100644 index 00000000..1bf84bbf --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveErrorCause.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; + +/** + * 自動削除のエラーを表す列挙型です。 + */ +public enum AutoRemoveErrorCause +{ + /** + * 自動削除が可能なプラグインが見つかりませんでした。 + */ + NO_AUTO_REMOVABLE_PLUGIN_FOUND, + + /** + * アンインストーラの初期化に失敗しました。 + */ + UNINSTALLER_INIT_FAILED, + /** + * アンインストールに失敗しました。 + */ + UNINSTALL_FAILED, + /** + * 自動削除がキャンセルされました。 + */ + CANCELLED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveSucceedResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveSucceedResult.java new file mode 100644 index 00000000..9fc5bb93 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveSucceedResult.java @@ -0,0 +1,21 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; + +import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; + +/** + * プラグインのアンインストールの結果を表すクラスです。 + */ +@Getter +public class AutoRemoveSucceedResult extends InstallResult +{ + private final UnInstallResult result; + + public AutoRemoveSucceedResult(InstallProgress progress, UnInstallResult result) + { + super(true, progress); + this.result = result; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveTasks.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveTasks.java new file mode 100644 index 00000000..e67db105 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveTasks.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; + +/** + * 自動削除のタスクを表す列挙型です。 + */ +public enum AutoRemoveTasks +{ + /** + * 削除対象のプラグインを取得します。 + */ + SEARCHING_REMOVABLES, + /** + * 削除対象のプラグインを削除します。 + */ + UNINSTALLING_PLUGINS +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java new file mode 100644 index 00000000..7e8aa25e --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java @@ -0,0 +1,112 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; + +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginUninstallFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstallSucceedResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * プラグインを自動削除するインストーラーの実装です。 + * 自動削除は主に以下の流れで動作します。 + * + *

      + *
    1. {@link AutoRemoveTasks#} - 自動削除対象のプラグインを検索する。
    2. + *
    + */ +public class PluginAutoRemover extends AbstractInstaller +{ + private static final PluginMetaProvider META_PROVIDER; + + static + { + META_PROVIDER = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider(); + } + + public PluginAutoRemover(SignalHandleManager signalHandler) throws IOException + { + super(signalHandler); + } + + @Override + public InstallResult execute(@NotNull AutoRemoveArgument argument) throws TaskFailedException + { + ArrayList targetPlugins; + // region Enumerate plugins to be removed + this.progress.setCurrentTask(AutoRemoveTasks.SEARCHING_REMOVABLES); + + List excludePlugins = argument.getExcludePlugins().stream().parallel() + .map(String::toLowerCase) + .collect(Collectors.toList()); + + targetPlugins = (ArrayList) META_PROVIDER.getUnusedPlugins() + .stream() + .parallel() + .filter(unusedPluginName -> !excludePlugins.contains(unusedPluginName.toLowerCase())) + .collect(Collectors.toList()); + + if (targetPlugins.isEmpty()) + return this.error(AutoRemoveErrorCause.NO_AUTO_REMOVABLE_PLUGIN_FOUND); + + PluginEnumeratedSignal signal = new PluginEnumeratedSignal(targetPlugins); + this.postSignal(signal); + if (signal.isCancel()) + return this.error(AutoRemoveErrorCause.CANCELLED); + + // Target plugins may be changed by signal handler. + targetPlugins = new ArrayList<>(signal.getTargetPlugins()); + + if (targetPlugins.isEmpty()) + return this.error(AutoRemoveErrorCause.NO_AUTO_REMOVABLE_PLUGIN_FOUND); + + // endregion + + // region Do uninstall + this.progress.setCurrentTask(AutoRemoveTasks.UNINSTALLING_PLUGINS); + + PluginUninstaller uninstaller; + try + { + uninstaller = new PluginUninstaller(this.signalHandler); + } + catch (IOException e) + { + e.printStackTrace(); + return this.error(AutoRemoveErrorCause.UNINSTALLER_INIT_FAILED); + } + + UninstallArgument uninstallArgument = new UninstallArgument(targetPlugins.toArray(new String[0])); + + InstallResult uninstallResult = uninstaller.execute(uninstallArgument); + + if (!uninstallResult.isSuccess()) + { + this.postSignal(new PluginUninstallFailedSignal(uninstallResult)); + return this.error(AutoRemoveErrorCause.UNINSTALL_FAILED); + } + + UnInstallResult unInstallResult = ((PluginUninstallSucceedResult) uninstallResult).getResult(); + List uninstalledPlugins = unInstallResult.getUninstalledPlugins(); + + uninstalledPlugins.forEach(pluginDescription -> this.progress.addRemoved(pluginDescription, false)); + + // endregion + + return this.success(new AutoRemoveSucceedResult(this.progress, unInstallResult)); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginEnumeratedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginEnumeratedSignal.java new file mode 100644 index 00000000..3e3ad9f9 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginEnumeratedSignal.java @@ -0,0 +1,33 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; + +/** + * 自動削除するプラグインが列挙された場合に送信されるシグナルです。 + */ +@Data +public class PluginEnumeratedSignal implements Signal +{ + /** + * 自動削除するプラグインのリストです。 + * このリストを変更すると、自動削除の対象を変更できます。 + */ + @NotNull + private final ArrayList targetPlugins; + + /** + * 自動削除をキャンセルするかどうかを示すフラグです。 + * このフラグがtrueの場合、自動削除はキャンセルされます。 + */ + private boolean cancel; + + public PluginEnumeratedSignal(@NotNull ArrayList targetPlugins) + { + this.targetPlugins = targetPlugins; + this.cancel = false; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java new file mode 100644 index 00000000..95babd12 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java @@ -0,0 +1,18 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +/** + * アンインストールに失敗したときに送信されるシグナルです。 + */ +@Value +public class PluginUninstallFailedSignal implements Signal +{ + /** + * アンインストールに失敗したときの結果です。 + */ + InstallResult result; +} From cddcc183e595b5b9cad555cd9b7ec23fbc31f6ef Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 23:08:19 +0900 Subject: [PATCH 349/745] refactor: Make SignalHandlingUtils.askContinue(terminal) --- .../commands/signal/SignalHandlingUtils.java | 23 ++++++++++++++ .../AutoRemoveReadySignalHandler.java | 19 ++---------- .../common/CheckEnvSignalHandler.java | 31 ++----------------- .../UninstallReadySignalHandler.java | 19 ++---------- 4 files changed, 30 insertions(+), 62 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java new file mode 100644 index 00000000..ff78818b --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; +import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; + +public class SignalHandlingUtils +{ + public static boolean askContinue(Terminal terminal) + { + try + { + QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?").waitAndGetResult(); + return result.test(QuestionAttribute.YES); + } + catch (InterruptedException e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました: " + e.getMessage()); + return false; + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java index 68cbe89c..465a9da5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; @@ -33,25 +32,11 @@ private void printUninstallInfo(List uninstallTargets) Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); } - private boolean pollContinue() - { - try - { - QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?").waitAndGetResult(); - return result.test(QuestionAttribute.YES); - } - catch (InterruptedException e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました: " + e.getMessage()); - return false; - } - } @SignalHandler public void onPluginEnumerated(PluginEnumeratedSignal signal) { this.printUninstallInfo(signal.getTargetPlugins()); - signal.setCancel(!this.pollContinue()); + signal.setCancel(!SignalHandlingUtils.askContinue(terminal)); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java index 5bb87a87..41cc1fa4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; @@ -30,19 +29,7 @@ public void onPluginIsIgnored(IgnoredPluginSignal signal) terminal.writeLine(ChatColor.DARK_RED + "W: 強制的なインストールは予期しない問題を引き起こす可能性があります。"); - try - { - QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?") - .waitAndGetResult(); - - boolean continueInstall = result.test(QuestionAttribute.YES); - - signal.setCancelInstall(!continueInstall); - } - catch (InterruptedException ex) - { - ex.printStackTrace(); - } + signal.setCancelInstall(!SignalHandlingUtils.askContinue(terminal)); } private void printKeyValue(String key, String value) @@ -66,18 +53,6 @@ public void onPluginIsDuplicated(AlreadyInstalledPluginSignal signal) terminal.writeLine(ChatColor.BLUE + "== インストールしようとしているプラグイン =="); printPluginInfo(signal.getInstallingPlugin()); - try - { - QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?") - .waitAndGetResult(); - - boolean continueInstall = result.test(QuestionAttribute.YES); - - signal.setReplacePlugin(continueInstall); - } - catch (InterruptedException ex) - { - ex.printStackTrace(); - } + signal.setReplacePlugin(SignalHandlingUtils.askContinue(terminal)); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java index 3772ba88..0c3f45e9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -1,8 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.UninstallReadySignal; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; @@ -31,25 +30,11 @@ private void printUninstallInfo(List uninstallTargets) Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); } - private boolean pollContinue() - { - try - { - QuestionResult result = terminal.getInput().showYNQuestion("続行しますか?").waitAndGetResult(); - return result.test(QuestionAttribute.YES); - } - catch (InterruptedException e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました: " + e.getMessage()); - return false; - } - } @SignalHandler public void onPluginsEnumerated(UninstallReadySignal signal) { printUninstallInfo(signal.getPlugins()); - signal.setContinueUninstall(pollContinue()); + signal.setContinueUninstall(SignalHandlingUtils.askContinue(terminal)); } } From 3c7c128f402fc707ef05cec54839fee97a2b98c9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 23:51:12 +0900 Subject: [PATCH 350/745] feat: Garbage cleaner --- .../commands/CommandClean.java | 87 ++------------ .../commands/signal/HeadSignalHandlers.java | 11 ++ .../GarbageCleanFinishedSignalHandler.java | 48 ++++++++ .../clean/GarbageCleanSignalHandler.java | 42 +++++++ .../plugin/installer/InstallManager.java | 36 ++++++ .../plugin/installer/InstallProgress.java | 36 ++++++ .../installer/impls/clean/CleanArgument.java | 46 ++++++++ .../impls/clean/CleanErrorCause.java | 8 ++ .../installer/impls/clean/CleanTasks.java | 16 +++ .../clean/GarbageCleanSucceedResult.java | 37 ++++++ .../installer/impls/clean/GarbageCleaner.java | 83 +++++++++++++ .../garbage/clean/GarbageCleanArgument.java | 23 ++++ .../garbage/clean/GarbageCleanErrorCause.java | 25 ++++ .../garbage/clean/GarbageCleanResult.java | 29 +++++ .../garbage/clean/GarbageCleanState.java | 16 +++ .../tasks/garbage/clean/GarbageCleanTask.java | 109 ++++++++++++++++++ .../signal/GarbageDeleteSkippedSignal.java | 20 ++++ .../clean/signal/GarbageDeletingSignal.java | 52 +++++++++ .../clean/signal/GarbageEnumeratedSignal.java | 23 ++++ .../clean/signal/InvalidIntegritySignal.java | 11 ++ .../garbage/search/GarbageSearchArgument.java | 51 ++++++++ .../search/GarbageSearchErrorCause.java | 12 ++ .../garbage/search/GarbageSearchResult.java | 39 +++++++ .../garbage/search/GarbageSearchState.java | 16 +++ .../garbage/search/GarbageSearchTask.java | 63 ++++++++++ .../signals/GarbageSearchingSignal.java | 18 +++ 26 files changed, 877 insertions(+), 80 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanTasks.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleanSucceedResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleaner.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchArgument.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchResult.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchState.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchTask.java create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index 6c85645a..4ea2a896 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -1,23 +1,15 @@ package net.kunmc.lab.teamkunpluginmanager.commands; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.Installer; -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean.CleanArgument; import net.kyori.adventure.text.TextComponent; -import org.apache.commons.lang.ArrayUtils; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; public class CommandClean extends CommandBase @@ -27,78 +19,15 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - if (!kpmInstance.getSession().lock()) - { - terminal.error("TeamKunPluginManagerが多重起動しています。"); - return; - } - - terminal.info("依存関係ツリーを読み込み中..."); - - String[] removable = Installer.getRemovableDataDirs(); - if (removable.length == 0) - { - terminal.info("削除可能な項目が見つかりませんでした。"); - kpmInstance.getSession().unlock(); - return; - } - - String pluginName = null; - if (args.length > 0 && !args[0].equals("all")) - pluginName = args[0]; - - if (pluginName != null) - if (ArrayUtils.contains(removable, pluginName)) - removable = new String[]{pluginName}; - else - { - terminal.error("指定されたプラグインのデータフォルダが見つかりませんでした。"); - kpmInstance.getSession().unlock(); - return; - } - - // TODO: aptっぽく、スキャンで引っかかったプラグインのリストを表示する - - terminal.writeLine(ChatColor.GREEN + "この操作で、以下の" + removable.length + "つのプラグインデータが削除されます: "); - terminal.writeLine(ChatColor.AQUA + String.join(", ", removable)); - - String[] finalRemovable = removable; - Runner.runAsync(() -> { - QuestionResult result = terminal.getInput(). - showQuestion("本当に続行しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) - .waitAndGetResult(); - - if (result.test(QuestionAttribute.CANCELLABLE)) - terminal.error("キャンセルしました。"); - else if (result.test(QuestionAttribute.YES)) - removeDatas(terminal, finalRemovable); - - kpmInstance.getSession().unlock(); - }, (exception, bukkitTask) -> { - }); - - } - - private void removeDatas(Terminal terminal, String[] removables) - { - for (String removable : removables) - { - terminal.info(removable + " を削除しています..."); - Installer.clean(removable); - } - - terminal.writeLine(Messages.getStatusMessage(0, removables.length, 0)); + Runner.runAsync(() -> + kpmInstance.getInstallManager().runGarbageClean(terminal, new CleanArgument()) + ); } @Override public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - List list = new ArrayList<>(Collections.singleton("all")); - - if (args.length == 1) - list.addAll(Arrays.asList(Installer.getRemovableDataDirs())); - - return list; + return null; } @Override @@ -110,14 +39,12 @@ private void removeDatas(Terminal terminal, String[] removables) @Override public TextComponent getHelpOneLine() { - return of("削除されて使用されなくなったプラグインのデータフォルダを再帰的に削除します。"); + return of("削除されて残ったプラグインの不要データを自動削除します。"); } @Override public String[] getArguments() { - return new String[]{ - optional("name", "プラグイン名", "all"), - }; + return new String[0]; } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java index da7d0ca8..cdfc38ac 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java @@ -3,6 +3,8 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove.AutoRemoveFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove.AutoRemoveReadySignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean.GarbageCleanFinishedSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean.GarbageCleanSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.CheckEnvSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.DownloadingSignalHandler; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.ModifySignalHandler; @@ -107,4 +109,13 @@ public static List getAutoRemoveHandlers(@NotNull Terminal terminal) new AutoRemoveReadySignalHandler(terminal) ); } + + public static List getGarbageCleanHandlers(Terminal terminal) + { + return createHandlersList( + getCommonHandlers(terminal), + new GarbageCleanFinishedSignalHandler(terminal), + new GarbageCleanSignalHandler(terminal) + ); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java new file mode 100644 index 00000000..4d8a2517 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java @@ -0,0 +1,48 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanErrorCause; + +public class GarbageCleanFinishedSignalHandler extends InstallFinishedSignalBase +{ + public GarbageCleanFinishedSignalHandler(Terminal terminal) + { + super(terminal); + } + + @Override + protected void onSuccess(InstallResult result) + { + this.terminal.success("不要データの削除に成功しました。"); + } + + private void handleGarbageCleanErrors(GarbageCleanErrorCause cause) + { + switch (cause) + { + case CANCELLED: + this.terminal.warn("不要データの削除がキャンセルされました。"); + break; + case ALL_DELETE_FAILED: + this.terminal.warn("すべての不要データの削除に失敗しました。"); + break; + case INVALID_INTEGRITY: + this.terminal.warn("ファイル・システムとの不整合が発生したため、システムが保護されました。"); + break; + case NO_GARBAGE: + this.terminal.warn("不要データが見つかりませんでした。"); + break; + } + } + + @Override + protected void onFail(InstallFailedInstallResult result) + { + if (result.getReason() != null && result.getReason() instanceof GarbageCleanErrorCause) + this.handleGarbageCleanErrors((GarbageCleanErrorCause) result.getReason()); + this.terminal.error("不要データの削除に失敗しました。"); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java new file mode 100644 index 00000000..cbe09e09 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java @@ -0,0 +1,42 @@ +package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import org.bukkit.ChatColor; + +import java.util.stream.Collectors; + +public class GarbageCleanSignalHandler +{ + // ignore GarbageDeleteSkippedSignal + + private final Terminal terminal; + + public GarbageCleanSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onGarbageEnumerated(GarbageEnumeratedSignal signal) + { + this.terminal.writeLine( + ChatColor.GREEN + "以下の未使用データは「" + + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); + this.terminal.writeLine(" " + signal.getGarbageDatas().stream() + .sorted() + .map(path -> path.getFileName().toString()) + .collect(Collectors.joining(" "))); + + signal.setCancel(!SignalHandlingUtils.askContinue(terminal)); + } + + @SignalHandler + public void onGarbageSearching(GarbageSearchingSignal signal) + { + this.terminal.info("不要データを検索しています ..."); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index a6d56a30..566db7a4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -5,6 +5,8 @@ import net.kunmc.lab.teamkunpluginmanager.commands.signal.HeadSignalHandlers; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.PluginAutoRemover; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean.CleanArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean.GarbageCleaner; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; @@ -188,4 +190,38 @@ public void runAutoRemove(@NotNull Terminal terminal, @NotNull AutoRemoveArgumen runningInstall = null; } } + + /** + * 不要データ(ガベージ)の削除を実行します。 + * + * @param terminal ターミナル + * @param argument 不要データ削除の引数 + * @throws IllegalStateException インストールが進行中の場合 + */ + public void runGarbageClean(@NotNull Terminal terminal, @NotNull CleanArgument argument) throws IllegalStateException + { + if (isRunning()) + { + terminal.error("他のインストーラが起動しています。"); + return; + } + + SignalHandleManager copiedHandleManager = signalHandleManager.copy(); + HeadSignalHandlers.getGarbageCleanHandlers(terminal).forEach(copiedHandleManager::register); + + try + { + GarbageCleaner collector = new GarbageCleaner(copiedHandleManager); + runningInstall = collector.getProgress(); + + collector.run(argument); + } + catch (Exception e) + { + e.printStackTrace(); + terminal.error("不明なエラーが発生しました。"); + + runningInstall = null; + } + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java index 15a8bb07..29f04581 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java @@ -267,6 +267,42 @@ public void addPending(@NotNull String pluginName) this.pending.add(pluginName); } + /** + * アップグレードされたとしてマークします。 + * + * @param targetName アップグレードされた物の名前または識別子 + */ + public void addUpgraded(@NotNull String targetName) + { + this.removeFromAll(targetName); + + this.upgraded.add(targetName); + } + + /** + * 新規にインストールされたとしてマークします。 + * + * @param targetName 新規にインストールされた物の名前または識別子 + */ + public void addInstalled(@NotNull String targetName) + { + this.removeFromAll(targetName); + + this.installed.add(targetName); + } + + /** + * 削除されたとしてマークします。 + * + * @param targetName 削除された物の名前または識別子 + */ + public void addRemoved(@NotNull String targetName) + { + this.removeFromAll(targetName); + + this.removed.add(targetName); + } + /** * インストールが完了したとしてマークし、インストールに使用された仮ディレクトリを削除します。 */ diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanArgument.java new file mode 100644 index 00000000..05111e25 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanArgument.java @@ -0,0 +1,46 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * 不要データ削除の引数を格納するクラスです。 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CleanArgument extends AbstractInstallerArgument +{ + /** + * 自動削除から除外するデータ名のリストです。 + */ + @NotNull + private final List excludeDataNames; + + private CleanArgument(@NotNull List excludeDataNames) + { + this.excludeDataNames = excludeDataNames; + } + + public CleanArgument() + { + this(new ArrayList<>()); + } + + /** + * 除外するデータを追加します。 + * + * @param dataName 除外するデータの名前 + * @return このインスタンス + */ + public CleanArgument addExcludeDataName(@NotNull String dataName) + { + excludeDataNames.add(dataName); + return this; + } + +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanErrorCause.java new file mode 100644 index 00000000..5fb5243f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanErrorCause.java @@ -0,0 +1,8 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; + +/** + * 不要データ削除のエラーを表す列挙型です。 + */ +public enum CleanErrorCause +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanTasks.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanTasks.java new file mode 100644 index 00000000..cb055258 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanTasks.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; + +/** + * 不要データ削除のタスクを表す列挙型です。 + */ +public enum CleanTasks +{ + /** + * 不要データを検索します。 + */ + SEARCHING_GARBAGE, + /** + * 不要データの削除中です。 + */ + DELETING_GARBAGE, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleanSucceedResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleanSucceedResult.java new file mode 100644 index 00000000..122b6607 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleanSucceedResult.java @@ -0,0 +1,37 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; +import java.util.List; + +/** + * 不要なデータの削除に成功したことを表す結果です。 + */ +@Value +@EqualsAndHashCode(callSuper = false) +public class GarbageCleanSucceedResult extends InstallResult +{ + /** + * 削除された不要なデータのパスのリストです。 + */ + @NotNull + List deletedFiles; + /** + * 削除に失敗した不要なデータのパスのリストです。 + */ + @NotNull + List deleteFailedFiles; + + public GarbageCleanSucceedResult(InstallProgress progress, + @NotNull List deletedFiles, @NotNull List deleteFailedFiles) + { + super(true, progress); + this.deletedFiles = deletedFiles; + this.deleteFailedFiles = deleteFailedFiles; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleaner.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleaner.java new file mode 100644 index 00000000..7775bca4 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleaner.java @@ -0,0 +1,83 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; + +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.GarbageSearchArgument; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.GarbageSearchTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * プラグインの不要データ削除するインストーラーの実装です。 + * 不要データ削除は主に以下の流れで動作します。 + * + *
      + *
    1. {@link CleanTasks#SEARCHING_GARBAGE} - 不要データを検索する。
    2. + *
    3. {@link CleanTasks#DELETING_GARBAGE} - 不要データを削除する。
    4. + *
    + */ +public class GarbageCleaner extends AbstractInstaller +{ + private static final Path PLUGIN_DIR; + + static + { + PLUGIN_DIR = TeamKunPluginManager.getPlugin().getDataFolder().toPath().getParent(); + } + + public GarbageCleaner(SignalHandleManager signalHandler) throws IOException + { + super(signalHandler); + } + + @Override + public InstallResult execute(@NotNull CleanArgument argument) throws TaskFailedException + { + List excludeDataNames = argument.getExcludeDataNames(); + excludeDataNames.addAll(TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore")); + List plugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName) + .collect(Collectors.toList()); + + GarbageCleanResult result = (GarbageCleanResult) this.submitter( + CleanTasks.SEARCHING_GARBAGE, + new GarbageSearchTask(this.progress, this.signalHandler) + ) + .then( + CleanTasks.DELETING_GARBAGE, + new GarbageCleanTask(this.progress, this.signalHandler) + ) + .bridgeArgument(searchResult -> + new GarbageCleanArgument(searchResult.getGarbageFiles())) + .submitAll(new GarbageSearchArgument(excludeDataNames, PLUGIN_DIR, plugins)); + + List deleted = new ArrayList<>(); + List failed = new ArrayList<>(); + + result.getDeletedGarbage().forEach((key, value) -> { + if (value) + { + deleted.add(key); + this.progress.addRemoved(key.getFileName().toString()); + } + else + failed.add(key); + }); + + return this.success(new GarbageCleanSucceedResult(this.progress, deleted, failed)); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanArgument.java new file mode 100644 index 00000000..367b8f8f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanArgument.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; +import java.util.List; + +/** + * 不要データ削除を行うタスクの引数です。 + */ +@Value +@EqualsAndHashCode(callSuper = false) +public class GarbageCleanArgument extends TaskArgument +{ + /** + * 不要データとして削除するディレクトリ・ファイルのパスです。 + */ + @NotNull + List paths; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java new file mode 100644 index 00000000..8e8c936f --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; + +/** + * 不要データ削除のエラーを表す列挙型です。 + */ +public enum GarbageCleanErrorCause +{ + /** + * キャンセルされました。 + */ + CANCELLED, + /** + * 不要データが存在しません。 + */ + NO_GARBAGE, + + /** + * すべての削除に失敗しました。 + */ + ALL_DELETE_FAILED, + /** + * ファイル・システムとの整合性が取れなく、スキップされました。 + */ + INVALID_INTEGRITY, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanResult.java new file mode 100644 index 00000000..a80cdffb --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanResult.java @@ -0,0 +1,29 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; +import java.util.HashMap; + +/** + * 不要データ削除を行うタスクの結果です。 + */ +@Value +@EqualsAndHashCode(callSuper = true) +public class GarbageCleanResult extends TaskResult +{ + /** + * 削除の結果と不要データのパスです。 + */ + HashMap deletedGarbage; + + public GarbageCleanResult(boolean success, @NotNull GarbageCleanState state, @Nullable GarbageCleanErrorCause errorCause, HashMap deletedGarbage) + { + super(success, state, errorCause); + this.deletedGarbage = deletedGarbage; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanState.java new file mode 100644 index 00000000..5bbfe9b8 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanState.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; + +/** + * 不要データ削除の状態を表します。 + */ +public enum GarbageCleanState +{ + /** + * 不要データ削除が初期化されたことを示します。 + */ + INITIALIZED, + /** + * 不要データを削除中であることを示します。 + */ + DELETING_GARBAGE, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanTask.java new file mode 100644 index 00000000..346989db --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanTask.java @@ -0,0 +1,109 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageDeleteSkippedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageDeletingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.InvalidIntegritySignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; +import org.jetbrains.annotations.NotNull; + +import java.io.FileNotFoundException; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; + +/** + * 不要データ削除を行うタスクです。 + */ +public class GarbageCleanTask extends InstallTask +{ + private GarbageCleanState status; + + public GarbageCleanTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + { + super(progress, signalHandler); + + this.status = GarbageCleanState.INITIALIZED; + } + + @Override + public @NotNull GarbageCleanResult runTask(@NotNull GarbageCleanArgument arguments) + { + List paths = arguments.getPaths(); + HashMap result = new HashMap<>(); + + if (arguments.getPaths().isEmpty()) + return new GarbageCleanResult(false, this.status, + GarbageCleanErrorCause.NO_GARBAGE, result + ); + + GarbageEnumeratedSignal signal = new GarbageEnumeratedSignal(paths); + this.postSignal(signal); + if (signal.isCancel()) + return new GarbageCleanResult(false, this.status, + GarbageCleanErrorCause.CANCELLED, result + ); + + paths = signal.getGarbageDatas(); // results may be modified by signal + + this.status = GarbageCleanState.DELETING_GARBAGE; + for (Path path : paths) + { + int state = this.removeOne(path); + if (state == -1) + { + this.postSignal(new InvalidIntegritySignal()); + return new GarbageCleanResult(false, this.status, + GarbageCleanErrorCause.INVALID_INTEGRITY, result + ); + } + + result.put(path, state == 0); + } + + if (result.values().stream().parallel().noneMatch(b -> b)) + return new GarbageCleanResult(false, this.status, + GarbageCleanErrorCause.ALL_DELETE_FAILED, result + ); + + return new GarbageCleanResult(true, this.status, null, result); + } + + /** + * 一つの不要データを削除します。 + * + * @param path 削除する不要データのパスです。 + * @return 0: 削除成功 1: 削除失敗 -1: 致命的なエラー + */ + private int removeOne(Path path) + { + GarbageDeletingSignal.Pre signal = new GarbageDeletingSignal.Pre(path); + this.postSignal(signal); + if (signal.isSkip()) + { + this.postSignal(new GarbageDeleteSkippedSignal(path)); + return 1; + } + + try + { + FileUtils.forceDelete(path.toFile()); + + this.postSignal(new GarbageDeletingSignal.Post(path)); + return 0; + } + catch (FileNotFoundException e) + { + // Illegal state, so protect the system. + return -1; + } + catch (Exception ignored) + { + } + + return 1; + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java new file mode 100644 index 00000000..ee95e0d6 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java @@ -0,0 +1,20 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +/** + * 不要データの削除がスキップされたことを示すシグナルです。 + */ +@Value +public class GarbageDeleteSkippedSignal implements Signal +{ + /** + * スキップされた不要データのパスです。 + */ + @NotNull + Path garbageData; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java new file mode 100644 index 00000000..2aba0dfb --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java @@ -0,0 +1,52 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +/** + * 不要なデータの削除中であることを示すシグナルです。 + */ +@Data +public class GarbageDeletingSignal implements Signal +{ + /** + * 不要なデータのパスです。 + */ + @NotNull + private final Path garbageData; + + /** + * 削除前に呼ばれるシグナルです。 + */ + public static class Pre extends GarbageDeletingSignal + { + /** + * 削除をスキップするかどうかです。 + */ + @Getter + @Setter + private boolean skip; + + public Pre(Path garbageData) + { + super(garbageData); + this.skip = false; + } + } + + /** + * 削除後に呼ばれるシグナルです。 + */ + public static class Post extends GarbageDeletingSignal + { + public Post(Path garbageData) + { + super(garbageData); + } + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java new file mode 100644 index 00000000..b912b543 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +import java.nio.file.Path; +import java.util.List; + +/** + * 不要なデータが列挙されたことを示すシグナルです。 + */ +@Data +public class GarbageEnumeratedSignal implements Signal +{ + /** + * 不要なデータのパスのリストです。 + */ + private final List garbageDatas; + /** + * 削除をキャンセルするかどうかです。 + */ + private boolean cancel; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java new file mode 100644 index 00000000..e79bd780 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java @@ -0,0 +1,11 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; + +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +/** + * 整合性がとれなく、システムが保護されたことを示すシグナルです。 + * 不要データの削除はスキップされます。 + */ +public class InvalidIntegritySignal implements Signal +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchArgument.java new file mode 100644 index 00000000..75b0b4e3 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchArgument.java @@ -0,0 +1,51 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 不要データ検索を行うタスクの引数です。 + */ +@Value +@EqualsAndHashCode(callSuper = false) +@AllArgsConstructor +public class GarbageSearchArgument extends TaskArgument +{ + /** + * 検索から除外するデータのリストです。 + */ + @NotNull + List excludes; + + /** + * 検索するディレクトリのパスです。 + */ + @NotNull + Path dataFolder; + + /** + * サーバに存在するプラグインのリストです。 + */ + @NotNull + List plugins; + + public GarbageSearchArgument(List excludes) + { + this(excludes, TeamKunPluginManager.getPlugin().getDataFolder().toPath().getParent(), + Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName) + .collect(Collectors.toList()) + ); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java new file mode 100644 index 00000000..1d6a1591 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; + +/** + * 不要データ検索のエラーを表す列挙型です。 + */ +public enum GarbageSearchErrorCause +{ + /** + * I/Oエラーが発生しました。 + */ + IO_EXCEPTION_OCCURRED, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchResult.java new file mode 100644 index 00000000..cd9132ad --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchResult.java @@ -0,0 +1,39 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; +import java.util.List; + +/** + * 不要データ検索を行うタスクの結果です。 + */ +@Value +@EqualsAndHashCode(callSuper = true) +public class GarbageSearchResult extends TaskResult +{ + /** + * 見つかった不要データのパスのリストです。 + */ + List garbageFiles; + + public GarbageSearchResult(boolean success, @NotNull GarbageSearchState state, @Nullable GarbageSearchErrorCause errorCause, List garbageFiles) + { + super(success, state, errorCause); + this.garbageFiles = garbageFiles; + } + + public GarbageSearchResult(@NotNull GarbageSearchState state, List garbageFiles) + { + this(true, state, null, garbageFiles); + } + + public GarbageSearchResult(boolean success, @NotNull GarbageSearchState state, @Nullable GarbageSearchErrorCause errorCause) + { + this(success, state, errorCause, null); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchState.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchState.java new file mode 100644 index 00000000..49aeec61 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchState.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; + +/** + * 不要データ検索の状態を表します。 + */ +public enum GarbageSearchState +{ + /** + * 不要データ検索が初期化されたことを示します。 + */ + INITIALIZED, + /** + * 不要データの検索中であることを示します。 + */ + SEARCHING_GARBAGE, +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchTask.java new file mode 100644 index 00000000..05570276 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchTask.java @@ -0,0 +1,63 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * 不要データ検索を行うタスクです。 + */ +public class GarbageSearchTask extends InstallTask +{ + private GarbageSearchState status; + + public GarbageSearchTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + { + super(progress, signalHandler); + + this.status = GarbageSearchState.INITIALIZED; + } + + @Override + public @NotNull GarbageSearchResult runTask(@NotNull GarbageSearchArgument arguments) + { + + List excludeList = arguments.getExcludes().stream().parallel() + .map(String::toLowerCase) + .collect(Collectors.toList()); + List serverPlugins = arguments.getPlugins().stream().parallel() + .map(String::toLowerCase) + .collect(Collectors.toList()); + + GarbageSearchingSignal signal = new GarbageSearchingSignal(arguments.getDataFolder()); + this.postSignal(signal); + Path dir = signal.getDataFolder(); // dir may be changed by signal handler + + this.status = GarbageSearchState.SEARCHING_GARBAGE; + + List results; + try (Stream stream = Files.list(dir)) + { + results = stream.parallel() + .filter(Files::isDirectory) + .filter(file -> !excludeList.contains(file.getFileName().toString().toLowerCase())) + .filter(file -> !serverPlugins.contains(file.getFileName().toString().toLowerCase())) + .collect(Collectors.toList()); + } + catch (IOException e) + { + return new GarbageSearchResult(false, this.status, GarbageSearchErrorCause.IO_EXCEPTION_OCCURRED); + } + + return new GarbageSearchResult(this.status, results); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java new file mode 100644 index 00000000..6c56393a --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java @@ -0,0 +1,18 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; + +import java.nio.file.Path; + +/** + * 不要データの検索を開始したことを示すシグナルです。 + */ +@Data +public class GarbageSearchingSignal implements Signal +{ + /** + * 検索対象のディレクトリです。 + */ + private final Path dataFolder; +} From 4b41bcbe60f4d0eeb625a46efc8d96c87944ed66 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 23:52:27 +0900 Subject: [PATCH 351/745] refactor: Remove unused classes --- .../plugin/InstallResult.java | 33 ------- .../plugin/Installer.java | 97 ------------------- 2 files changed, 130 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java deleted file mode 100644 index b770ebab..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/InstallResult.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin; - -import lombok.AllArgsConstructor; -import lombok.Value; - -@Value -@AllArgsConstructor -public class InstallResult -{ - - String fileName; - String pluginName; - int add; - int remove; - int modify; - boolean success; - - public InstallResult(boolean success) - { - this("", "", 0, 0, 0, success); - } - - public InstallResult(int add, int remove, int modify, boolean success) - { - this("", "", add, remove, modify, success); - } - - public InstallResult(String fileName, String pluginName) - { - this(fileName, pluginName, 0, 0, 0, true); - } - -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java deleted file mode 100644 index 41bb57ae..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/Installer.java +++ /dev/null @@ -1,97 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin; - -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -@SuppressWarnings("unused") -public class Installer -{ - /** - * 削除可能なデータフォルダを取得 - * - * @return データフォルダ - */ - public static String[] getRemovableDataDirs() - { - try - { - //ignoreされているものを全て取得 - List bb = TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore"); - - return Arrays.stream(Objects.requireNonNull(new File("plugins/").listFiles(File::isDirectory))) //plugins/の中のフォルダを全取得 - .map(File::getName) //Stream => Stream ファイルの名前 - .filter(file -> !PluginUtil.isPluginLoaded(file)) //プラグインフォルダが使用されていたら除外 - .filter(file -> !bb.contains(file)) //除外リスト似合った場合はreturn - .toArray(String[]::new); //結果を全てreturn - - } - catch (Exception e) //例外が発生した場合は空return - { - return new String[]{}; - } - } - - /** - * プラグインデータフォルダを削除 - * - * @param name 対象 - * @return 合否 - */ - public static boolean clean(String name) - { - Plugin plugin = Bukkit.getPluginManager().getPlugin(name); - - if (PluginUtil.isPluginLoaded(name)) - return false; //プラグインがイネーブルの時、プロセスロックが掛かる - - if (TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream() - .anyMatch(s -> s.equalsIgnoreCase(name))) // 保護されていたら除外 - return false; - - if (plugin != null) - { - try - { - FileUtils.forceDelete(plugin.getDataFolder()); - return true; - } - catch (IOException e) - { - e.printStackTrace(); - return false; - } - - } - - try - { - Arrays.stream(Objects.requireNonNull(new File("plugins/").listFiles(File::isDirectory))) //plugins/の中のフォルダを全取得 - .filter(file -> file.getName().equalsIgnoreCase(name)) //一致するフォルダを取得 - .forEach(file -> { - try - { - //強制削除 - FileUtils.forceDelete(file); - } - catch (IOException e) - { - e.printStackTrace(); - } - }); - return true; - } - catch (Exception e) - { - return false; - } - } -} From dd0692c696024fd4716183e832b9f38a9506d42d Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 9 Oct 2022 23:56:07 +0900 Subject: [PATCH 352/745] refactor: Remove legacy session control --- .../TeamKunPluginManager.java | 3 --- .../commands/CommandRegister.java | 9 --------- .../commands/CommandReload.java | 8 -------- .../teamkunpluginmanager/utils/Session.java | 19 ------------------- 4 files changed, 39 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Session.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index b871dbe0..c51a1ff1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -25,7 +25,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.KnownPluginsResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; -import net.kunmc.lab.teamkunpluginmanager.utils.Session; import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; @@ -45,7 +44,6 @@ public final class TeamKunPluginManager extends JavaPlugin private FileConfiguration pluginConfig; private TokenStore tokenStore; - private Session session; private PluginResolver resolver; private CommandManager commandManager; private InstallManager installManager; @@ -145,7 +143,6 @@ private void setupToken() @Override public void onEnable() { - session = new Session(); saveDefaultConfig(); plugin = this; pluginConfig = getConfig(); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 95c772dd..f09ee88b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -137,7 +137,6 @@ private static Runner.GeneralExceptableRunner polling(Terminal terminal, String terminal.success("トークンを正常に保管しました!"); if (terminal.isPlayer()) terminal.clearNotification(); - kpmInstance.getSession().unlock(); successFlag.set(true); throw new RuntimeException(); // For cancel bukkit task @@ -153,12 +152,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } - if (!kpmInstance.getSession().lock()) - { - terminal.error("TeamKunPluginManagerが多重起動しています。"); - return; - } - if (args.length == 1) { try @@ -173,7 +166,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, } terminal.success("トークンを正常に保管しました!"); - kpmInstance.getSession().unlock(); return; } @@ -187,7 +179,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, else if (result.test(QuestionAttribute.YES)) performAction(terminal); - kpmInstance.getSession().unlock(); }, (e, b) -> { }); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java index b0c8a3f7..ce80a1b7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java @@ -3,7 +3,6 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; @@ -32,17 +31,10 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } - if (!TeamKunPluginManager.getPlugin().getSession().lock()) - { - terminal.error("TeamKunPluginManagerが多重起動しています。"); - return; - } - Runner.runAsync(() -> { terminal.info("プラグイン %s を再読み込み中...", args[0]); PluginLoader.getInstance().reloadPlugin(plugin); terminal.success("プラグイン %s を正常に再読み込み中しました。", args[0]); - TeamKunPluginManager.getPlugin().getSession().unlock(); }); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Session.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Session.java deleted file mode 100644 index 0dd7471f..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Session.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -public class Session -{ - private volatile boolean session = false; - - public boolean lock() - { - if (session) - return false; - return session = true; - } - - public void unlock() - { - session = false; - } - -} From f61c7c222e8d16d370565aa1341386ef96899e3e Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 10 Oct 2022 00:04:51 +0900 Subject: [PATCH 353/745] chore: v3.0.0-pre5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 49117b54..ffff7ce3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kunmc.lab TeamKunPluginManager - 3.0.0-pre4 + 3.0.0-pre5 jar TeamKunPluginManager From 22bb4ec45362e9408ec0242da43f1969f2b8d37a Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 10 Oct 2022 21:38:30 +0900 Subject: [PATCH 354/745] feat: KPMDaemon --- .../lab/teamkunpluginmanager/KPMDaemon.java | 184 ++++++++++++++++++ .../TeamKunPluginManager.java | 145 +++----------- .../commands/CommandAutoRemove.java | 10 +- .../commands/CommandClean.java | 10 +- .../commands/CommandDebug.java | 10 +- .../commands/CommandInfo.java | 9 +- .../commands/CommandInstall.java | 10 +- .../commands/CommandRegister.java | 17 +- .../commands/CommandReload.java | 8 +- .../commands/CommandResolve.java | 9 +- .../commands/CommandStatus.java | 30 ++- .../commands/CommandUninstall.java | 10 +- .../commands/CommandUpdate.java | 7 +- .../commands/debug/CommandInstallDebug.java | 11 +- .../commands/debug/CommandUninstallDebug.java | 8 +- .../plugin/installer/InstallManager.java | 21 +- .../impls/autoremove/PluginAutoRemover.java | 17 +- .../impls/install/PluginInstaller.java | 35 ++-- .../impls/uninstall/PluginUninstaller.java | 11 +- .../installer/impls/update/AliasUpdater.java | 8 +- .../tasks/alias/update/UpdateAliasesTask.java | 9 +- .../collector/DependsCollectTask.java | 13 +- .../tasks/install/PluginsInstallTask.java | 19 +- .../task/tasks/resolve/PluginResolveTask.java | 16 +- .../task/tasks/uninstall/UnInstallTask.java | 12 +- .../plugin/loader/PluginLoader.java | 17 -- .../impl/BruteforceGitHubResolver.java | 11 +- .../resolver/impl/KnownPluginsResolver.java | 15 +- .../teamkunpluginmanager/utils/Messages.java | 15 -- .../utils/http/Requests.java | 15 +- 30 files changed, 430 insertions(+), 282 deletions(-) create mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java new file mode 100644 index 00000000..00024808 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -0,0 +1,184 @@ +package net.kunmc.lab.teamkunpluginmanager; + +import lombok.AccessLevel; +import lombok.Getter; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; +import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; +import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasProvider; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.BruteforceGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubURLResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.KnownPluginsResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * KPMを操作するためのクラスです。 + */ +@Getter +public class KPMDaemon +{ + @SuppressWarnings("NotNullFieldNotInitialized") + @Getter(AccessLevel.NONE) + @NotNull + private static KPMDaemon INSTANCE; + + @Getter(AccessLevel.NONE) + @NotNull + private final TeamKunPluginManager kpmInstance; + + /** + * ログを出力するためのロガーです。 + */ + @NotNull + private final Logger logger; + + /** + * データフォルダのパスです。 + */ + @NotNull + private final Path dataFolderPath; + + /** + * プラグインのメタデータを管理するクラスです。 + */ + @NotNull + private final PluginMetaManager pluginMetaManager; + /** + * トークンを保管しセキュアに管理するクラスです。 + */ + @NotNull + private final TokenStore tokenStore; + /** + * プラグインクエリを解決するクラスです。 + */ + @NotNull + private final PluginResolver pluginResolver; + /** + * インストールを管理するクラスです。 + */ + @NotNull + private final InstallManager installManager; + /** + * エイリアスを管理するクラスです。 + */ + @NotNull + private final AliasProvider aliasProvider; + + /** + * プラグインをロード/アンロードするためのクラスです。 + */ + @NotNull + private final PluginLoader pluginLoader; + + { + INSTANCE = this; + } + + public KPMDaemon( + @NotNull TeamKunPluginManager kpmInstance, + @NotNull Logger logger, + @NotNull Path dataFolderPath, + @NotNull Path databasePath, + @NotNull Path tokenPath, + @NotNull Path tokenKeyPath, + @NotNull Path aliasPath) + { + this.kpmInstance = kpmInstance; + this.logger = logger; + this.dataFolderPath = dataFolderPath; + this.pluginMetaManager = new PluginMetaManager(kpmInstance, databasePath); + this.tokenStore = new TokenStore(tokenPath, tokenKeyPath); + this.pluginResolver = new PluginResolver(); + this.aliasProvider = new AliasProvider(aliasPath); + this.pluginLoader = new PluginLoader(); + this.installManager = new InstallManager(this); + } + + /** + * KPMのインスタンスを取得します。 + * + * @return KPMのインスタンス + */ + @NotNull + public static KPMDaemon getInstance() + { + return INSTANCE; + } + + public void setupDaemon(@NotNull Path dataFolder) + { + this.setupDependencyTree(dataFolder); + this.setupPluginResolvers(); + this.setupToken(); + } + + private void setupDependencyTree(Path dataFolder) + { + logger.info("Loading plugin meta data ..."); + this.pluginMetaManager.crawlAll(); + + Path aliasFile = dataFolder.resolve("aliases.db"); + boolean isFirstTime = !Files.exists(aliasFile); + if (isFirstTime && this.tokenStore.isTokenAvailable()) // Do update + new CommandUpdate(this).onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); + } + + private void setupPluginResolvers() + { + GitHubURLResolver githubResolver = new GitHubURLResolver(); + this.pluginResolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); + this.pluginResolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); + this.pluginResolver.addResolver(new KnownPluginsResolver(this), "local", "alias"); + this.pluginResolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); + this.pluginResolver.addResolver(githubResolver, "github", "gh"); + + this.pluginResolver.addOnNotFoundResolver(new BruteforceGitHubResolver( + kpmInstance.getPluginConfig().get("githubName"), + githubResolver + )); + } + + private void setupToken() + { + try + { + boolean tokenAvailable = this.tokenStore.loadToken(); + if (!tokenAvailable) + if (this.tokenStore.migrateToken()) + tokenAvailable = true; + + if (!tokenAvailable) + this.logger.warn("Token is not available. Please login with /kpm register"); + } + catch (IOException e) + { + e.printStackTrace(); + this.logger.error("Failed to load token"); + } + + + String tokenEnv = System.getenv("TOKEN"); + + if (tokenEnv != null && !tokenEnv.isEmpty()) + this.tokenStore.fromEnv(); + } + + public void shutdown() + { + this.pluginMetaManager.getProvider().close(); + this.aliasProvider.close(); + } +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index c51a1ff1..f7a4aa34 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -2,7 +2,6 @@ import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.command.CommandManager; -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; import net.kunmc.lab.teamkunpluginmanager.commands.CommandAutoRemove; import net.kunmc.lab.teamkunpluginmanager.commands.CommandClean; import net.kunmc.lab.teamkunpluginmanager.commands.CommandDebug; @@ -14,130 +13,40 @@ import net.kunmc.lab.teamkunpluginmanager.commands.CommandStatus; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUninstall; import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; -import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasProvider; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.BruteforceGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubURLResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.KnownPluginsResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; -import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; -import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; -import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; @Getter public final class TeamKunPluginManager extends JavaPlugin { @Getter private static TeamKunPluginManager plugin; - private FileConfiguration pluginConfig; - private TokenStore tokenStore; - - private PluginResolver resolver; private CommandManager commandManager; - private InstallManager installManager; - private PluginMetaManager pluginMetaManager; - private AliasProvider aliasProvider; - private void setupDependencyTree() - { - this.pluginMetaManager = new PluginMetaManager( - this, - Paths.get(plugin.getDataFolder().toURI()).resolve("plugins.db") - ); + private KPMDaemon daemon; - System.out.println("プラグインメタデータを取得中 ..."); - this.pluginMetaManager.crawlAll(); - - Path aliasFile = Paths.get(plugin.getDataFolder().toURI()).resolve("aliases.db"); - boolean isFirstTime = !Files.exists(aliasFile); - - this.aliasProvider = new AliasProvider(aliasFile); - - if (isFirstTime && isTokenAvailable()) // Do update - new CommandUpdate().onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); - } - - private static void setupResolver(TeamKunPluginManager plugin) + public static void registerCommands(KPMDaemon daemon, CommandManager commandManager) { - PluginResolver resolver = plugin.getResolver(); - - GitHubURLResolver githubResolver = new GitHubURLResolver(); - resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); - resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); - resolver.addResolver(new KnownPluginsResolver(resolver), "local", "alias"); - resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); - resolver.addResolver(githubResolver, "github", "gh"); - - resolver.addOnNotFoundResolver(new BruteforceGitHubResolver(plugin, githubResolver)); + commandManager.registerCommand("autoremove", new CommandAutoRemove(daemon)); + commandManager.registerCommand("clean", new CommandClean(daemon)); + commandManager.registerCommand("info", new CommandInfo(daemon)); + commandManager.registerCommand("install", new CommandInstall(daemon), "add", "i"); + commandManager.registerCommand("register", new CommandRegister(daemon), "login"); + commandManager.registerCommand("reload", new CommandReload(daemon)); + commandManager.registerCommand("resolve", new CommandResolve(daemon)); + commandManager.registerCommand("status", new CommandStatus(daemon)); + commandManager.registerCommand("uninstall", new CommandUninstall(daemon), "remove", "rm"); + commandManager.registerCommand("update", new CommandUpdate(daemon)); + commandManager.registerCommand("debug", new CommandDebug()); } @Override public void onDisable() { - this.pluginMetaManager.getProvider().close(); - this.aliasProvider.close(); - } - - public boolean isTokenAvailable() - { - return tokenStore.isTokenAvailable(); - } - - public static void registerCommands(CommandManager commandManager) - { - commandManager.registerCommand("autoremove", new CommandAutoRemove()); - commandManager.registerCommand("clean", new CommandClean()); - commandManager.registerCommand("info", new CommandInfo()); - commandManager.registerCommand("install", new CommandInstall(), "add", "i"); - commandManager.registerCommand("register", new CommandRegister(), "login"); - commandManager.registerCommand("reload", new CommandReload()); - commandManager.registerCommand("resolve", new CommandResolve()); - commandManager.registerCommand("status", new CommandStatus()); - commandManager.registerCommand("uninstall", new CommandUninstall(), "remove", "rm"); - commandManager.registerCommand("update", new CommandUpdate()); - commandManager.registerCommand("debug", new CommandDebug()); - } - - private void setupToken() - { - tokenStore = new TokenStore( - this.getDataFolder().toPath().resolve("token.dat"), - this.getDataFolder().toPath().resolve("token_key.dat") - ); - try - { - boolean tokenAvailable = tokenStore.loadToken(); - if (!tokenAvailable) - if (tokenStore.migrateToken()) - tokenAvailable = true; - - if (!tokenAvailable) - System.out.println("Tokenが見つかりませんでした。/kpm registerでTokenを登録してください。"); - } - catch (IOException e) - { - e.printStackTrace(); - System.out.println("トークンの読み込みに失敗しました。"); - } - - - String tokenEnv = System.getenv("TOKEN"); - - if (tokenEnv != null && !tokenEnv.isEmpty()) - tokenStore.fromEnv(); - + this.daemon.shutdown(); } @Override @@ -145,17 +54,25 @@ public void onEnable() { saveDefaultConfig(); plugin = this; - pluginConfig = getConfig(); - resolver = new PluginResolver(); - commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); - installManager = new InstallManager(this); - new PluginLoader(); // Initialize plugin loader + this.pluginConfig = getConfig(); + this.commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); + + + Path dataDir = this.getDataFolder().toPath(); + + this.daemon = new KPMDaemon( + this, + this.getSLF4JLogger(), + dataDir, + dataDir.resolve("plugins.db"), + dataDir.resolve("token.dat"), + dataDir.resolve("token_key.dat"), + dataDir.resolve("aliases.db") + ); - setupResolver(this); - setupToken(); - setupDependencyTree(); + this.daemon.setupDaemon(this.getDataFolder().toPath()); - registerCommands(commandManager); + registerCommands(this.daemon, commandManager); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 38cc4fb0..45cac572 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -1,9 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -12,15 +13,16 @@ import java.util.List; +@AllArgsConstructor public class CommandAutoRemove extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> - kpmInstance.getInstallManager().runAutoRemove(terminal, new AutoRemoveArgument()) + this.daemon.getInstallManager().runAutoRemove(terminal, new AutoRemoveArgument()) ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index 4ea2a896..669d1139 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -1,9 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean.CleanArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -12,15 +13,16 @@ import java.util.List; +@AllArgsConstructor public class CommandClean extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> - kpmInstance.getInstallManager().runGarbageClean(terminal, new CleanArgument()) + this.daemon.getInstallManager().runGarbageClean(terminal, new CleanArgument()) ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java index 2a8261df..4bff33b6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java @@ -2,7 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandDepTreeDebug; import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandInstallDebug; import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandUninstallDebug; @@ -20,10 +20,12 @@ public class CommandDebug extends SubCommandWith static { + KPMDaemon daemon = KPMDaemon.getInstance(); + COMMANDS = new HashMap<>(); - COMMANDS.put("installDebug", new CommandInstallDebug()); - COMMANDS.put("uninstallDebug", new CommandUninstallDebug()); - COMMANDS.put("depTree", new CommandDepTreeDebug(TeamKunPluginManager.getPlugin().getPluginMetaManager())); + COMMANDS.put("installDebug", new CommandInstallDebug(daemon)); + COMMANDS.put("uninstallDebug", new CommandUninstallDebug(daemon)); + COMMANDS.put("depTree", new CommandDepTreeDebug(daemon.getPluginMetaManager())); } @Override diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index f4e2b8b7..501be2cc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -1,7 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependType; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.InstallOperator; @@ -30,8 +32,11 @@ import java.util.Map; import java.util.stream.Collectors; +@AllArgsConstructor public class CommandInfo extends CommandBase { + private final KPMDaemon daemon; + private static Component dependTree(String name, List l) { TextComponent content = Component.text(name + ": "); @@ -118,9 +123,6 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, terminal.info("依存関係ツリーを読み込み中..."); - PluginMetaProvider provider = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider(); - - JavaPlugin plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(args[0]); if (plugin == null) @@ -129,6 +131,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } + PluginMetaProvider provider = this.daemon.getPluginMetaManager().getProvider(); if (!provider.isPluginMetaExists(plugin.getName())) { terminal.error("プラグインが見つかりませんでした。"); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index 2611705a..0c963ee6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -1,9 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -12,8 +13,11 @@ import java.util.List; +@AllArgsConstructor public class CommandInstall extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -22,10 +26,8 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String query = args[0]; - TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> - kpmInstance.getInstallManager().runInstall(terminal, new InstallArgument(query)) + this.daemon.getInstallManager().runInstall(terminal, new InstallArgument(query)) ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index f09ee88b..7f101e52 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -2,12 +2,13 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; @@ -24,6 +25,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +@AllArgsConstructor public class CommandRegister extends CommandBase { private static final String CLIENT_ID = "94c5d446dbc765895979"; @@ -34,7 +36,7 @@ public class CommandRegister extends CommandBase "https://github.com/login/oauth/access_token?client_id=" + CLIENT_ID + "&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&device_code="; - private static final TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); + private final KPMDaemon daemon; private static void parseErrorAndPost(Terminal terminal, HTTPResponse response) { @@ -55,7 +57,7 @@ private static void parseErrorAndPost(Terminal terminal, HTTPResponse response) } } - private static void performAction(Terminal terminal) + private void performAction(Terminal terminal) { terminal.info(ChatColor.LIGHT_PURPLE + "サーバと通信しています..."); @@ -67,6 +69,7 @@ private static void performAction(Terminal terminal) if (response.getStatus() != HTTPResponse.RequestStatus.OK) { parseErrorAndPost(terminal, response); + return; } JsonObject object = response.getAsJson().getAsJsonObject(); @@ -101,7 +104,7 @@ private static void performAction(Terminal terminal) } - private static Runner.GeneralExceptableRunner polling(Terminal terminal, String device_code, AtomicBoolean successFlag) + private Runner.GeneralExceptableRunner polling(Terminal terminal, String device_code, AtomicBoolean successFlag) { return () -> { HTTPResponse httpResponse = Requests.request(RequestContext.builder() @@ -133,7 +136,7 @@ private static Runner.GeneralExceptableRunner polling(Terminal terminal, String throw new RuntimeException(); // For cancel bukkit task } - kpmInstance.getTokenStore().storeToken(response.get("access_token").getAsString()); + this.daemon.getTokenStore().storeToken(response.get("access_token").getAsString()); terminal.success("トークンを正常に保管しました!"); if (terminal.isPlayer()) terminal.clearNotification(); @@ -156,7 +159,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { try { - kpmInstance.getTokenStore().storeToken(args[0]); + this.daemon.getTokenStore().storeToken(args[0]); } catch (IOException e) { @@ -177,7 +180,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (result.test(QuestionAttribute.CANCELLABLE)) terminal.error("キャンセルしました。"); else if (result.test(QuestionAttribute.YES)) - performAction(terminal); + this.performAction(terminal); }, (e, b) -> { }); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java index ce80a1b7..e75853e0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java @@ -1,9 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -15,8 +16,11 @@ import java.util.List; import java.util.stream.Collectors; +@AllArgsConstructor public class CommandReload extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -33,7 +37,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, Runner.runAsync(() -> { terminal.info("プラグイン %s を再読み込み中...", args[0]); - PluginLoader.getInstance().reloadPlugin(plugin); + this.daemon.getPluginLoader().reloadPlugin(plugin); terminal.success("プラグイン %s を正常に再読み込み中しました。", args[0]); }); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java index b686c33e..f76eb998 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java @@ -1,8 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitSuccessResult; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubSuccessResult; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCSuccessResult; @@ -20,6 +21,7 @@ import java.util.List; +@AllArgsConstructor public class CommandResolve extends CommandBase { private static final String DELIMITER_SMALL; @@ -32,6 +34,9 @@ public class CommandResolve extends CommandBase DELIMITER = StringUtils.repeat(DELIMITER_SMALL, 2); } + @NotNull + private final KPMDaemon daemon; + private static void printResult(Terminal terminal, ResolveResult result, boolean smallDelimiter) { if (smallDelimiter) @@ -119,7 +124,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String query = args[0]; terminal.info("プラグインの名前解決をしています..."); - ResolveResult result = TeamKunPluginManager.getPlugin().getResolver().resolve(query); + ResolveResult result = this.daemon.getPluginResolver().resolve(query); printResult(terminal, result, false); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java index 3bad1b6c..9e9a8473 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java @@ -1,8 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; @@ -11,13 +12,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.List; +@AllArgsConstructor public class CommandStatus extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -25,22 +26,15 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, terminal.writeLine(Messages.keyValue("プラグイン数", Bukkit.getPluginManager().getPlugins().length)); - File resolve = new File( - TeamKunPluginManager.getPlugin().getDataFolder(), - TeamKunPluginManager.getPlugin().getPluginConfig().getString("resolvePath") - ); - if (resolve.exists()) - terminal.writeLine(Messages.keyValue( - "最終アップデート", - new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(resolve.lastModified())) - )); - - String autoRemovable = Messages.getUnInstallableMessage(); - + List autoRemovable = this.daemon.getPluginMetaManager().getProvider().getUnusedPlugins(); if (!autoRemovable.isEmpty()) - terminal.writeLine(autoRemovable); + terminal.writeLine( + ChatColor.BLUE + "以下のプラグインがインストールされていますが、もう必要とされていません:\n" + + ChatColor.GREEN + " " + String.join(" ", autoRemovable) + "\n" + + ChatColor.BLUE + "これを削除するには、'/kpm autoremove' を利用してください。" + ); - if (!TeamKunPluginManager.getPlugin().isTokenAvailable()) + if (!this.daemon.getTokenStore().isTokenAvailable()) terminal.writeLine(ChatColor.RED + "トークンがセットされていません!/kpm register でトークンを発行してください。"); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index 9bff6ccf..b6420e16 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -1,9 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; @@ -16,8 +17,11 @@ import java.util.List; import java.util.stream.Collectors; +@AllArgsConstructor public class CommandUninstall extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -26,10 +30,8 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String query = args[0]; - TeamKunPluginManager kpmInstance = TeamKunPluginManager.getPlugin(); - Runner.runAsync(() -> - kpmInstance.getInstallManager().runUninstall(terminal, new UninstallArgument(query)) + daemon.getInstallManager().runUninstall(terminal, new UninstallArgument(query)) ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index ea8a576d..f44d6390 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -1,9 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.commands; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.UpdateArgument; import net.kyori.adventure.text.TextComponent; @@ -15,8 +17,11 @@ import java.util.List; import java.util.Map; +@AllArgsConstructor public class CommandUpdate extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -31,7 +36,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, .collect(HashMap::new, (map, pair) -> map.put(pair.getLeft(), pair.getRight()), HashMap::putAll); Runner.runAsync(() -> - TeamKunPluginManager.getPlugin().getInstallManager().runUpdate(terminal, new UpdateArgument( + this.daemon.getInstallManager().runUpdate(terminal, new UpdateArgument( aliasMap )) ); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java index 47ae0b5b..0d6fc924 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java @@ -1,8 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.commands.debug; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; @@ -17,8 +19,12 @@ import java.util.Arrays; import java.util.List; +@AllArgsConstructor public class CommandInstallDebug extends CommandBase { + @NotNull + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -30,7 +36,10 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, Runner.runAsync(() -> { try { - PluginInstaller installer = new PluginInstaller(DebugSignalHandler.toManager(terminal)); + PluginInstaller installer = new PluginInstaller( + this.daemon, + DebugSignalHandler.toManager(terminal) + ); InstallResult installResult = installer.execute(new InstallArgument(query)); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java index 492bfc57..05f13b04 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java @@ -1,8 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.commands.debug; +import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; @@ -20,8 +22,11 @@ import java.util.List; import java.util.stream.Collectors; +@AllArgsConstructor public class CommandUninstallDebug extends CommandBase { + private final KPMDaemon daemon; + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -33,7 +38,8 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, Runner.runAsync(() -> { try { - PluginUninstaller installer = new PluginUninstaller(DebugSignalHandler.toManager(terminal)); + PluginUninstaller installer = + new PluginUninstaller(this.daemon, DebugSignalHandler.toManager(terminal)); InstallResult installResult = installer.execute(new UninstallArgument(query)); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java index 566db7a4..e4dc3449 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java @@ -1,7 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.commands.signal.HeadSignalHandlers; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.PluginAutoRemover; @@ -14,6 +14,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.AliasUpdater; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.UpdateArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -23,14 +24,16 @@ */ public class InstallManager { - private final TeamKunPluginManager pluginManager; + private final KPMDaemon daemon; + private final TokenStore tokenStore; private final SignalHandleManager signalHandleManager; private InstallProgress runningInstall; - public InstallManager(@NotNull TeamKunPluginManager pluginManager) + public InstallManager(@NotNull KPMDaemon daemon) { - this.pluginManager = pluginManager; + this.daemon = daemon; + this.tokenStore = daemon.getTokenStore(); this.signalHandleManager = new SignalHandleManager(); this.runningInstall = null; @@ -68,7 +71,7 @@ public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argu terminal.error("他のインストーラが起動しています。"); return; } - if (!this.pluginManager.isTokenAvailable()) + if (!this.tokenStore.isTokenAvailable()) { terminal.error("GitHub にログインされていません。"); terminal.info("/kpm register でログインしてください。"); @@ -81,7 +84,7 @@ public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argu PluginInstaller installer; try { - installer = new PluginInstaller(copiedHandleManager); + installer = new PluginInstaller(this.daemon, copiedHandleManager); runningInstall = installer.getProgress(); installer.run(argument); @@ -116,7 +119,7 @@ public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument try { - PluginUninstaller uninstaller = new PluginUninstaller(copiedHandleManager); + PluginUninstaller uninstaller = new PluginUninstaller(this.daemon, copiedHandleManager); runningInstall = uninstaller.getProgress(); uninstaller.run(argument); @@ -143,7 +146,7 @@ public void runUpdate(@NotNull Terminal terminal, @NotNull UpdateArgument argume try { - AliasUpdater updater = new AliasUpdater(copiedHandleManager); + AliasUpdater updater = new AliasUpdater(this.daemon, copiedHandleManager); runningInstall = updater.getProgress(); updater.run(argument); @@ -176,7 +179,7 @@ public void runAutoRemove(@NotNull Terminal terminal, @NotNull AutoRemoveArgumen try { - PluginAutoRemover remover = new PluginAutoRemover(copiedHandleManager); + PluginAutoRemover remover = new PluginAutoRemover(this.daemon, copiedHandleManager); runningInstall = remover.getProgress(); remover.run(argument); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java index 7e8aa25e..6200e122 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginEnumeratedSignal; @@ -11,7 +11,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -31,16 +30,12 @@ */ public class PluginAutoRemover extends AbstractInstaller { - private static final PluginMetaProvider META_PROVIDER; + private final KPMDaemon daemon; - static - { - META_PROVIDER = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider(); - } - - public PluginAutoRemover(SignalHandleManager signalHandler) throws IOException + public PluginAutoRemover(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { super(signalHandler); + this.daemon = daemon; } @Override @@ -54,7 +49,7 @@ public InstallResult execute(@NotNull AutoRemoveArgument argume .map(String::toLowerCase) .collect(Collectors.toList()); - targetPlugins = (ArrayList) META_PROVIDER.getUnusedPlugins() + targetPlugins = (ArrayList) this.daemon.getPluginMetaManager().getProvider().getUnusedPlugins() .stream() .parallel() .filter(unusedPluginName -> !excludePlugins.contains(unusedPluginName.toLowerCase())) @@ -82,7 +77,7 @@ public InstallResult execute(@NotNull AutoRemoveArgument argume PluginUninstaller uninstaller; try { - uninstaller = new PluginUninstaller(this.signalHandler); + uninstaller = new PluginUninstaller(this.daemon, this.signalHandler); } catch (IOException e) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index ac599f64..3a3bb39f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; @@ -20,7 +21,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; @@ -47,9 +47,12 @@ */ public class PluginInstaller extends AbstractInstaller { - public PluginInstaller(@NotNull SignalHandleManager signalHandler) throws IOException + private final KPMDaemon daemon; + + public PluginInstaller(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { super(signalHandler); + this.daemon = daemon; } @Override @@ -64,7 +67,10 @@ public InstallResult execute(@NotNull InstallArgument argument) th // region Do plugin resolve, download and description load. TaskResult pluginDescriptionResult = - this.submitter(InstallTasks.RESOLVING_QUERY, new PluginResolveTask(progress, signalHandler)) + this.submitter( + InstallTasks.RESOLVING_QUERY, + new PluginResolveTask(this.daemon, progress, signalHandler) + ) .then(InstallTasks.DOWNLOADING, new DownloadTask(progress, signalHandler)) .bridgeArgument(result -> { if (result.getResolveResult() == null) @@ -73,12 +79,7 @@ public InstallResult execute(@NotNull InstallArgument argument) th return new DownloadArgument(result.getResolveResult().getDownloadUrl()); }) .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(progress, signalHandler)) - .bridgeArgument(result -> { - if (result.getPath() == null) - throw new IllegalArgumentException("Plugin Description Loading must be successful"); - - return new DescriptionLoadArgument(result.getPath()); - }) + .bridgeArgument(result -> new DescriptionLoadArgument(result.getPath())) .submitAll(new PluginResolveArgument(query)); DescriptionLoadResult descriptionLoadResult = (DescriptionLoadResult) pluginDescriptionResult; @@ -136,10 +137,16 @@ public InstallResult execute(@NotNull InstallArgument argument) th // region Do collect dependencies, compute dependencies load order and install them. TaskResult installResult = - this.submitter(InstallTasks.COLLECTING_DEPENDENCIES, new DependsCollectTask(progress, signalHandler)) + this.submitter( + InstallTasks.COLLECTING_DEPENDENCIES, + new DependsCollectTask(this.daemon, progress, signalHandler) + ) .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(progress, signalHandler)) .bridgeArgument(result -> new DependsComputeOrderArgument(result.getCollectedPlugins())) - .then(InstallTasks.INSTALLING_PLUGINS, new PluginsInstallTask(progress, signalHandler)) + .then( + InstallTasks.INSTALLING_PLUGINS, + new PluginsInstallTask(this.daemon, progress, signalHandler) + ) .bridgeArgument(result -> new PluginsInstallArgument( pluginFilePath, pluginDescription, query, result.getOrder() )) @@ -160,11 +167,9 @@ private void removeOldPlugin(Plugin plugin) File oldPluginFile = PluginUtil.getFile(plugin); - PluginLoader.getInstance().unloadPlugin(plugin); // TODO: Replace with uninstall. + this.daemon.getPluginLoader().unloadPlugin(plugin); // TODO: Replace with uninstall. if (!safeDelete(oldPluginFile)) - Runner.runLater(() -> { - safeDelete(oldPluginFile); - }, 10L); + Runner.runLater(() -> safeDelete(oldPluginFile), 10L); } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index 4ca6c845..9f51c29f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; @@ -43,9 +43,12 @@ */ public class PluginUninstaller extends AbstractInstaller { - public PluginUninstaller(SignalHandleManager signalHandler) throws IOException + private final KPMDaemon daemon; + + public PluginUninstaller(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { super(signalHandler); + this.daemon = daemon; } @Override @@ -138,7 +141,7 @@ public InstallResult execute(@NotNull UninstallArgument argument ) .then( UnInstallTasks.UNINSTALLING_PLUGINS, - new UnInstallTask(this.progress, this.signalHandler) + new UnInstallTask(this.daemon, this.progress, this.signalHandler) ) .bridgeArgument(computeResult -> { List ordered = computeResult.getOrder(); @@ -173,7 +176,7 @@ private ArrayList getAllDependencies(Plugin target) ArrayList plugins = new ArrayList<>(); List dependencies = - TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().getDependOn(target.getName()); + this.daemon.getPluginMetaManager().getProvider().getDependOn(target.getName()); for (DependencyNode depend : dependencies) { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java index 1bdd02a8..268fc29b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.signals.UpdateFinishedSignal; @@ -26,9 +27,12 @@ */ public class AliasUpdater extends AbstractInstaller { - public AliasUpdater(SignalHandleManager signalHandler) throws IOException + private final KPMDaemon daemon; + + public AliasUpdater(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { super(signalHandler); + this.daemon = daemon; } @Override @@ -43,7 +47,7 @@ public InstallResult execute(@NotNull UpdateArgument argument) thro ) .then( UpdateTasks.UPDATING_ALIASES, - new UpdateAliasesTask(this.progress, this.signalHandler) + new UpdateAliasesTask(this.daemon, this.progress, this.signalHandler) ) .bridgeArgument(sourceDownloadResult -> new UpdateAliasesArgument(sourceDownloadResult.getDownloadedSources())) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java index 653fc972..9dbe43f2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java @@ -3,7 +3,7 @@ import com.google.gson.JsonSyntaxException; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasUpdater; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; @@ -28,11 +28,14 @@ */ public class UpdateAliasesTask extends InstallTask { + private final KPMDaemon daemon; + private UpdateAliasesState status; - public UpdateAliasesTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + public UpdateAliasesTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); + this.daemon = daemon; this.status = UpdateAliasesState.INITIALIZED; } @@ -77,7 +80,7 @@ public UpdateAliasesTask(@NotNull InstallProgress progress, @NotNull Signa private long updateAliasesFromSource(String sourceName, URL url, Path source) { - AliasUpdater updater = TeamKunPluginManager.getPlugin().getAliasProvider().createUpdater( + AliasUpdater updater = this.daemon.getAliasProvider().createUpdater( sourceName, url.toString() ); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 945becf8..c7016466 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -1,5 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; @@ -51,15 +52,17 @@ */ public class DependsCollectTask extends InstallTask { // TODO: きれいに + private final KPMDaemon daemon; private final SignalHandleManager signalHandler; private final DependsCollectStatus status; private DependsCollectState taskState; - public DependsCollectTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + public DependsCollectTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); + this.daemon = daemon; this.signalHandler = signalHandler; this.status = progress.getDependsCollectStatus(); @@ -123,7 +126,6 @@ public DependsCollectTask(@NotNull InstallProgress progress, @NotNull Sign Path pluginPath = downloadResults.get(actualName).getPath(); - assert pluginPath != null; this.status.onCollect( exceptedName, new DependencyElement(exceptedName, pluginPath, @@ -160,7 +162,7 @@ private DependsCollectResult passCollector(@NotNull PluginDescriptionFile plugin { DependsCollectArgument arguments = new DependsCollectArgument(pluginDescription, alreadyCollectedPlugins); - return new DependsCollectTask(this.progress, this.signalHandler) // do new() because DependsCollectTask is stateful. + return new DependsCollectTask(this.daemon, this.progress, this.signalHandler) // do new() because DependsCollectTask is stateful. .runTask(arguments); } @@ -191,9 +193,6 @@ private PluginDescriptionFile downloadResultToPluginDescriptionFile(@NotNull Dow { Path pluginPath = downloadResult.getPath(); - if (pluginPath == null) - return null; - return PluginUtil.loadDescription(pluginPath.toFile()); } catch (Exception e) @@ -253,7 +252,7 @@ private PluginResolveResult passResolver(@NotNull String dependency) { PluginResolveArgument resolveArgument = new PluginResolveArgument(dependency); - return new PluginResolveTask(this.progress, this.signalHandler) + return new PluginResolveTask(this.daemon, this.progress, this.signalHandler) .runTask(resolveArgument); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index 450633d3..c8a3c7cd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; @@ -12,6 +13,8 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.InstallOperator; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; +import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; @@ -50,12 +53,18 @@ public class PluginsInstallTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public PluginsInstallTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); + PluginMetaManager pluginMetaManager = daemon.getPluginMetaManager(); + this.pluginMetaManager = pluginMetaManager; + this.pluginMetaProvider = pluginMetaManager.getProvider(); + this.state = PluginsInstallState.INITIALIZED; } @@ -91,7 +100,7 @@ private static void patchPluginCommands(List targets) } for (Plugin plugin : installedPlugins) - TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().buildDependencyTree(plugin); + this.pluginMetaProvider.buildDependencyTree(plugin); // Install plugin after dependencies installed @@ -101,7 +110,7 @@ private static void patchPluginCommands(List targets) ); if (result.isSuccess() && result.getInstalledPlugin() != null) - TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().buildDependencyTree(result.getInstalledPlugin()); + this.pluginMetaProvider.buildDependencyTree(result.getInstalledPlugin()); return result; } @@ -164,7 +173,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr } // Enable plugin - TeamKunPluginManager.getPlugin().getPluginMetaManager().preparePluginModify(target); + this.pluginMetaManager.preparePluginModify(target); this.state = PluginsInstallState.PLUGIN_ENABLING; this.postSignal(new PluginEnablingSignal.Pre(target)); PLUGIN_MANAGER.enablePlugin(target); @@ -172,7 +181,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr installedPlugins.add(target); - TeamKunPluginManager.getPlugin().getPluginMetaManager().onInstalled( + this.pluginMetaManager.onInstalled( target, isDependency ? InstallOperator.KPM_DEPENDENCY_RESOLVER: InstallOperator.SERVER_ADMIN, query, diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java index 16b615fe..4a33c9dc 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; @@ -20,18 +20,14 @@ */ public class PluginResolveTask extends InstallTask { - private static final PluginResolver PLUGIN_RESOLVER; - - static - { - PLUGIN_RESOLVER = TeamKunPluginManager.getPlugin().getResolver(); - } + private final PluginResolver resolver; private PluginResolveState taskState; - public PluginResolveTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + public PluginResolveTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); + this.resolver = daemon.getPluginResolver(); this.taskState = PluginResolveState.INITIALIZED; } @@ -67,9 +63,9 @@ public PluginResolveTask(@NotNull InstallProgress progress, @NotNull Signa String query = arguments.getQuery(); this.taskState = PluginResolveState.PRE_RESOLVING; - this.postSignal(new PluginResolvingSignal(PLUGIN_RESOLVER, query)); + this.postSignal(new PluginResolvingSignal(this.resolver, query)); - ResolveResult queryResolveResult = PLUGIN_RESOLVER.resolve(query); + ResolveResult queryResolveResult = this.resolver.resolve(query); this.taskState = PluginResolveState.PRE_RESOLVE_FINISHED; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 509aa3e4..b989b3bf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; @@ -79,13 +80,16 @@ public class UnInstallTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public UnInstallTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); + this.daemon = daemon; - taskState = UnInstallState.INITIALIZED; + this.taskState = UnInstallState.INITIALIZED; } @Override @@ -101,7 +105,7 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan for (Plugin plugin : orderedUninstallTargets) { - TeamKunPluginManager.getPlugin().getPluginMetaManager().preparePluginModify(plugin.getName()); + this.daemon.getPluginMetaManager().preparePluginModify(plugin.getName()); PluginDescriptionFile description = plugin.getDescription(); UnInstallErrorCause errorCause = uninstallOnePlugin(plugin); @@ -120,7 +124,7 @@ public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHan if (pluginFile.exists()) pluginFile.delete(); - TeamKunPluginManager.getPlugin().getPluginMetaManager().onUninstalled(plugin.getName()); + this.daemon.getPluginMetaManager().onUninstalled(plugin.getName()); }), 20L); orderedUninstallTargets.stream() diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java index 7e15d48e..ee8c9cfb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/loader/PluginLoader.java @@ -34,8 +34,6 @@ */ public class PluginLoader { - private static PluginLoader INSTANCE; - private final PluginManager pluginManager; private final CommandsPatcher commandsPatcher; @@ -47,27 +45,12 @@ public class PluginLoader public PluginLoader() { - setInstance(this); - this.pluginManager = Bukkit.getPluginManager(); this.commandsPatcher = new CommandsPatcher(); this.initReflections(); } - public static PluginLoader getInstance() - { - return INSTANCE; - } - - private static void setInstance(@NotNull PluginLoader instance) - { - if (INSTANCE != null) - throw new IllegalStateException("PluginLoader is already initialized."); - - INSTANCE = instance; - } - @SuppressWarnings("unchecked") private void initReflections() { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/BruteforceGitHubResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/BruteforceGitHubResolver.java index a4d29b5c..2979e9a2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/BruteforceGitHubResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/BruteforceGitHubResolver.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; import lombok.AllArgsConstructor; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; @@ -13,14 +12,13 @@ @AllArgsConstructor public class BruteforceGitHubResolver implements BaseResolver { - private final TeamKunPluginManager plugin; + private final Object gitHubName; private final GitHubURLResolver gitHubURLResolver; @Override public ResolveResult resolve(QueryContext query) { - - Object obj = plugin.getPluginConfig().get("gitHubName"); + Object obj = gitHubName; if (obj instanceof String) // Legacy support { @@ -33,7 +31,10 @@ public ResolveResult resolve(QueryContext query) ResolveResult result = new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); - for (String str : plugin.getPluginConfig().getStringList("gitHubName")) + if ((obj instanceof List)) + return result; + + for (String str : (List) obj) { query.setQuery("https://github.com/" + str + "/" + query.getQuery()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java index 2ddb98c0..a708aab5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java @@ -1,8 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; -import lombok.AllArgsConstructor; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.plugin.alias.Alias; +import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasProvider; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; @@ -10,16 +10,23 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import org.jetbrains.annotations.NotNull; -@AllArgsConstructor public class KnownPluginsResolver implements BaseResolver { private final PluginResolver resolver; + private final AliasProvider aliasProvider; + + public KnownPluginsResolver(@NotNull KPMDaemon daemon) + { + this.resolver = daemon.getPluginResolver(); + this.aliasProvider = daemon.getAliasProvider(); + } @Override public ResolveResult resolve(QueryContext query) { - Alias alias = TeamKunPluginManager.getPlugin().getAliasProvider().getAlias(query.getQuery()); + Alias alias = this.aliasProvider.getAlias(query.getQuery()); if (alias == null) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java index 53322c66..246d90ae 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java @@ -1,25 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.utils; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import org.bukkit.ChatColor; -import java.util.List; - public class Messages { - public static String getUnInstallableMessage() - { - List rmble = TeamKunPluginManager.getPlugin().getPluginMetaManager().getProvider().getUnusedPlugins(); - - if (rmble.isEmpty()) - return ""; - - return ChatColor.BLUE + "以下のプラグインがインストールされていますが、もう必要とされていません:\n" + - ChatColor.GREEN + " " + String.join(" ", rmble) + "\n" + - ChatColor.BLUE + "これを削除するには、'/kpm autoremove' を利用してください。"; - } - public static String getModifyMessage(ModifyType type, String name) { switch (type) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 7f12508d..4dd6761a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -2,6 +2,7 @@ import lombok.Getter; import lombok.Setter; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; @@ -22,6 +23,13 @@ public class Requests { + private static final KPMDaemon DAEMON; + + static + { + DAEMON = KPMDaemon.getInstance(); + } + @Getter @Setter private static int REDIRECT_LIMIT = 15; @@ -66,8 +74,11 @@ private static Map setupDefaultHeaders(@NotNull String host) { headers.put("Accept", "application/vnd.github.v3+json"); - if (TeamKunPluginManager.getPlugin().isTokenAvailable()) - headers.put("Authorization", "Token " + TeamKunPluginManager.getPlugin().getTokenStore().getToken()); + if (DAEMON.getTokenStore().isTokenAvailable()) + headers.put( + "Authorization", + "Token " + DAEMON.getTokenStore().getToken() + ); } else if (host.equalsIgnoreCase("file.io")) From e69e6faceb4e8fc199eef4b796bc141ed538ea42 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 10 Oct 2022 21:39:27 +0900 Subject: [PATCH 355/745] refactor: Remove Messages --- .../commands/CommandInfo.java | 112 ++++++++++-------- .../teamkunpluginmanager/utils/Messages.java | 50 -------- 2 files changed, 63 insertions(+), 99 deletions(-) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index 501be2cc..b80b3c93 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -9,7 +9,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.meta.InstallOperator; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMeta; import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import net.kyori.adventure.text.Component; @@ -57,25 +56,25 @@ private static Component dependTree(String name, List l) @SuppressWarnings("unchecked") private static Component commandHover(String name, Map command) { - Component component = Component.text(Messages.keyValue("コマンド名", name + "\n\n")); + Component component = Component.text(keyValue("コマンド名", name + "\n\n")); if (command.containsKey("aliases")) { if (command.get("aliases") instanceof String) - component = component.append(Component.text(Messages.keyValue("エイリアス", "/" + command.get("aliases")))); + component = component.append(Component.text(keyValue("エイリアス", "/" + command.get("aliases")))); else if (command.get("aliases") instanceof List) - component = component.append(Component.text(Messages.keyValue( + component = component.append(Component.text(keyValue( "エイリアス", "/" + String.join(", /", (List) command.get("aliases")) ) + "\n")); } if (command.containsKey("usage")) - component = component.append(Component.text(Messages.keyValue("使用法", command.get("usage")) + "\n")); + component = component.append(Component.text(keyValue("使用法", command.get("usage")) + "\n")); if (command.containsKey("description")) - component = component.append(Component.text(Messages.keyValue("概要", command.get("description")) + "\n")); + component = component.append(Component.text(keyValue("概要", command.get("description")) + "\n")); if (command.containsKey("permission")) - component = component.append(Component.text(Messages.keyValue("権限", command.get("permission")) + "\n")); + component = component.append(Component.text(keyValue("権限", command.get("permission")) + "\n")); return component; } @@ -115,6 +114,50 @@ private static String getInstalledByString(InstallOperator operator) } } + private static String keyValue(String property, String value) + { + return ChatColor.GREEN + property + ChatColor.WHITE + ": " + ChatColor.DARK_GREEN + value; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (args.length == 1) + return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() + .map(Plugin::getName).collect(Collectors.toList()); + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.info"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("インストールされているプラグインの詳細を表示します。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + required("pluginName", "string") + }; + } + + private static String keyValueYesNo(String property, boolean a) + { + return ChatColor.GREEN + property + ChatColor.WHITE + ": " + (a ? ChatColor.DARK_GREEN + "はい": ChatColor.RED + "いいえ"); + } + + private static String keyValue(String property, Object obj) + { + return ChatColor.GREEN + property + ChatColor.WHITE + ": " + obj.toString(); + } + @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -145,37 +188,37 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, terminal.info("情報を読み込み中..."); File file = PluginUtil.getFile(plugin); - terminal.writeLine(Messages.keyValue("名前", meta.getName())); - terminal.writeLine(Messages.keyValue("作成者", String.join(", ", meta.getAuthors()))); - terminal.writeLine(Messages.keyValue("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); - terminal.writeLine(Messages.keyValue("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); - terminal.writeLine(Messages.keyValueYesNo( + terminal.writeLine(keyValue("名前", meta.getName())); + terminal.writeLine(keyValue("作成者", String.join(", ", meta.getAuthors()))); + terminal.writeLine(keyValue("状態", plugin.isEnabled() ? ChatColor.DARK_GREEN + "有効": ChatColor.RED + "無効")); + terminal.writeLine(keyValue("読み込みタイミング", PluginUtil.loadToString(plugin.getDescription().getLoad()))); + terminal.writeLine(keyValueYesNo( "保護", TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream().parallel() .anyMatch(s -> s.equalsIgnoreCase(meta.getName())) )); if (plugin.getDescription().getWebsite() != null) - terminal.writeLine(Messages.keyValue("ウェブサイト", ChatColor.UNDERLINE + plugin.getDescription().getWebsite())); + terminal.writeLine(keyValue("ウェブサイト", ChatColor.UNDERLINE + plugin.getDescription().getWebsite())); if (plugin.getDescription().getPrefix() != null) - terminal.writeLine(Messages.keyValue("ログ接頭辞", plugin.getDescription().getPrefix())); + terminal.writeLine(keyValue("ログ接頭辞", plugin.getDescription().getPrefix())); if (plugin.getDescription().getDescription() != null) - terminal.writeLine(Messages.keyValue("概要", plugin.getDescription().getDescription())); + terminal.writeLine(keyValue("概要", plugin.getDescription().getDescription())); if (file != null) { terminal.writeLine(""); - terminal.writeLine(Messages.keyValue("ファイル名", file.getName())); - terminal.writeLine(Messages.keyValue("ダウンロードサイズ", Utils.roundSizeUnit(file.length()))); + terminal.writeLine(keyValue("ファイル名", file.getName())); + terminal.writeLine(keyValue("ダウンロードサイズ", Utils.roundSizeUnit(file.length()))); } terminal.writeLine(""); - terminal.writeLine(Messages.keyValue( + terminal.writeLine(keyValue( "インストール者", getInstalledByString(meta.getInstalledBy()) )); - terminal.writeLine(Messages.keyValueYesNo("依存関係?", meta.isDependency())); - terminal.writeLine(Messages.keyValue("インストール日時", epochToString(meta.getInstalledAt()))); + terminal.writeLine(keyValueYesNo("依存関係?", meta.isDependency())); + terminal.writeLine(keyValue("インストール日時", epochToString(meta.getInstalledAt()))); terminal.writeLine(""); @@ -203,33 +246,4 @@ else if (dep.getDependType() == DependType.SOFT_DEPEND) terminal.writeLine(""); terminal.write(commandList(plugin.getDescription().getCommands())); } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) - { - if (args.length == 1) - return Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() - .map(Plugin::getName).collect(Collectors.toList()); - return null; - } - - @Override - public @Nullable String getPermission() - { - return "kpm.info"; - } - - @Override - public TextComponent getHelpOneLine() - { - return of("インストールされているプラグインの詳細を表示します。"); - } - - @Override - public String[] getArguments() - { - return new String[]{ - required("pluginName", "string") - }; - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java deleted file mode 100644 index 246d90ae..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Messages.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -import org.bukkit.ChatColor; - -public class Messages -{ - - public static String getModifyMessage(ModifyType type, String name) - { - switch (type) - { - case ADD: - return ChatColor.GREEN + "+ " + name; - case MODIFY: - return ChatColor.YELLOW + "~ " + name; - case REMOVE: - return ChatColor.RED + "- " + name; - default: - return ChatColor.GOLD + "? " + name; - } - } - - public static String getStatusMessage(int installed, int removed, int modified) - { - return ChatColor.GREEN.toString() + installed + " 追加 " + ChatColor.RED + removed + " 削除 " + ChatColor.YELLOW + modified + " 変更"; - } - - public static String keyValue(String property, String value) - { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + ChatColor.DARK_GREEN + value; - } - - public static String keyValueYesNo(String property, boolean a) - { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + (a ? ChatColor.DARK_GREEN + "はい": ChatColor.RED + "いいえ"); - } - - public static String keyValue(String property, Object obj) - { - return ChatColor.GREEN + property + ChatColor.WHITE + ": " + obj.toString(); - } - - public enum ModifyType - { - ADD, - REMOVE, - MODIFY - } - -} From 32b3f689ea980d28f23c9bc80a278bdde6571bfb Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 10 Oct 2022 22:45:49 +0900 Subject: [PATCH 356/745] feat: wip: Multi-module --- KPMDaemon/pom.xml | 21 +++++ .../lab/teamkunpluginmanager/KPMDaemon.java | 79 +++++++++++++------ .../teamkunpluginmanager}/alias/Alias.java | 2 +- .../alias/AliasProvider.java | 2 +- .../alias/AliasSource.java | 2 +- .../alias/AliasUpdater.java | 2 +- .../installer/AbstractInstaller.java | 23 +++--- .../installer/AbstractInstallerArgument.java | 5 ++ .../installer/InstallFailedInstallResult.java | 2 +- .../installer/InstallManager.java | 27 +++---- .../installer/InstallProgress.java | 18 +++-- .../installer/InstallResult.java | 2 +- .../impls/autoremove/AutoRemoveArgument.java | 4 +- .../autoremove/AutoRemoveErrorCause.java | 2 +- .../autoremove/AutoRemoveSucceedResult.java | 8 +- .../impls/autoremove/AutoRemoveTasks.java | 2 +- .../impls/autoremove/PluginAutoRemover.java | 24 +++--- .../signals/PluginEnumeratedSignal.java | 4 +- .../signals/PluginUninstallFailedSignal.java | 8 +- .../installer/impls/clean/CleanArgument.java | 4 +- .../impls/clean/CleanErrorCause.java | 2 +- .../installer/impls/clean/CleanTasks.java | 2 +- .../clean/GarbageCleanSucceedResult.java | 6 +- .../installer/impls/clean/GarbageCleaner.java | 26 +++--- .../impls/install/InstallArgument.java | 4 +- .../impls/install/InstallErrorCause.java | 6 +- .../installer/impls/install/InstallTasks.java | 16 ++-- .../impls/install/PluginInstaller.java | 42 +++++----- .../signals/AlreadyInstalledPluginSignal.java | 4 +- .../PluginUninstallSucceedResult.java | 8 +- .../impls/uninstall/PluginUninstaller.java | 32 ++++---- .../impls/uninstall/UnInstallErrorCause.java | 6 +- .../impls/uninstall/UnInstallTasks.java | 2 +- .../impls/uninstall/UninstallArgument.java | 4 +- .../signals/PluginIsDependencySignal.java | 4 +- .../signals/SearchingPluginSignal.java | 4 +- .../signals/UninstallReadySignal.java | 4 +- .../installer/impls/update/AliasUpdater.java | 22 +++--- .../impls/update/UpdateArgument.java | 4 +- .../impls/update/UpdateErrorCause.java | 2 +- .../installer/impls/update/UpdateTasks.java | 2 +- .../update/signals/UpdateFinishedSignal.java | 4 +- .../signals/InstallFinishedSignal.java | 6 +- .../signals/PluginModifiedSignal.java | 4 +- .../assertion/IgnoredPluginSignal.java | 4 +- .../installer/task/InstallTask.java | 8 +- .../installer/task/TaskArgument.java | 2 +- .../installer/task/TaskChain.java | 4 +- .../installer/task/TaskFailedException.java | 2 +- .../installer/task/TaskResult.java | 2 +- .../download/SourceDownloadArgument.java | 4 +- .../download/SourceDownloadErrorCause.java | 2 +- .../source/download/SourceDownloadResult.java | 4 +- .../source/download/SourceDownloadState.java | 2 +- .../source/download/SourceDownloadTask.java | 22 +++--- .../download/signals/InvalidRemoteSignal.java | 4 +- .../download/signals/MalformedURLSignal.java | 2 +- .../signals/SourceDownloadFailedSignal.java | 15 ++++ .../signals/UnsupportedProtocolSignal.java | 2 +- .../alias/update/UpdateAliasesArgument.java | 4 +- .../alias/update/UpdateAliasesErrorCause.java | 2 +- .../alias/update/UpdateAliasesResult.java | 4 +- .../alias/update/UpdateAliasesState.java | 2 +- .../tasks/alias/update/UpdateAliasesTask.java | 16 ++-- .../update/signals/AliasUpdateSignal.java | 4 +- .../update/signals/InvalidSourceSignal.java | 2 +- .../update/signals/SourcePreparedSignal.java | 2 +- .../alias/update/signals/SourceSignal.java | 4 +- .../tasks/dependencies/DependencyElement.java | 2 +- .../collector/DependsCollectArgument.java | 4 +- .../collector/DependsCollectErrorCause.java | 2 +- .../collector/DependsCollectResult.java | 6 +- .../collector/DependsCollectState.java | 2 +- .../collector/DependsCollectStatus.java | 6 +- .../collector/DependsCollectTask.java | 42 +++++----- ...CollectDependencysDependsFailedSignal.java | 4 +- .../DependencyCollectFailedSignalBase.java | 4 +- .../DependencyDownloadFailedSignal.java | 2 +- ...DependencyLoadDescriptionFailedSignal.java | 2 +- .../signals/DependencyNameMismatchSignal.java | 2 +- .../DependencyResolveFailedSignal.java | 2 +- .../signals/DependsCollectFailedSignal.java | 4 +- .../DependsDownloadFinishedSignal.java | 6 +- .../signals/DependsEnumeratedSignal.java | 4 +- .../computer/DependsComputeOrderArgument.java | 6 +- .../DependsComputeOrderErrorCause.java | 2 +- .../computer/DependsComputeOrderResult.java | 6 +- .../computer/DependsComputeOrderState.java | 2 +- .../computer/DependsComputeOrderTask.java | 12 +-- .../DependsLoadOrderComputingSignal.java | 6 +- .../description/DescriptionLoadArgument.java | 4 +- .../DescriptionLoadErrorCause.java | 2 +- .../description/DescriptionLoadResult.java | 4 +- .../description/DescriptionLoadState.java | 2 +- .../description/DescriptionLoadTask.java | 10 +-- .../signals/LoadPluginDescriptionSignal.java | 4 +- .../task/tasks/download/DownloadArgument.java | 4 +- .../tasks/download/DownloadErrorCause.java | 2 +- .../task/tasks/download/DownloadResult.java | 4 +- .../task/tasks/download/DownloadState.java | 2 +- .../task/tasks/download/DownloadTask.java | 18 ++--- .../download/signals/DownloadErrorSignal.java | 4 +- .../signals/DownloadProgressSignal.java | 2 +- .../download/signals/DownloadSignal.java | 4 +- .../signals/DownloadStartingSignal.java | 2 +- .../signals/DownloadSucceedSignal.java | 2 +- .../garbage/clean/GarbageCleanArgument.java | 4 +- .../garbage/clean/GarbageCleanErrorCause.java | 2 +- .../garbage/clean/GarbageCleanResult.java | 4 +- .../garbage/clean/GarbageCleanState.java | 2 +- .../tasks/garbage/clean/GarbageCleanTask.java | 18 ++--- .../signal/GarbageDeleteSkippedSignal.java | 4 +- .../clean/signal/GarbageDeletingSignal.java | 4 +- .../clean/signal/GarbageEnumeratedSignal.java | 4 +- .../clean/signal/InvalidIntegritySignal.java | 4 +- .../garbage/search/GarbageSearchArgument.java | 18 +---- .../search/GarbageSearchErrorCause.java | 2 +- .../garbage/search/GarbageSearchResult.java | 4 +- .../garbage/search/GarbageSearchState.java | 2 +- .../garbage/search/GarbageSearchTask.java | 10 +-- .../signals/GarbageSearchingSignal.java | 4 +- .../tasks/install/PluginsInstallArgument.java | 6 +- .../install/PluginsInstallErrorCause.java | 2 +- .../tasks/install/PluginsInstallResult.java | 4 +- .../tasks/install/PluginsInstallState.java | 2 +- .../tasks/install/PluginsInstallTask.java | 31 ++++---- .../install/signals/PluginEnablingSignal.java | 4 +- .../signals/PluginInstallingSignal.java | 4 +- .../install/signals/PluginLoadSignal.java | 4 +- .../signals/PluginOnLoadRunningSignal.java | 4 +- .../signals/PluginRelocatingSignal.java | 4 +- .../tasks/resolve/PluginResolveArgument.java | 4 +- .../resolve/PluginResolveErrorCause.java | 4 +- .../tasks/resolve/PluginResolveResult.java | 6 +- .../tasks/resolve/PluginResolveState.java | 2 +- .../task/tasks/resolve/PluginResolveTask.java | 24 +++--- .../signals/MultiplePluginResolvedSignal.java | 10 +-- .../signals/PluginResolveErrorSignal.java | 6 +- .../PluginResolvedSuccessfulSignal.java | 6 +- .../signals/PluginResolvingSignal.java | 6 +- .../tasks/uninstall/UnInstallArgument.java | 4 +- .../tasks/uninstall/UnInstallErrorCause.java | 2 +- .../task/tasks/uninstall/UnInstallResult.java | 4 +- .../task/tasks/uninstall/UnInstallState.java | 2 +- .../task/tasks/uninstall/UnInstallTask.java | 27 +++---- .../signals/PluginDisablingSignal.java | 4 +- .../signals/PluginRegisteredRecipeSignal.java | 4 +- .../signals/PluginUninstallErrorSignal.java | 6 +- .../signals/PluginUninstallingSignal.java | 4 +- .../signals/PluginUnloadingSignal.java | 4 +- .../uninstall/signals/StartingGCSignal.java | 10 +++ .../loader/CommandsPatcher.java | 2 +- .../loader/PluginLoadResult.java | 2 +- .../loader/PluginLoader.java | 12 +-- .../meta/DependType.java | 2 +- .../meta/DependencyNode.java | 2 +- .../meta/InstallOperator.java | 2 +- .../meta/MetaSQLUtil.java | 2 +- .../meta/PluginMeta.java | 2 +- .../meta/PluginMetaManager.java | 7 +- .../meta/PluginMetaProvider.java | 2 +- .../resolver/PluginResolver.java | 12 +-- .../resolver/QueryContext.java | 2 +- .../impl/BruteforceGitHubResolver.java | 31 ++------ .../resolver/impl/CurseBukkitResolver.java | 12 +-- .../impl/CurseBukkitSuccessResult.java | 6 +- .../resolver/impl/GitHubSuccessResult.java | 8 +- .../resolver/impl/GitHubURLResolver.java | 14 ++-- .../resolver/impl/KnownPluginsResolver.java | 20 ++--- .../resolver/impl/OmittedGitHubResolver.java | 12 +-- .../resolver/impl/SpigotMCResolver.java | 12 +-- .../resolver/impl/SpigotMCSuccessResult.java | 10 +-- .../resolver/interfaces/BaseResolver.java | 10 +-- .../resolver/interfaces/URLResolver.java | 8 +- .../resolver/result/ErrorResult.java | 4 +- .../resolver/result/MarketplaceResult.java | 2 +- .../resolver/result/MultiResult.java | 4 +- .../resolver/result/PipeResult.java | 6 +- .../resolver/result/ResolveResult.java | 4 +- .../resolver/result/SuccessResult.java | 4 +- .../resolver/result/VersionedResult.java | 2 +- .../teamkunpluginmanager}/signal/Signal.java | 2 +- .../signal/SignalHandleManager.java | 4 +- .../signal/SignalHandler.java | 2 +- .../signal/SignalHandlerList.java | 4 +- .../teamkunpluginmanager/utils/HashLib.java | 0 .../lab/teamkunpluginmanager/utils/Pair.java | 0 .../utils/PluginUtil.java | 0 .../utils/ReflectionUtils.java | 0 .../teamkunpluginmanager/utils/ResultRow.java | 0 .../utils/ReversedCollector.java | 0 .../utils/TokenStore.java | 0 .../utils/Transaction.java | 0 .../lab/teamkunpluginmanager/utils/Utils.java | 2 +- .../utils/http/DownloadProgress.java | 0 .../utils/http/HTTPResponse.java | 0 .../utils/http/RequestContext.java | 0 .../utils/http/RequestMethod.java | 0 .../utils/http/Requests.java | 3 +- KPMPlugin/pom.xml | 29 +++++++ .../TeamKunPluginManager.java | 23 +++++- .../commands/CommandAutoRemove.java | 2 +- .../commands/CommandClean.java | 2 +- .../commands/CommandDebug.java | 0 .../commands/CommandInfo.java | 8 +- .../commands/CommandInstall.java | 2 +- .../commands/CommandRegister.java | 0 .../commands/CommandReload.java | 0 .../commands/CommandResolve.java | 16 ++-- .../commands/CommandStatus.java | 4 +- .../commands/CommandUninstall.java | 2 +- .../commands/CommandUpdate.java | 18 +---- .../commands/debug/CommandDepTreeDebug.java | 2 +- .../commands/debug/CommandInstallDebug.java | 12 +-- .../commands/debug/CommandUninstallDebug.java | 12 +-- .../commands/debug/DebugSignalHandler.java | 14 ++-- .../deptree/CommandMarkAsDependency.java | 2 +- .../commands/debug/deptree/CommandPurge.java | 2 +- .../debug/deptree/CommandRelation.java | 8 +- .../commands/signal/HeadSignalHandlers.java | 0 .../commands/signal/SignalHandlingUtils.java | 0 .../AutoRemoveFinishedSignalHandler.java | 6 +- .../AutoRemoveReadySignalHandler.java | 4 +- .../GarbageCleanFinishedSignalHandler.java | 6 +- .../clean/GarbageCleanSignalHandler.java | 6 +- .../common/CheckEnvSignalHandler.java | 6 +- .../common/DownloadingSignalHandler.java | 8 +- .../common/InstallFinishedSignalBase.java | 8 +- .../handlers/common/ModifySignalHandler.java | 4 +- .../intall/DependenciesSignalHandler.java | 12 +-- .../intall/InstallFinishedSignalHandler.java | 16 ++-- .../intall/InstallerSignalHandler.java | 10 +-- .../intall/ResolverSignalHandler.java | 10 +-- .../PluginIsDependencySignalHandler.java | 4 +- .../UninstallFinishedSignalHandler.java | 12 +-- .../UninstallReadySignalHandler.java | 4 +- .../uninstall/UninstallerSignalHandler.java | 12 +-- .../update/UpdateAliasesSignalHandler.java | 10 +-- .../src}/main/resources/config.v2.yml | 0 .../src}/main/resources/config.yml | 0 .../src}/main/resources/plugin.yml | 0 pom.xml | 6 +- .../installer/AbstractInstallerArgument.java | 5 -- .../signals/SourceDownloadFailedSignal.java | 15 ---- .../uninstall/signals/StartingGCSignal.java | 10 --- .../resolver/PluginResolverTest.java | 71 ----------------- .../result/http/RequestsTest.java | 72 ----------------- 247 files changed, 845 insertions(+), 929 deletions(-) create mode 100644 KPMDaemon/pom.xml rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java (65%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/alias/Alias.java (84%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/alias/AliasProvider.java (98%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/alias/AliasSource.java (93%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/alias/AliasUpdater.java (97%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/AbstractInstaller.java (80%) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/InstallFailedInstallResult.java (94%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/InstallManager.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/InstallProgress.java (94%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/InstallResult.java (98%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/autoremove/AutoRemoveArgument.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/autoremove/AutoRemoveErrorCause.java (87%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/autoremove/AutoRemoveSucceedResult.java (56%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/autoremove/AutoRemoveTasks.java (79%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/autoremove/PluginAutoRemover.java (76%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/autoremove/signals/PluginEnumeratedSignal.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java (50%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/clean/CleanArgument.java (86%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/clean/CleanErrorCause.java (58%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/clean/CleanTasks.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/clean/GarbageCleanSucceedResult.java (80%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/clean/GarbageCleaner.java (67%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/install/InstallArgument.java (71%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/install/InstallErrorCause.java (50%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/install/InstallTasks.java (62%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/install/PluginInstaller.java (76%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/install/signals/AlreadyInstalledPluginSignal.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/PluginUninstallSucceedResult.java (57%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/PluginUninstaller.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/UnInstallErrorCause.java (52%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/UnInstallTasks.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/UninstallArgument.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/signals/PluginIsDependencySignal.java (88%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/signals/SearchingPluginSignal.java (62%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/uninstall/signals/UninstallReadySignal.java (81%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/update/AliasUpdater.java (65%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/update/UpdateArgument.java (73%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/update/UpdateErrorCause.java (62%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/update/UpdateTasks.java (80%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/impls/update/signals/UpdateFinishedSignal.java (73%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/signals/InstallFinishedSignal.java (54%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/signals/PluginModifiedSignal.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/signals/assertion/IgnoredPluginSignal.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/InstallTask.java (79%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/TaskArgument.java (57%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/TaskChain.java (97%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/TaskFailedException.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/TaskResult.java (92%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/SourceDownloadArgument.java (72%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java (71%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/SourceDownloadResult.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/SourceDownloadState.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/SourceDownloadTask.java (77%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java (72%) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java (83%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/UpdateAliasesArgument.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java (72%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/UpdateAliasesResult.java (88%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/UpdateAliasesState.java (80%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/UpdateAliasesTask.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/alias/update/signals/SourceSignal.java (76%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/DependencyElement.java (94%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/DependsCollectArgument.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java (71%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/DependsCollectResult.java (84%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/DependsCollectState.java (86%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/DependsCollectStatus.java (92%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/DependsCollectTask.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java (75%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java (74%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java (83%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java (76%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java (73%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java (75%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java (59%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java (75%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java (60%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java (63%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java (75%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java (84%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java (92%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/description/DescriptionLoadArgument.java (77%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/description/DescriptionLoadErrorCause.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/description/DescriptionLoadResult.java (87%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/description/DescriptionLoadState.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/description/DescriptionLoadTask.java (83%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java (77%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/DownloadArgument.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/DownloadErrorCause.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/DownloadResult.java (90%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/DownloadState.java (83%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/DownloadTask.java (83%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/signals/DownloadErrorSignal.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/signals/DownloadProgressSignal.java (92%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/signals/DownloadSignal.java (70%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/signals/DownloadStartingSignal.java (88%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/download/signals/DownloadSucceedSignal.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/GarbageCleanArgument.java (74%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/GarbageCleanResult.java (83%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/GarbageCleanState.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/GarbageCleanTask.java (79%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java (70%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java (86%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java (73%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java (58%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/search/GarbageSearchArgument.java (50%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java (69%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/search/GarbageSearchResult.java (87%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/search/GarbageSearchState.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/search/GarbageSearchTask.java (82%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java (65%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/PluginsInstallArgument.java (77%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/PluginsInstallErrorCause.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/PluginsInstallResult.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/PluginsInstallState.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/PluginsInstallTask.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/signals/PluginEnablingSignal.java (87%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/signals/PluginInstallingSignal.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/signals/PluginLoadSignal.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java (85%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/install/signals/PluginRelocatingSignal.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/PluginResolveArgument.java (75%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/PluginResolveErrorCause.java (75%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/PluginResolveResult.java (80%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/PluginResolveState.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/PluginResolveTask.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java (71%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java (58%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java (65%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/resolve/signals/PluginResolvingSignal.java (66%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/UnInstallArgument.java (71%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/UnInstallErrorCause.java (88%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/UnInstallResult.java (87%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/UnInstallState.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/UnInstallTask.java (86%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java (84%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java (94%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java (66%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java (66%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java (87%) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/StartingGCSignal.java rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/loader/CommandsPatcher.java (99%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/loader/PluginLoadResult.java (95%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/loader/PluginLoader.java (95%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/meta/DependType.java (90%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/meta/DependencyNode.java (86%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/meta/InstallOperator.java (93%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/meta/MetaSQLUtil.java (97%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/meta/PluginMeta.java (96%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/meta/PluginMetaManager.java (95%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/meta/PluginMetaProvider.java (99%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/PluginResolver.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/QueryContext.java (96%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/BruteforceGitHubResolver.java (55%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/CurseBukkitResolver.java (92%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/CurseBukkitSuccessResult.java (90%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/GitHubSuccessResult.java (84%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/GitHubURLResolver.java (93%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/KnownPluginsResolver.java (67%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/OmittedGitHubResolver.java (62%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/SpigotMCResolver.java (91%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/impl/SpigotMCSuccessResult.java (72%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/interfaces/BaseResolver.java (78%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/interfaces/URLResolver.java (93%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/result/ErrorResult.java (94%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/result/MarketplaceResult.java (88%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/result/MultiResult.java (65%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/result/PipeResult.java (60%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/result/ResolveResult.java (87%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/result/SuccessResult.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/resolver/result/VersionedResult.java (79%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/signal/Signal.java (90%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/signal/SignalHandleManager.java (95%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/signal/SignalHandler.java (89%) rename {src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/signal/SignalHandlerList.java (94%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java (95%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java (100%) rename {src => KPMDaemon/src}/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java (98%) create mode 100644 KPMPlugin/pom.xml rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java (77%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java (93%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java (94%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java (100%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java (97%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java (94%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java (100%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java (100%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java (89%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java (92%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java (95%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java (63%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java (95%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java (85%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java (85%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java (93%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java (97%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java (96%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java (94%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java (100%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java (100%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java (87%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java (89%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java (86%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java (80%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java (89%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java (87%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java (85%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java (88%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java (71%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java (88%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java (76%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java (87%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java (92%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java (80%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java (88%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java (77%) rename {src => KPMPlugin/src}/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java (77%) rename {src => KPMPlugin/src}/main/resources/config.v2.yml (100%) rename {src => KPMPlugin/src}/main/resources/config.yml (100%) rename {src => KPMPlugin/src}/main/resources/plugin.yml (100%) delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java delete mode 100644 src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java delete mode 100644 src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java delete mode 100644 src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml new file mode 100644 index 00000000..433890ed --- /dev/null +++ b/KPMDaemon/pom.xml @@ -0,0 +1,21 @@ + + + + TeamKunPluginManager + net.kunmc.lab + 3.0.0-pre5 + ../pom.xml + + 4.0.0 + + KPMDaemon + + + 8 + 8 + UTF-8 + + + diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 00024808..17b0adc2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -3,26 +3,29 @@ import lombok.AccessLevel; import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; -import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasProvider; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.BruteforceGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubURLResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.KnownPluginsResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallManager; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; +import net.kunmc.lab.teamkunpluginmanager.loader.PluginLoader; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; +import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.BruteforceGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.KnownPluginsResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; -import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; /** * KPMを操作するためのクラスです。 @@ -35,9 +38,8 @@ public class KPMDaemon @NotNull private static KPMDaemon INSTANCE; - @Getter(AccessLevel.NONE) @NotNull - private final TeamKunPluginManager kpmInstance; + private final Plugin plugin; /** * ログを出力するためのロガーです。 @@ -76,6 +78,11 @@ public class KPMDaemon */ @NotNull private final AliasProvider aliasProvider; + /** + * エイリアスのソースです。 + */ + @NotNull + private final HashMap sources; /** * プラグインをロード/アンロードするためのクラスです。 @@ -88,23 +95,28 @@ public class KPMDaemon } public KPMDaemon( - @NotNull TeamKunPluginManager kpmInstance, + @NotNull Plugin plugin, @NotNull Logger logger, @NotNull Path dataFolderPath, @NotNull Path databasePath, @NotNull Path tokenPath, @NotNull Path tokenKeyPath, - @NotNull Path aliasPath) + @NotNull Path aliasPath, + @NotNull List organizationNames, + @NotNull HashMap sources) { - this.kpmInstance = kpmInstance; + this.plugin = plugin; this.logger = logger; this.dataFolderPath = dataFolderPath; - this.pluginMetaManager = new PluginMetaManager(kpmInstance, databasePath); + this.pluginMetaManager = new PluginMetaManager(plugin, databasePath); this.tokenStore = new TokenStore(tokenPath, tokenKeyPath); this.pluginResolver = new PluginResolver(); this.aliasProvider = new AliasProvider(aliasPath); - this.pluginLoader = new PluginLoader(); + this.pluginLoader = new PluginLoader(this); this.installManager = new InstallManager(this); + this.sources = sources; + + this.setupDaemon(dataFolderPath, organizationNames); } /** @@ -118,13 +130,23 @@ public static KPMDaemon getInstance() return INSTANCE; } - public void setupDaemon(@NotNull Path dataFolder) + public void setupDaemon(@NotNull Path dataFolder, @NotNull List organizationNames) { this.setupDependencyTree(dataFolder); - this.setupPluginResolvers(); + this.setupPluginResolvers(organizationNames); this.setupToken(); } + private void firstUpdate() + { + Runner.runAsync(() -> { + this.getInstallManager().runUpdate( + Terminals.ofConsole(), + new UpdateArgument(this.sources) + ); + }); + } + private void setupDependencyTree(Path dataFolder) { logger.info("Loading plugin meta data ..."); @@ -132,11 +154,11 @@ private void setupDependencyTree(Path dataFolder) Path aliasFile = dataFolder.resolve("aliases.db"); boolean isFirstTime = !Files.exists(aliasFile); - if (isFirstTime && this.tokenStore.isTokenAvailable()) // Do update - new CommandUpdate(this).onCommand(Bukkit.getConsoleSender(), Terminals.ofConsole(), new String[0]); + if (isFirstTime && this.tokenStore.isTokenAvailable()) + this.firstUpdate(); } - private void setupPluginResolvers() + private void setupPluginResolvers(List organizationNames) { GitHubURLResolver githubResolver = new GitHubURLResolver(); this.pluginResolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); @@ -146,7 +168,7 @@ private void setupPluginResolvers() this.pluginResolver.addResolver(githubResolver, "github", "gh"); this.pluginResolver.addOnNotFoundResolver(new BruteforceGitHubResolver( - kpmInstance.getPluginConfig().get("githubName"), + organizationNames, githubResolver )); } @@ -181,4 +203,9 @@ public void shutdown() this.pluginMetaManager.getProvider().close(); this.aliasProvider.close(); } + + public String getVersion() + { + return this.plugin.getDescription().getVersion(); + } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/Alias.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/Alias.java similarity index 84% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/Alias.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/Alias.java index 5c549516..31fb7edb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/Alias.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/Alias.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.alias; +package net.kunmc.lab.teamkunpluginmanager.alias; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java similarity index 98% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java index 6d8bdfd5..eb0352f6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.alias; +package net.kunmc.lab.teamkunpluginmanager.alias; import com.zaxxer.hikari.HikariDataSource; import lombok.AccessLevel; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasSource.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java similarity index 93% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasSource.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java index a05f9f82..0d2af874 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasSource.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.alias; +package net.kunmc.lab.teamkunpluginmanager.alias; import lombok.Value; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java similarity index 97% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java index bdb7ee09..989e20cb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/alias/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.alias; +package net.kunmc.lab.teamkunpluginmanager.alias; import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index 507acdbe..7ad627ce 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +package net.kunmc.lab.teamkunpluginmanager.installer; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskChain; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskChain; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -105,7 +105,8 @@ private InstallResult

    handleTaskError(@NotNull TaskResult result) protected boolean isPluginIgnored(@NotNull String pluginName) { - return TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore").stream() + // TODO: include to abstract + return KPMDaemon.getInstance().getPlugin().getConfig().getStringList("ignore").stream() .parallel() .anyMatch(s -> s.equalsIgnoreCase(pluginName)); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java new file mode 100644 index 00000000..e15aaf44 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java @@ -0,0 +1,5 @@ +package net.kunmc.lab.teamkunpluginmanager.installer; + +public abstract class AbstractInstallerArgument +{ +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java index 4982e1b1..b5f3daef 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallFailedInstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +package net.kunmc.lab.teamkunpluginmanager.installer; import lombok.Getter; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java index e4dc3449..6997bcde 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java @@ -1,19 +1,18 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +package net.kunmc.lab.teamkunpluginmanager.installer; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.HeadSignalHandlers; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.PluginAutoRemover; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean.CleanArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean.GarbageCleaner; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.AliasUpdater; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.UpdateArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.PluginAutoRemover; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.CleanArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.GarbageCleaner; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.PluginInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.AliasUpdater; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; import org.jetbrains.annotations.NotNull; @@ -78,7 +77,7 @@ public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argu return; } - SignalHandleManager copiedHandleManager = signalHandleManager.copy(); + SignalHandleManager copiedHandleManager = signalHandleManager.copy(); // TODO: Fix in next commit HeadSignalHandlers.getInstallHandlers(terminal).forEach(copiedHandleManager::register); PluginInstaller installer; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java index 29f04581..268dc9e5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallProgress.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +package net.kunmc.lab.teamkunpluginmanager.installer; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectStatus; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.PluginModifiedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectStatus; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.apache.commons.io.FileUtils; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -29,6 +29,9 @@ @Getter public class InstallProgress, I extends AbstractInstaller> { + // TODO: include to abstract + @Getter(AccessLevel.NONE) + private static final KPMDaemon DAEMON; @Getter(AccessLevel.NONE) private static final HashMap> PROGRESS_CACHES; @Getter(AccessLevel.NONE) @@ -62,8 +65,9 @@ public class InstallProgress, I extends AbstractInstaller(); - CACHE_DIRECTORY = TeamKunPluginManager.getPlugin().getDataFolder().toPath().resolve(".cache"); + CACHE_DIRECTORY = DAEMON.getDataFolderPath(); if (!Files.exists(CACHE_DIRECTORY)) try diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java similarity index 98% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java index f240ed90..a55004c3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; +package net.kunmc.lab.teamkunpluginmanager.installer; import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java index 171644e6..dd25493d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveErrorCause.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveErrorCause.java index 1bf84bbf..75bbf124 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; /** * 自動削除のエラーを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveSucceedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveSucceedResult.java similarity index 56% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveSucceedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveSucceedResult.java index 9fc5bb93..4a423456 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveSucceedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveSucceedResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; /** * プラグインのアンインストールの結果を表すクラスです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveTasks.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveTasks.java index e67db105..2f905873 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/AutoRemoveTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; /** * 自動削除のタスクを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java similarity index 76% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java index 6200e122..cd5dcecd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/PluginAutoRemover.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java @@ -1,17 +1,17 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginUninstallFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstallSucceedResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginUninstallFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstallSucceedResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginEnumeratedSignal.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginEnumeratedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginEnumeratedSignal.java index 3e3ad9f9..ebf7cf66 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginEnumeratedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java similarity index 50% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java index 95babd12..94e4a682 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; /** * アンインストールに失敗したときに送信されるシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java index 05111e25..8bba8dbd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanErrorCause.java similarity index 58% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanErrorCause.java index 5fb5243f..f975e42e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; /** * 不要データ削除のエラーを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanTasks.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanTasks.java index cb055258..9e44dba2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/CleanTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; /** * 不要データ削除のタスクを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleanSucceedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleanSucceedResult.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleanSucceedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleanSucceedResult.java index 122b6607..6dceb7ac 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleanSucceedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleanSucceedResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleaner.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java similarity index 67% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleaner.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java index 7775bca4..c01e49c8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/clean/GarbageCleaner.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.GarbageSearchArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.GarbageSearchTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.GarbageSearchArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.GarbageSearchTask; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -36,7 +36,7 @@ public class GarbageCleaner extends AbstractInstaller execute(@NotNull CleanArgument argument) throws TaskFailedException { List excludeDataNames = argument.getExcludeDataNames(); - excludeDataNames.addAll(TeamKunPluginManager.getPlugin().getPluginConfig().getStringList("ignore")); + excludeDataNames.addAll(KPMDaemon.getInstance().getPlugin().getConfig().getStringList("ignore")); // TODO: fix on next commit List plugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() .map(Plugin::getName) .collect(Collectors.toList()); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallArgument.java similarity index 71% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallArgument.java index 2f59d92a..5f990a37 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java similarity index 50% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java index 51a793a9..b8d8f76c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; /** * インストールのエラーを表す列挙型です。 @@ -8,12 +8,12 @@ public enum InstallErrorCause // Environment errors /** * 変更しようとしているプラグインが、無視リストに登録されており、 - * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal} でも強制インストールが選択されませんでした。 + * {@link net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal} でも強制インストールが選択されませんでした。 */ PLUGIN_IGNORED, /** * インストールしようとしているプラグインが、既にインストールされており、 - * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 + * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 */ PLUGIN_ALREADY_INSTALLED, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallTasks.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallTasks.java index 9b34552c..da381f1b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/InstallTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; /** * インストールに必要なタスクをまとめた列挙型です。 @@ -18,20 +18,20 @@ public enum InstallTasks /** * プラグイン・クエリの解決中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask + * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask */ RESOLVING_QUERY, /** * プラグインのダウンロード中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask + * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask */ DOWNLOADING, /** * プラグイン情報の読み込み中であることを示します。 * * @see org.bukkit.plugin.PluginDescriptionFile - * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadTask + * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadTask */ LOADING_PLUGIN_DESCRIPTION, /** @@ -42,25 +42,25 @@ public enum InstallTasks CHECKING_ENVIRONMENT, /** * 古いプラグインの削除中であることを示します。 - * このタスクは必ずしも実行されるわけではなく、{@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal} で {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal#setReplacePlugin(boolean)} に {@code true} が設定されてた場合にのみ実行されます。 + * このタスクは必ずしも実行されるわけではなく、{@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} で {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal#setReplacePlugin(boolean)} に {@code true} が設定されてた場合にのみ実行されます。 */ REMOVING_OLD_PLUGIN, /** * 依存関係のインストール中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectTask + * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectTask */ COLLECTING_DEPENDENCIES, /** * プラグインの読み込み順序を計算中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal + * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal */ COMPUTING_LOAD_ORDER, /** * プラグインのインストール中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask + * @see net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask */ INSTALLING_PLUGINS, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java similarity index 76% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index 3a3bb39f..9e2ba345 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -1,27 +1,27 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/AlreadyInstalledPluginSignal.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/AlreadyInstalledPluginSignal.java index d95eb72a..845c50b8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/signals/AlreadyInstalledPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/AlreadyInstalledPluginSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstallSucceedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstallSucceedResult.java similarity index 57% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstallSucceedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstallSucceedResult.java index e37805fc..d1e1c7fe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstallSucceedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstallSucceedResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; /** * プラグインのアンインストールの結果を表すクラスです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java index 9f51c29f..fa17eabb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java @@ -1,21 +1,21 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.SearchingPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.UninstallReadySignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependencyNode; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.PluginIsDependencySignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.SearchingPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.UninstallReadySignal; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallTask; +import net.kunmc.lab.teamkunpluginmanager.meta.DependencyNode; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.ReversedCollector; import org.bukkit.Bukkit; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallErrorCause.java similarity index 52% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallErrorCause.java index 15ab7e69..6f844a38 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; /** * アンインストールのエラーを表す列挙型です。 @@ -11,12 +11,12 @@ public enum UnInstallErrorCause PLUGIN_NOT_FOUND, /** * 指定されたプラグインが無視リストに登録されており、 - * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal} でも強制アンインストールが選択されませんでした。 + * {@link net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal} でも強制アンインストールが選択されませんでした。 */ PLUGIN_IGNORED, /** * 指定されたプラグインが他のプラグインの依存関係に含まれており、 - * {@link net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal} でも強制アンインストールが選択されませんでした。 + * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.PluginIsDependencySignal} でも強制アンインストールが選択されませんでした。 */ PLUGIN_IS_DEPENDENCY, } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallTasks.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallTasks.java index 8982fc07..1384c29a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UnInstallTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; /** * アンインストールのタスクを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UninstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UninstallArgument.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UninstallArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UninstallArgument.java index fdaf5e1b..316960d0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/UninstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UninstallArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/PluginIsDependencySignal.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/PluginIsDependencySignal.java index e6e4db1f..ee0c86f1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/PluginIsDependencySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/PluginIsDependencySignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/SearchingPluginSignal.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/SearchingPluginSignal.java index 7e578e83..6bb9c716 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/SearchingPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/SearchingPluginSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/UninstallReadySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/UninstallReadySignal.java similarity index 81% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/UninstallReadySignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/UninstallReadySignal.java index 94e2e644..3fde6ffe 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/signals/UninstallReadySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/UninstallReadySignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.bukkit.plugin.Plugin; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java index 268fc29b..2aaaa144 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.signals.UpdateFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.SourceDownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.SourceDownloadTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.UpdateAliasesArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.UpdateAliasesResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.UpdateAliasesTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.signals.UpdateFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.SourceDownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.SourceDownloadTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.UpdateAliasesArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.UpdateAliasesResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.UpdateAliasesTask; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java similarity index 73% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java index 94a18834..6740bcee 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstallerArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; import java.util.HashMap; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateErrorCause.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateErrorCause.java index 7582329f..9e68b3bf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; /** * エイリアスのアップデートのエラーを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateTasks.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateTasks.java index d6df4da1..c1ad77a6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/UpdateTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; /** * エイリアスのアップデートのタスクを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/signals/UpdateFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/signals/UpdateFinishedSignal.java similarity index 73% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/signals/UpdateFinishedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/signals/UpdateFinishedSignal.java index 9c3bb3d9..b7efcc9e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/update/signals/UpdateFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/signals/UpdateFinishedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.impls.update.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import java.util.HashMap; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/InstallFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InstallFinishedSignal.java similarity index 54% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/InstallFinishedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InstallFinishedSignal.java index 766e55ff..29dcc052 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/InstallFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InstallFinishedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; /** * インストールが完了したことを表すシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/PluginModifiedSignal.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/PluginModifiedSignal.java index c029507d..4f1b4377 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/PluginModifiedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/PluginModifiedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/assertion/IgnoredPluginSignal.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/assertion/IgnoredPluginSignal.java index d6c25cd5..1f84cbe7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/signals/assertion/IgnoredPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/assertion/IgnoredPluginSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion; +package net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/InstallTask.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/InstallTask.java index fbaf9bf2..6886ece1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/InstallTask.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; +package net.kunmc.lab.teamkunpluginmanager.installer.task; import lombok.AllArgsConstructor; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java similarity index 57% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java index f3b3adc2..35c14391 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; +package net.kunmc.lab.teamkunpluginmanager.installer.task; /** * タスクの引数を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java similarity index 97% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java index 3226c992..0136d2f3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskChain.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; +package net.kunmc.lab.teamkunpluginmanager.installer.task; import lombok.AccessLevel; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskFailedException.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskFailedException.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java index 849f03c1..9b027f59 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskFailedException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; +package net.kunmc.lab.teamkunpluginmanager.installer.task; import lombok.Getter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskResult.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskResult.java index 63af1bea..b86a4ebb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/TaskResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task; +package net.kunmc.lab.teamkunpluginmanager.installer.task; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java similarity index 72% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java index 6caaf067..04446b97 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import java.util.HashMap; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java similarity index 71% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java index 8873b1b9..5da17781 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; /** * ソースファイルのダウンロードに失敗した理由を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadResult.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadResult.java index bce3c3ae..9c4346d7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadState.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadState.java index 1c773e23..32b1233f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; /** * ソースファイルのダウンロードの状態を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java index bc7537dd..7a14108a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/SourceDownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.SourceDownloadFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.UnsupportedProtocolSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; + +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.SourceDownloadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.UnsupportedProtocolSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java index 6dcd6526..f11f69f7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java similarity index 72% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java index 5edf9c19..3826a8af 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; /** * 不正なURLが指定された場合に送信されるシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java new file mode 100644 index 00000000..3b737da6 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; + +/** + * ソースファイルのダウンロードに失敗したことを示すシグナルです。 + */ +@Value +public class SourceDownloadFailedSignal implements Signal +{ + String remoteName; + DownloadResult downloadResult; +} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java index f2cd7652..98fdec4c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; import lombok.Getter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesArgument.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesArgument.java index 29c060ad..e8f6a8cd 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import java.net.URL; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java similarity index 72% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java index b8b2eb4c..e3b84f4c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; /** * エイリアスのアップデートに失敗した理由を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesResult.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesResult.java index 0ab147be..63eaed22 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesState.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesState.java index d45d7fad..45c92098 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; /** * エイリアスのアップデートの状態を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java index 9dbe43f2..427b6816 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/UpdateAliasesTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; import com.google.gson.JsonSyntaxException; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasUpdater; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.AliasUpdateSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.InvalidSourceSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.SourcePreparedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.alias.AliasUpdater; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.AliasUpdateSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.InvalidSourceSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.SourcePreparedSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java index 2f914c4d..34673a2b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.net.URL; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java index 52a3b925..727ec8eb 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java index 674a854a..e452b436 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourceSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourceSignal.java similarity index 76% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourceSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourceSignal.java index 104394a3..ab32ba62 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/update/signals/SourceSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourceSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java index 720ff7ac..2fafc363 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/DependencyElement.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies; import lombok.AllArgsConstructor; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectArgument.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectArgument.java index 1ad87412..70efa177 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java similarity index 71% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java index e6c398a2..e8abbae4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; /** * 依存関係の取得に失敗した理由を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectResult.java similarity index 84% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectResult.java index 6a3305ab..bbe6adc4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectState.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectState.java index 45a46167..cf7755d9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; /** * 依存関係取得の状態を表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index 637892ab..81ee3a05 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectStatus.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java index c7016466..32147b95 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -1,26 +1,26 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyDownloadFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsCollectFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsDownloadFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependsEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyDownloadFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependsCollectFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependsDownloadFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependsEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java similarity index 75% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java index b9853465..cfbcfb30 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java similarity index 74% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java index d89833fe..0968045a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; /** * 依存関係の取得に失敗したことを示すシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java index fc05751b..9913b889 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; import lombok.Getter; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java similarity index 76% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java index eaebfa87..db752016 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; /** * 依存関係のプラグイン情報ファイルの読み込みに失敗したことを示すシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java index 481edbf4..f457b3b0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; import lombok.Getter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java similarity index 73% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java index b3d890fc..cd16081f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; /** * 依存関係の解決に失敗したことを示すシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java similarity index 75% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java index 319538c5..7a4936f0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java similarity index 59% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java index 55bc2f47..ee23147e 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java similarity index 75% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java index 98c5da62..d54073e0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java index 3364a9c3..57e790ff 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java similarity index 63% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java index cb613ea7..e53d4e97 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; /** * 依存関係の読み込み順序を計算する際に発生したエラーの原因を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java similarity index 75% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java index 2c1ac002..a708b3ea 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java similarity index 84% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java index 826888a3..75acfdc0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; /** * 依存関係の読み込み順序計算の状態を表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index cd13a82b..95c36f1d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java index 635b3eea..7dc9ed7c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.Collections; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadArgument.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadArgument.java index b7390bf3..dbd2e538 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadErrorCause.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadErrorCause.java index cf070347..9585178f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; /** * プラグイン情報ファイルの読み込みに失敗した際のエラーの原因を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadResult.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadResult.java index efd4ad96..e0ff74f7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadState.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadState.java index 39840bdf..37877114 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; /** * プラグイン情報ファイルの読み込みの状態を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java index 0a0e0543..34f49a92 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java index 2bf1e700..b7973b37 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.signals; import lombok.AllArgsConstructor; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadArgument.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadArgument.java index 77eab308..8aa28071 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadErrorCause.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadErrorCause.java index 4d3ca47f..9abf1e63 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; /** * ダウンロードに失敗した際のエラーの原因を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadResult.java similarity index 90% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadResult.java index 8b2071a7..53605a29 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadState.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadState.java index c8521075..1241c8b1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; /** * ダウンロードの状態を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java index 08b0a38d..5b7f0015 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadStartingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadSucceedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; + +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadStartingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadErrorSignal.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadErrorSignal.java index 521af476..4a04a4a8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadErrorSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadErrorSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadErrorCause; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java index c61124b3..3a95a4ca 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadProgressSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSignal.java similarity index 70% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSignal.java index 4aa71809..d912d3ab 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadStartingSignal.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadStartingSignal.java index d567f05e..18d43f69 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadStartingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadStartingSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSucceedSignal.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSucceedSignal.java index c4bd54af..4f5e1bdf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/signals/DownloadSucceedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSucceedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanArgument.java similarity index 74% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanArgument.java index 367b8f8f..b1c51383 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java index 8e8c936f..6b6d9629 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; /** * 不要データ削除のエラーを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanResult.java similarity index 83% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanResult.java index a80cdffb..290fed89 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanState.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanState.java index 5bbfe9b8..12f2f7ac 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; /** * 不要データ削除の状態を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java index 346989db..3088970f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/GarbageCleanTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean; - -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageDeleteSkippedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageDeletingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.InvalidIntegritySignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; + +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageDeleteSkippedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageDeletingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.InvalidIntegritySignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java similarity index 70% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java index ee95e0d6..3bdf6f24 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java index 2aba0dfb..5a043e3c 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; import lombok.Data; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java similarity index 73% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java index b912b543..4725a1ed 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import java.nio.file.Path; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java similarity index 58% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java index e79bd780..b1cf7fe4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; /** * 整合性がとれなく、システムが保護されたことを示すシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchArgument.java similarity index 50% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchArgument.java index 75b0b4e3..459e4b92 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchArgument.java @@ -1,18 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; /** * 不要データ検索を行うタスクの引数です。 @@ -39,13 +34,4 @@ public class GarbageSearchArgument extends TaskArgument */ @NotNull List plugins; - - public GarbageSearchArgument(List excludes) - { - this(excludes, TeamKunPluginManager.getPlugin().getDataFolder().toPath().getParent(), - Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() - .map(Plugin::getName) - .collect(Collectors.toList()) - ); - } } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java similarity index 69% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java index 1d6a1591..d9d1733b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; /** * 不要データ検索のエラーを表す列挙型です。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchResult.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchResult.java index cd9132ad..af23df95 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchState.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchState.java index 49aeec61..e8fa0920 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; /** * 不要データ検索の状態を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java similarity index 82% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java index 05570276..1f8eac25 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/GarbageSearchTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java index 6c56393a..5d09ae96 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; import java.nio.file.Path; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java index a5513eee..8430ad57 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java index aa2a7962..41047614 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; /** * プラグインのインストール時に発生したエラーの原因を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallResult.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallResult.java index 1e0bcf8b..930c1649 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallState.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallState.java index e1dd6519..78fdf952 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; /** * プラグインのインストールの状態を表します。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java index c8a3c7cd..2ff5e1a4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java @@ -1,21 +1,20 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginEnablingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginInstallingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginLoadSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.InstallOperator; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginInstallingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginLoadSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.teamkunpluginmanager.loader.CommandsPatcher; +import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.entity.Player; @@ -48,7 +47,7 @@ public class PluginsInstallTask extends InstallTask gitHubName; private final GitHubURLResolver gitHubURLResolver; @Override public ResolveResult resolve(QueryContext query) { - Object obj = gitHubName; - - if (obj instanceof String) // Legacy support - { - query.setQuery("https://github.com/" + obj + "/" + query.getQuery()); - return gitHubURLResolver.resolve(query); - } - - if (!(obj instanceof List) && !(obj instanceof String[])) - throw new IllegalArgumentException("Invalid config: gitHubName: config must be a string or a list of strings"); - ResolveResult result = new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); - if ((obj instanceof List)) - return result; - - for (String str : (List) obj) + for (String str : gitHubName) { - query.setQuery("https://github.com/" + str + "/" + query.getQuery()); result = gitHubURLResolver.resolve(query); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 17c53121..6e4cd265 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java similarity index 90% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index 9fd44b6e..2c06971d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/CurseBukkitSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java similarity index 84% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java index c85ff416..49de5960 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java similarity index 93% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 0f18bcd8..26e66e7d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java similarity index 67% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java index a708aab5..4ab494ea 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/KnownPluginsResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.alias.Alias; -import net.kunmc.lab.teamkunpluginmanager.plugin.alias.AliasProvider; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.alias.Alias; +import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; +import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; public class KnownPluginsResolver implements BaseResolver diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/OmittedGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java similarity index 62% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/OmittedGitHubResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java index 0d44673a..b884553f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/OmittedGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.PipeResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.PipeResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import org.apache.commons.lang.StringUtils; public class OmittedGitHubResolver implements BaseResolver diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java similarity index 91% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index c0a584c1..c9c22cb4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java similarity index 72% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java index 736b50d7..fa3125a8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/impl/SpigotMCSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.VersionedResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.VersionedResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/BaseResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java similarity index 78% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/BaseResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java index c4b0ec8d..8bb5ef8a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/BaseResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces; +package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; /** * プラグインリゾルバのインターフェース diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/URLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java similarity index 93% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/URLResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 01c1afce..6827ca6b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/interfaces/URLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces; +package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import java.net.MalformedURLException; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ErrorResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ErrorResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index 9b5a9334..7f750a6a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ErrorResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.EqualsAndHashCode; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MarketplaceResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MarketplaceResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java index 173b6b5f..1f52af46 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MarketplaceResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.resolver.result; /** * 紹介文付きのリソースの解決結果を格納。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MultiResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java similarity index 65% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MultiResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java index 471db22c..bcad38e3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/MultiResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; /** * 解決結果が複数ある場合に返されるクラス。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/PipeResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java similarity index 60% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/PipeResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java index 81018427..8c70e55a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/PipeResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ResolveResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ResolveResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java index e741a2bd..9bc2eaa7 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/ResolveResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; /** * プラグイン解決結果のインタフェース diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/SuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/SuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java index 22f6270f..37c8d044 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/SuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.interfaces.BaseResolver; +import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/VersionedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java similarity index 79% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/VersionedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java index 0b254023..5f50f1c9 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/resolver/result/VersionedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result; +package net.kunmc.lab.teamkunpluginmanager.resolver.result; import java.util.List; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/Signal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/Signal.java similarity index 90% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/Signal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/Signal.java index f345bfc0..768b92a8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/Signal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/Signal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.signal; +package net.kunmc.lab.teamkunpluginmanager.signal; /** * インストーラやタスクなどからスローされるシグナルです。 diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java index 2046c365..a1b18b74 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.signal; +package net.kunmc.lab.teamkunpluginmanager.signal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandler.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandler.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandler.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandler.java index b7a07c86..beef22a6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandler.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.signal; +package net.kunmc.lab.teamkunpluginmanager.signal; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java index 1f9dcf56..2e8b30b1 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandlerList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.signal; +package net.kunmc.lab.teamkunpluginmanager.signal; import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java index 332fb623..e90ba136 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java @@ -1,7 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.utils; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import org.bukkit.ChatColor; public class Utils diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java similarity index 98% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 4dd6761a..3467170b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -3,7 +3,6 @@ import lombok.Getter; import lombok.Setter; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -66,7 +65,7 @@ private static Map setupDefaultHeaders(@NotNull String host) HashMap headers = new HashMap<>(); headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + - TeamKunPluginManager.getPlugin().getDescription().getVersion()); + DAEMON.getVersion()); if (host.equalsIgnoreCase("github.com") || StringUtils.endsWithIgnoreCase(host, ".github.com") || diff --git a/KPMPlugin/pom.xml b/KPMPlugin/pom.xml new file mode 100644 index 00000000..d217466c --- /dev/null +++ b/KPMPlugin/pom.xml @@ -0,0 +1,29 @@ + + + + TeamKunPluginManager + net.kunmc.lab + 3.0.0-pre5 + ../pom.xml + + 4.0.0 + + KPMPlugin + + + 8 + 8 + UTF-8 + + + + + + net.kunmc.lab + KPMDaemon + 3.0.0-pre5 + + + diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index f7a4aa34..d906db77 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -2,6 +2,7 @@ import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.command.CommandManager; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.commands.CommandAutoRemove; import net.kunmc.lab.teamkunpluginmanager.commands.CommandClean; import net.kunmc.lab.teamkunpluginmanager.commands.CommandDebug; @@ -17,6 +18,9 @@ import org.bukkit.plugin.java.JavaPlugin; import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Getter public final class TeamKunPluginManager extends JavaPlugin @@ -49,6 +53,20 @@ public void onDisable() this.daemon.shutdown(); } + private HashMap setupSources() + { + List> aliasSources = + TeamKunPluginManager.getPlugin().getPluginConfig().getMapList("config"); + + @SuppressWarnings("unchecked") + HashMap aliasMap = aliasSources.stream() + .map(map -> (Map) map) + .map(map -> new Pair<>((String) map.get("name"), (String) map.get("url"))) + .collect(HashMap::new, (map, pair) -> map.put(pair.getLeft(), pair.getRight()), HashMap::putAll); + + return aliasMap; + } + @Override public void onEnable() { @@ -67,10 +85,11 @@ public void onEnable() dataDir.resolve("plugins.db"), dataDir.resolve("token.dat"), dataDir.resolve("token_key.dat"), - dataDir.resolve("aliases.db") + dataDir.resolve("aliases.db"), + this.getPluginConfig().getStringList("githubName"), + this.setupSources() ); - this.daemon.setupDaemon(this.getDataFolder().toPath()); registerCommands(this.daemon, commandManager); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java similarity index 93% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 45cac572..9524ec51 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -5,7 +5,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index 669d1139..76f5c738 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -5,7 +5,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.clean.CleanArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.CleanArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java similarity index 97% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index b80b3c93..14c6edbf 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -5,10 +5,10 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependType; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.InstallOperator; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMeta; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kunmc.lab.teamkunpluginmanager.meta.DependType; +import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMeta; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import net.kyori.adventure.text.Component; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index 0c963ee6..da22b466 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -5,7 +5,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java index f76eb998..a606a109 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java @@ -4,14 +4,14 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.CurseBukkitSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCSuccessResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kyori.adventure.text.TextComponent; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java index 9e9a8473..c47ba2b4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java @@ -4,7 +4,6 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.utils.Messages; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -24,7 +23,8 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { terminal.writeLine("===現在の状態==="); - terminal.writeLine(Messages.keyValue("プラグイン数", Bukkit.getPluginManager().getPlugins().length)); + terminal.writeLine(ChatColor.GREEN + "プラグイン数" + ChatColor.WHITE + ": " + + Bukkit.getPluginManager().getPlugins().length); List autoRemovable = this.daemon.getPluginMetaManager().getProvider().getUnusedPlugins(); if (!autoRemovable.isEmpty()) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index b6420e16..bec8b385 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -5,7 +5,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java similarity index 63% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index f44d6390..785847b5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -3,19 +3,15 @@ import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.UpdateArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.List; -import java.util.Map; @AllArgsConstructor public class CommandUpdate extends CommandBase @@ -25,19 +21,9 @@ public class CommandUpdate extends CommandBase @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { - // TODO: Migrate to new config system - List> aliasSources = - TeamKunPluginManager.getPlugin().getPluginConfig().getMapList("config"); - - @SuppressWarnings("unchecked") - HashMap aliasMap = aliasSources.stream() - .map(map -> (Map) map) - .map(map -> new Pair<>((String) map.get("name"), (String) map.get("url"))) - .collect(HashMap::new, (map, pair) -> map.put(pair.getLeft(), pair.getRight()), HashMap::putAll); - Runner.runAsync(() -> this.daemon.getInstallManager().runUpdate(terminal, new UpdateArgument( - aliasMap + this.daemon.getSources() )) ); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java similarity index 95% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java index 067cdfcf..468640e4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java @@ -5,7 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandMarkAsDependency; import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandPurge; import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandRelation; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaManager; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java index 0d6fc924..c33b9002 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java @@ -5,12 +5,12 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallArgument; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallTasks; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.PluginInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallTasks; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.PluginInstaller; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java index 05f13b04..eb8b12f5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java @@ -5,12 +5,12 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.PluginUninstaller; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallTasks; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java similarity index 93% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index c3edfc35..08318b9d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -4,13 +4,13 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Question; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java similarity index 97% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java index 03fcb988..9f918f24 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java @@ -3,7 +3,7 @@ import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java similarity index 96% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java index f04dc2a6..df472a0f 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java @@ -3,7 +3,7 @@ import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java similarity index 94% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java index 18c9f8a2..01e224d6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java @@ -4,10 +4,10 @@ import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependType; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.DependencyNode; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMeta; -import net.kunmc.lab.teamkunpluginmanager.plugin.meta.PluginMetaProvider; +import net.kunmc.lab.teamkunpluginmanager.meta.DependType; +import net.kunmc.lab.teamkunpluginmanager.meta.DependencyNode; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMeta; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java similarity index 100% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java index 4e8f1eeb..e06a2c64 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java @@ -2,9 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.AutoRemoveErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveErrorCause; public class AutoRemoveFinishedSignalHandler extends InstallFinishedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java index 465a9da5..1116b678 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java @@ -2,8 +2,8 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.autoremove.signals.PluginEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java similarity index 86% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java index 4d8a2517..44d60451 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java @@ -2,9 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.GarbageCleanErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanErrorCause; public class GarbageCleanFinishedSignalHandler extends InstallFinishedSignalBase { diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java index cbe09e09..20aa77af 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java @@ -2,9 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.bukkit.ChatColor; import java.util.stream.Collectors; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java similarity index 89% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java index 41cc1fa4..8f399173 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java @@ -2,9 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java index 81fc4a72..0be12502 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java @@ -2,10 +2,10 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadSucceedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java similarity index 85% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java index cc01aa5a..ef317c1d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java @@ -3,10 +3,10 @@ import lombok.AccessLevel; import lombok.Setter; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java index 70924dfe..ea84c7b8 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java @@ -1,8 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.PluginModifiedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.PluginModifiedSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java similarity index 71% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java index 43487fae..6cf4e5f6 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java @@ -1,12 +1,12 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.bukkit.ChatColor; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java index ccb5cceb..03619bc0 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -2,14 +2,14 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.InstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.collector.DependsCollectErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.DescriptionLoadErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.PluginsInstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveErrorCause; import org.jetbrains.annotations.Nullable; /** diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java similarity index 76% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java index ab8ef997..827f90d4 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java @@ -1,11 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginEnablingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginInstallingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginLoadSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginInstallingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginLoadSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java similarity index 87% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java index 42df1022..98f6102b 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java @@ -4,11 +4,11 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolvingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolvingSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.bukkit.ChatColor; import java.util.AbstractMap; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java similarity index 92% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java index b6266c76..aaeb82a2 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java @@ -3,8 +3,8 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.PluginIsDependencySignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java similarity index 80% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java index 8192d67f..cb8dd227 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -2,9 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallErrorCause; import org.jetbrains.annotations.Nullable; /** @@ -23,7 +23,7 @@ protected void onSuccess(InstallResult result) this.terminal.success("アンインストールが正常に完了しました。"); } - private boolean handleGeneralErrors(@Nullable net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause cause) + private boolean handleGeneralErrors(@Nullable net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause cause) { if (cause == null) return false; @@ -47,8 +47,8 @@ private boolean handleGeneralErrors(@Nullable net.kunmc.lab.teamkunpluginmanager @Override protected void onFail(InstallFailedInstallResult result) { - if (result.getReason() instanceof net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause && - this.handleGeneralErrors((net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.UnInstallErrorCause) result.getReason())) + if (result.getReason() instanceof net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause && + this.handleGeneralErrors((net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause) result.getReason())) return; if (result.getReason() instanceof UnInstallErrorCause) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java similarity index 88% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java index 0c3f45e9..fca04c0a 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -2,8 +2,8 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.UninstallReadySignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.UninstallReadySignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java index fd66c483..ee4dd1b5 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java @@ -1,12 +1,12 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginDisablingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java similarity index 77% rename from src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java index 1d9d08d8..849a5e72 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java @@ -1,11 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.update; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.update.signals.UpdateFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.update.signals.InvalidSourceSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.signals.UpdateFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.InvalidSourceSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; public class UpdateAliasesSignalHandler { diff --git a/src/main/resources/config.v2.yml b/KPMPlugin/src/main/resources/config.v2.yml similarity index 100% rename from src/main/resources/config.v2.yml rename to KPMPlugin/src/main/resources/config.v2.yml diff --git a/src/main/resources/config.yml b/KPMPlugin/src/main/resources/config.yml similarity index 100% rename from src/main/resources/config.yml rename to KPMPlugin/src/main/resources/config.yml diff --git a/src/main/resources/plugin.yml b/KPMPlugin/src/main/resources/plugin.yml similarity index 100% rename from src/main/resources/plugin.yml rename to KPMPlugin/src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml index ffff7ce3..beb77b20 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,11 @@ net.kunmc.lab TeamKunPluginManager 3.0.0-pre5 - jar + + KPMDaemon + KPMPlugin + + pom TeamKunPluginManager diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java deleted file mode 100644 index a1351374..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/AbstractInstallerArgument.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; - -public abstract class AbstractInstallerArgument -{ -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java deleted file mode 100644 index afe18fe7..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.alias.source.download.signals; - -import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; - -/** - * ソースファイルのダウンロードに失敗したことを示すシグナルです。 - */ -@Value -public class SourceDownloadFailedSignal implements Signal -{ - String remoteName; - DownloadResult downloadResult; -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java deleted file mode 100644 index a7faa294..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/signals/StartingGCSignal.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals; - -import net.kunmc.lab.teamkunpluginmanager.plugin.signal.Signal; - -/** - * VMのGCを実行することを通知するシグナルです。 - */ -public class StartingGCSignal implements Signal -{ -} diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java deleted file mode 100644 index f6b0427c..00000000 --- a/src/test/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolverTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver; - -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.GitHubURLResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.OmittedGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.impl.SpigotMCResolver; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; -import org.junit.Ignore; -import org.junit.Test; - -public class PluginResolverTest -{ - public static void printResult(ResolveResult result, boolean first) - { - if (result instanceof SuccessResult) - { - SuccessResult successResult = (SuccessResult) result; - System.out.println(successResult.getFileName() + ":" + successResult.getDownloadUrl() + " @" + successResult.getVersion()); - - if (result instanceof GitHubSuccessResult) - { - GitHubSuccessResult gitHubSuccessResult = (GitHubSuccessResult) result; - System.out.println("GitHub: " + gitHubSuccessResult.getOwner() + "/" + gitHubSuccessResult.getRepoName()); - System.out.println("GitHub: " + gitHubSuccessResult.getTitle() + ": " + gitHubSuccessResult.getReleaseName()); - System.out.println("GitHub: " + gitHubSuccessResult.getUrl()); - } - } - else if (result instanceof ErrorResult) - { - ErrorResult errorResult = (ErrorResult) result; - System.out.println(errorResult.getCause()); - System.out.println(errorResult.getCause().getMessage()); - System.out.println(errorResult.getSource()); - } - else if (result instanceof MultiResult) - { - MultiResult multiResult = (MultiResult) result; - for (ResolveResult resolveResult : multiResult.getResults()) - printResult(resolveResult, false); - } - } - - @Ignore - @Test - public void resolveTest() - { - - PluginResolver resolver = new PluginResolver(); - resolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); - resolver.addResolver(new GitHubURLResolver(), "github", "gh"); - resolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); - // resolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); - - // resolver.addResolver(new KnownPluginsResolver(), "local", "alias"); - - - ResolveResult result; - // result = resolver.resolve("https://www.spigotmc.org/resources/coreprotect.8631/"); - // printResult(result, true); - - // result = resolver.resolve("spigot>https://github.com/TeamKUN/TeamKUNPluginManager==v1.0"); - //result = resolver.resolve("TeamKUN/TeamKUNPluginManager==v1.0"); - result = resolver.resolve("bukkit>coreprotect==v1.0"); - - printResult(result, true); - } -} diff --git a/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java b/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java deleted file mode 100644 index 6c71184b..00000000 --- a/src/test/java/net/kunmc/lab/teamkunpluginmanager/result/http/RequestsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.result.http; - -import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class RequestsTest -{ - private static final String mockUrl = "https://run.mocky.io/v3/63f730d5-cb39-413e-a56f-37450aea4df0"; - private static final String redirMockURl = "https://run.mocky.io/v3/3df2a3b9-c9fd-4b44-a69c-2c408d9f93fa"; - - @Test - public void testGetNoRedir() - { - HTTPResponse response = Requests.request(RequestContext.builder() - .url(mockUrl) - .build()); - - Assert.assertEquals(200, response.getStatusCode()); - Assert.assertEquals(response.getHeader("Content-Type"), "application/json; charset=UTF-8"); - - JsonObject json = response.getAsJson().getAsJsonObject(); - - Assert.assertEquals(json.get("hello").getAsString(), "world"); - } - - @Test - public void testGetRedir() - { - HTTPResponse response = Requests.request(RequestContext.builder() - .url(redirMockURl) - .followRedirects(true) - .build()); - - Assert.assertEquals(200, response.getStatusCode()); - Assert.assertEquals(response.getHeader("Content-Type"), "application/json; charset=UTF-8"); - - JsonObject json = response.getAsJson().getAsJsonObject(); - - Assert.assertEquals(json.get("hello").getAsString(), "world"); - } - - @Test - public void testGetRedirButNoRedir() - { - HTTPResponse response = Requests.request(RequestContext.builder() - .url(redirMockURl) - .followRedirects(false) - .build()); - - Assert.assertEquals(301, response.getStatusCode()); - Assert.assertEquals(response.getHeader("Location"), mockUrl); - } - - @Test - public void testGetCache() - { - HTTPResponse response = Requests.request(RequestContext.builder() - .url(mockUrl) - .build()); - - String first = response.getAsString(); - String second = response.getAsString(); - - Assert.assertEquals(first, second); - } -} From b996b1e4407f68c3a2555f8b1879edac983e05c6 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 10 Oct 2022 23:08:32 +0900 Subject: [PATCH 357/745] feat: KPMEnvironment --- .../lab/teamkunpluginmanager/KPMDaemon.java | 49 +++------- .../teamkunpluginmanager/KPMEnvironment.java | 94 +++++++++++++++++++ .../installer/AbstractInstaller.java | 3 +- .../installer/InstallProgress.java | 2 +- .../installer/impls/clean/GarbageCleaner.java | 4 +- .../impls/update/UpdateArgument.java | 2 +- .../tasks/install/PluginsInstallTask.java | 2 +- .../TeamKunPluginManager.java | 18 ++-- 8 files changed, 122 insertions(+), 52 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 17b0adc2..696789af 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -17,7 +17,6 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -38,20 +37,16 @@ public class KPMDaemon @NotNull private static KPMDaemon INSTANCE; - @NotNull - private final Plugin plugin; - /** - * ログを出力するためのロガーです。 + * KPMの環境です。 */ @NotNull - private final Logger logger; - + private final KPMEnvironment envs; /** - * データフォルダのパスです。 + * KPMのロガーです。 */ @NotNull - private final Path dataFolderPath; + private final Logger logger; /** * プラグインのメタデータを管理するクラスです。 @@ -78,11 +73,6 @@ public class KPMDaemon */ @NotNull private final AliasProvider aliasProvider; - /** - * エイリアスのソースです。 - */ - @NotNull - private final HashMap sources; /** * プラグインをロード/アンロードするためのクラスです。 @@ -94,29 +84,18 @@ public class KPMDaemon INSTANCE = this; } - public KPMDaemon( - @NotNull Plugin plugin, - @NotNull Logger logger, - @NotNull Path dataFolderPath, - @NotNull Path databasePath, - @NotNull Path tokenPath, - @NotNull Path tokenKeyPath, - @NotNull Path aliasPath, - @NotNull List organizationNames, - @NotNull HashMap sources) + public KPMDaemon(@NotNull KPMEnvironment env) { - this.plugin = plugin; - this.logger = logger; - this.dataFolderPath = dataFolderPath; - this.pluginMetaManager = new PluginMetaManager(plugin, databasePath); - this.tokenStore = new TokenStore(tokenPath, tokenKeyPath); + this.envs = env; + this.logger = env.getLogger(); + this.pluginMetaManager = new PluginMetaManager(env.getPlugin(), env.getMetadataDBPath()); + this.tokenStore = new TokenStore(env.getTokenPath(), env.getTokenKeyPath()); this.pluginResolver = new PluginResolver(); - this.aliasProvider = new AliasProvider(aliasPath); + this.aliasProvider = new AliasProvider(env.getAliasesDBPath()); this.pluginLoader = new PluginLoader(this); this.installManager = new InstallManager(this); - this.sources = sources; - this.setupDaemon(dataFolderPath, organizationNames); + this.setupDaemon(env.getDataDirPath(), env.getOrganizations()); } /** @@ -142,14 +121,14 @@ private void firstUpdate() Runner.runAsync(() -> { this.getInstallManager().runUpdate( Terminals.ofConsole(), - new UpdateArgument(this.sources) + new UpdateArgument((HashMap) this.envs.getSources()) ); }); } private void setupDependencyTree(Path dataFolder) { - logger.info("Loading plugin meta data ..."); + this.logger.info("Loading plugin meta data ..."); this.pluginMetaManager.crawlAll(); Path aliasFile = dataFolder.resolve("aliases.db"); @@ -206,6 +185,6 @@ public void shutdown() public String getVersion() { - return this.plugin.getDescription().getVersion(); + return this.getEnvs().getPlugin().getDescription().getVersion(); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java new file mode 100644 index 00000000..af1615f5 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java @@ -0,0 +1,94 @@ +package net.kunmc.lab.teamkunpluginmanager; + +import lombok.Builder; +import lombok.Getter; +import lombok.Singular; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; + +import java.nio.file.Path; +import java.util.List; +import java.util.Map; + +@Builder +@Getter +public class KPMEnvironment +{ + /** + * KPMのプラグインです。 + */ + @NotNull + private final Plugin plugin; + + /** + * プラグインのデータディレクトリのパスです。 + */ + @NotNull + private final Path dataDirPath; + + /** + * KPMデーモンが使用するロガーです。 + */ + @NotNull + private final Logger logger; + + /** + * トークンの格納先のパスです。 + */ + @NotNull + private final Path tokenPath; + + /** + * トークンの鍵の格納先のパスです。 + */ + @NotNull + private final Path tokenKeyPath; + + /** + * プラグインメタデータデータベースのパスです。 + */ + @NotNull + private final Path metadataDBPath; + + /** + * エイリアスデータベースのパスです。 + */ + @NotNull + private final Path aliasesDBPath; + + /** + * プラグイン解決に使用するGitHubの組織名です。 + */ + @NotNull + @Singular("organization") + private final List organizations; + + /** + * 様々な操作から除外するプラグインの名前です。 + * 通常は、削除やアップデートを行わないようにするために使用します。 + */ + @NotNull + @Singular("excludePlugin") + private final List excludes; + + /** + * エイリアスのソースです。 + */ + @NotNull + @Singular("sources") + private final Map sources; + + public static KPMEnvironmentBuilder builder(@NotNull Plugin plugin, @NotNull Logger logger, @NotNull Path dataDirPath) + { + return new KPMEnvironmentBuilder() + .plugin(plugin) + .logger(logger) + .dataDirPath(dataDirPath); + } + + public static KPMEnvironmentBuilder builder(@NotNull Plugin plugin) + { + return builder(plugin, plugin.getSLF4JLogger(), plugin.getDataFolder().toPath()); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index 7ad627ce..79a9112a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -105,8 +105,7 @@ private InstallResult

    handleTaskError(@NotNull TaskResult result) protected boolean isPluginIgnored(@NotNull String pluginName) { - // TODO: include to abstract - return KPMDaemon.getInstance().getPlugin().getConfig().getStringList("ignore").stream() + return KPMDaemon.getInstance().getEnvs().getExcludes().stream() .parallel() .anyMatch(s -> s.equalsIgnoreCase(pluginName)); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java index 268dc9e5..6214a632 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java @@ -67,7 +67,7 @@ public class InstallProgress, I extends AbstractInstaller(); - CACHE_DIRECTORY = DAEMON.getDataFolderPath(); + CACHE_DIRECTORY = DAEMON.getEnvs().getDataDirPath().resolve(".caches"); if (!Files.exists(CACHE_DIRECTORY)) try diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java index c01e49c8..823e3bdf 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java @@ -36,7 +36,7 @@ public class GarbageCleaner extends AbstractInstaller execute(@NotNull CleanArgument argument) throws TaskFailedException { List excludeDataNames = argument.getExcludeDataNames(); - excludeDataNames.addAll(KPMDaemon.getInstance().getPlugin().getConfig().getStringList("ignore")); // TODO: fix on next commit + excludeDataNames.addAll(KPMDaemon.getInstance().getEnvs().getExcludes()); List plugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).parallel() .map(Plugin::getName) .collect(Collectors.toList()); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java index 6740bcee..38d632ca 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java @@ -18,5 +18,5 @@ public class UpdateArgument extends AbstractInstallerArgument /** * エイリアスのソースのURLです。 */ - HashMap remotes; + HashMap remotes; // TODO: Migrate to Map remotes; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java index 2ff5e1a4..11935ef8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java @@ -47,7 +47,7 @@ public class PluginsInstallTask extends InstallTask Date: Tue, 11 Oct 2022 00:09:20 +0900 Subject: [PATCH 358/745] feat: HeadInstallers --- .../lab/teamkunpluginmanager/KPMDaemon.java | 24 +-- .../installer/InstallManager.java | 203 +++--------------- .../exceptions/InstallerRunningException.java | 22 ++ .../TokenNotAvailableException.java | 22 ++ .../teamkunpluginmanager/HeadInstallers.java | 175 +++++++++++++++ .../TeamKunPluginManager.java | 28 +-- .../commands/CommandAutoRemove.java | 6 +- .../commands/CommandClean.java | 6 +- .../commands/CommandInstall.java | 7 +- .../commands/CommandUninstall.java | 6 +- .../commands/CommandUpdate.java | 7 +- .../signal/HeadSignalHandlers.java | 34 +-- .../signal/SignalHandlingUtils.java | 2 +- .../AutoRemoveFinishedSignalHandler.java | 4 +- .../AutoRemoveReadySignalHandler.java | 4 +- .../GarbageCleanFinishedSignalHandler.java | 4 +- .../clean/GarbageCleanSignalHandler.java | 4 +- .../common/CheckEnvSignalHandler.java | 4 +- .../common/DownloadingSignalHandler.java | 2 +- .../common/InstallFinishedSignalBase.java | 2 +- .../handlers/common/ModifySignalHandler.java | 2 +- .../intall/DependenciesSignalHandler.java | 2 +- .../intall/InstallFinishedSignalHandler.java | 4 +- .../intall/InstallerSignalHandler.java | 2 +- .../intall/ResolverSignalHandler.java | 2 +- .../PluginIsDependencySignalHandler.java | 2 +- .../UninstallFinishedSignalHandler.java | 4 +- .../UninstallReadySignalHandler.java | 4 +- .../uninstall/UninstallerSignalHandler.java | 2 +- .../update/UpdateAliasesSignalHandler.java | 2 +- 30 files changed, 323 insertions(+), 269 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/InstallerRunningException.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/TokenNotAvailableException.java create mode 100644 KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/HeadSignalHandlers.java (66%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/SignalHandlingUtils.java (92%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java (90%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java (90%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java (91%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/clean/GarbageCleanSignalHandler.java (90%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/common/CheckEnvSignalHandler.java (93%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/common/DownloadingSignalHandler.java (97%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/common/InstallFinishedSignalBase.java (96%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/common/ModifySignalHandler.java (94%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/intall/DependenciesSignalHandler.java (97%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/intall/InstallFinishedSignalHandler.java (97%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/intall/InstallerSignalHandler.java (96%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/intall/ResolverSignalHandler.java (98%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/uninstall/PluginIsDependencySignalHandler.java (96%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/uninstall/UninstallFinishedSignalHandler.java (92%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/uninstall/UninstallReadySignalHandler.java (89%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/uninstall/UninstallerSignalHandler.java (97%) rename KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/{commands => }/signal/handlers/update/UpdateAliasesSignalHandler.java (96%) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 696789af..6f092dd9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -2,11 +2,8 @@ import lombok.AccessLevel; import lombok.Getter; -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminals; -import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; import net.kunmc.lab.teamkunpluginmanager.installer.InstallManager; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; import net.kunmc.lab.teamkunpluginmanager.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; @@ -21,9 +18,7 @@ import org.slf4j.Logger; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.util.HashMap; import java.util.List; /** @@ -111,30 +106,15 @@ public static KPMDaemon getInstance() public void setupDaemon(@NotNull Path dataFolder, @NotNull List organizationNames) { - this.setupDependencyTree(dataFolder); + this.setupDependencyTree(); this.setupPluginResolvers(organizationNames); this.setupToken(); } - private void firstUpdate() - { - Runner.runAsync(() -> { - this.getInstallManager().runUpdate( - Terminals.ofConsole(), - new UpdateArgument((HashMap) this.envs.getSources()) - ); - }); - } - - private void setupDependencyTree(Path dataFolder) + private void setupDependencyTree() { this.logger.info("Loading plugin meta data ..."); this.pluginMetaManager.crawlAll(); - - Path aliasFile = dataFolder.resolve("aliases.db"); - boolean isFirstTime = !Files.exists(aliasFile); - if (isFirstTime && this.tokenStore.isTokenAvailable()) - this.firstUpdate(); } private void setupPluginResolvers(List organizationNames) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java index 6997bcde..2fb72a7e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java @@ -1,23 +1,12 @@ package net.kunmc.lab.teamkunpluginmanager.installer; -import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.PluginAutoRemover; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.CleanArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.GarbageCleaner; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.PluginInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.AliasUpdater; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.InstallerRunningException; +import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.TokenNotAvailableException; import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; import org.jetbrains.annotations.NotNull; -import java.io.IOException; - /** * プラグインのインストールを管理するクラスです。 */ @@ -25,7 +14,6 @@ public class InstallManager { private final KPMDaemon daemon; private final TokenStore tokenStore; - private final SignalHandleManager signalHandleManager; private InstallProgress runningInstall; @@ -33,7 +21,6 @@ public InstallManager(@NotNull KPMDaemon daemon) { this.daemon = daemon; this.tokenStore = daemon.getTokenStore(); - this.signalHandleManager = new SignalHandleManager(); this.runningInstall = null; } @@ -45,12 +32,12 @@ public InstallManager(@NotNull KPMDaemon daemon) */ public boolean isRunning() { - if (runningInstall == null) + if (this.runningInstall == null) return false; - if (runningInstall.isFinished()) + if (this.runningInstall.isFinished()) { - runningInstall = null; + this.runningInstall = null; return false; } @@ -58,172 +45,32 @@ public boolean isRunning() } /** - * インストールを実行します。 + * インストーラを実行します。 * - * @param terminal ターミナル - * @param argument インストールの引数 + * @param installer インストーラ + * @param arguments インストーラに渡す引数 + * @param インストーラの引数の型 + * @param インストールのタスクの型 + * @param インストーラの型 + * @return インストールの結果 */ - public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argument) + @SuppressWarnings("unchecked") + public , I extends AbstractInstaller> InstallProgress runInstallerAsync( + @NotNull I installer, + @NotNull A arguments + ) { if (isRunning()) - { - terminal.error("他のインストーラが起動しています。"); - return; - } + throw new InstallerRunningException("Install is already running."); if (!this.tokenStore.isTokenAvailable()) - { - terminal.error("GitHub にログインされていません。"); - terminal.info("/kpm register でログインしてください。"); - return; - } - - SignalHandleManager copiedHandleManager = signalHandleManager.copy(); // TODO: Fix in next commit - HeadSignalHandlers.getInstallHandlers(terminal).forEach(copiedHandleManager::register); - - PluginInstaller installer; - try - { - installer = new PluginInstaller(this.daemon, copiedHandleManager); - runningInstall = installer.getProgress(); - - installer.run(argument); - } - catch (IOException e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました。"); - - runningInstall = null; - } - } - - /** - * アンインストールを実行します。 - * - * @param terminal ターミナル - * @param argument アンインストールするプラグインのクエリ - * @throws IllegalStateException インストールが進行中の場合 - * @throws IOException 予期しない例外が発生した場合 - */ - public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument argument) throws IllegalStateException - { - if (isRunning()) - { - terminal.error("他のインストーラが起動しています。"); - return; - } - - SignalHandleManager copiedHandleManager = signalHandleManager.copy(); - HeadSignalHandlers.getUninstallHandlers(terminal).forEach(copiedHandleManager::register); - - try - { - PluginUninstaller uninstaller = new PluginUninstaller(this.daemon, copiedHandleManager); - runningInstall = uninstaller.getProgress(); - - uninstaller.run(argument); - } - catch (Exception e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました。"); - - runningInstall = null; - } - } - - public void runUpdate(@NotNull Terminal terminal, @NotNull UpdateArgument argument) - { - if (isRunning()) - { - terminal.error("他のインストーラが起動しています。"); - return; - } - - SignalHandleManager copiedHandleManager = signalHandleManager.copy(); - HeadSignalHandlers.getUpdateHandlers(terminal).forEach(copiedHandleManager::register); - - try - { - AliasUpdater updater = new AliasUpdater(this.daemon, copiedHandleManager); - runningInstall = updater.getProgress(); - - updater.run(argument); - } - catch (Exception e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました。"); - - runningInstall = null; - } - } - - /** - * プラグインの自動削除を実行します。 - * - * @param terminal ターミナル - * @param argument 自動削除の引数 - */ - public void runAutoRemove(@NotNull Terminal terminal, @NotNull AutoRemoveArgument argument) - { - if (isRunning()) - { - terminal.error("他のインストーラが起動しています。"); - return; - } - - SignalHandleManager copiedHandleManager = signalHandleManager.copy(); - HeadSignalHandlers.getAutoRemoveHandlers(terminal).forEach(copiedHandleManager::register); - - try - { - PluginAutoRemover remover = new PluginAutoRemover(this.daemon, copiedHandleManager); - runningInstall = remover.getProgress(); - - remover.run(argument); + throw new TokenNotAvailableException("Token is not available."); - } - catch (Exception e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました。"); + this.runningInstall = installer.getProgress(); - runningInstall = null; - } - } + Runner.runAsync(() -> { + installer.run(arguments); + }); - /** - * 不要データ(ガベージ)の削除を実行します。 - * - * @param terminal ターミナル - * @param argument 不要データ削除の引数 - * @throws IllegalStateException インストールが進行中の場合 - */ - public void runGarbageClean(@NotNull Terminal terminal, @NotNull CleanArgument argument) throws IllegalStateException - { - if (isRunning()) - { - terminal.error("他のインストーラが起動しています。"); - return; - } - - SignalHandleManager copiedHandleManager = signalHandleManager.copy(); - HeadSignalHandlers.getGarbageCleanHandlers(terminal).forEach(copiedHandleManager::register); - - try - { - GarbageCleaner collector = new GarbageCleaner(copiedHandleManager); - runningInstall = collector.getProgress(); - - collector.run(argument); - } - catch (Exception e) - { - e.printStackTrace(); - terminal.error("不明なエラーが発生しました。"); - - runningInstall = null; - } + return (InstallProgress) installer.getProgress(); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/InstallerRunningException.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/InstallerRunningException.java new file mode 100644 index 00000000..c26fc88d --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/InstallerRunningException.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.exceptions; + +/** + * インストーラが既に実行中であることを表す例外です。 + */ +public class InstallerRunningException extends IllegalStateException +{ + public InstallerRunningException(String s) + { + super(s); + } + + public InstallerRunningException(String message, Throwable cause) + { + super(message, cause); + } + + public InstallerRunningException(Throwable cause) + { + super(cause); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/TokenNotAvailableException.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/TokenNotAvailableException.java new file mode 100644 index 00000000..bb2a91f9 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/TokenNotAvailableException.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.exceptions; + +/** + * トークンが設定されていないことを表す例外です。 + */ +public class TokenNotAvailableException extends IllegalStateException +{ + public TokenNotAvailableException(String s) + { + super(s); + } + + public TokenNotAvailableException(String message, Throwable cause) + { + super(message, cause); + } + + public TokenNotAvailableException(Throwable cause) + { + super(cause); + } +} diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java new file mode 100644 index 00000000..7e2357e1 --- /dev/null +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java @@ -0,0 +1,175 @@ +package net.kunmc.lab.teamkunpluginmanager; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.InstallerRunningException; +import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.TokenNotAvailableException; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.PluginAutoRemover; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.CleanArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.GarbageCleaner; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.PluginInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.AliasUpdater; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; +import net.kunmc.lab.teamkunpluginmanager.signal.HeadSignalHandlers; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; + +@AllArgsConstructor +public class HeadInstallers +{ + private final KPMDaemon daemon; + + private , I extends AbstractInstaller> void headRun( + @NotNull Terminal terminal, + @NotNull I installer, + @NotNull A arguments + ) + { + try + { + this.daemon.getInstallManager().runInstallerAsync(installer, arguments); + } + catch (InstallerRunningException e) + { + terminal.error("他のインストールが実行中です。"); + } + catch (TokenNotAvailableException e) + { + terminal.error("トークンが設定されていません!"); + terminal.info("/kpm register でトークンを設定してください。"); + } + } + + /** + * インストールを実行します。 + * + * @param terminal ターミナル + * @param argument インストールの引数 + */ + public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argument) + { + SignalHandleManager handleManager = new SignalHandleManager(); + HeadSignalHandlers.getInstallHandlers(terminal).forEach(handleManager::register); + + PluginInstaller installer; + try + { + installer = new PluginInstaller(this.daemon, handleManager); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("インストーラの初期化に失敗しました:" + e.getMessage()); + return; + } + + this.headRun(terminal, installer, argument); + } + + /** + * アンインストールを実行します。 + * + * @param terminal ターミナル + * @param argument アンインストールするプラグインのクエリ + */ + public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument argument) + { + SignalHandleManager handleManager = new SignalHandleManager(); + HeadSignalHandlers.getUninstallHandlers(terminal).forEach(handleManager::register); + + PluginUninstaller uninstaller; + try + { + uninstaller = new PluginUninstaller(this.daemon, handleManager); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("インストーラの初期化に失敗しました:" + e.getMessage()); + return; + } + + this.headRun(terminal, uninstaller, argument); + } + + public void runUpdate(@NotNull Terminal terminal, @NotNull UpdateArgument argument) + { + SignalHandleManager handleManager = new SignalHandleManager(); + HeadSignalHandlers.getUpdateHandlers(terminal).forEach(handleManager::register); + + AliasUpdater updater; + try + { + updater = new AliasUpdater(this.daemon, handleManager); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("インストーラの初期化に失敗しました:" + e.getMessage()); + return; + } + + this.headRun(terminal, updater, argument); + } + + /** + * プラグインの自動削除を実行します。 + * + * @param terminal ターミナル + * @param argument 自動削除の引数 + */ + public void runAutoRemove(@NotNull Terminal terminal, @NotNull AutoRemoveArgument argument) + { + SignalHandleManager handleManager = new SignalHandleManager(); + HeadSignalHandlers.getAutoRemoveHandlers(terminal).forEach(handleManager::register); + + PluginAutoRemover autoRemover; + try + { + autoRemover = new PluginAutoRemover(this.daemon, handleManager); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("インストーラの初期化に失敗しました:" + e.getMessage()); + return; + } + + this.headRun(terminal, autoRemover, argument); + } + + /** + * 不要データ(ガベージ)の削除を実行します。 + * + * @param terminal ターミナル + * @param argument 不要データ削除の引数 + * @throws IllegalStateException インストールが進行中の場合 + */ + public void runGarbageClean(@NotNull Terminal terminal, @NotNull CleanArgument argument) throws IllegalStateException + { + SignalHandleManager handleManager = new SignalHandleManager(); + HeadSignalHandlers.getGarbageCleanHandlers(terminal).forEach(handleManager::register); + + GarbageCleaner garbageCleaner; + try + { + garbageCleaner = new GarbageCleaner(handleManager); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("インストーラの初期化に失敗しました:" + e.getMessage()); + return; + } + + this.headRun(terminal, garbageCleaner, argument); + } +} diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 7399e6f1..5f57c7d8 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -32,18 +32,20 @@ public final class TeamKunPluginManager extends JavaPlugin private KPMDaemon daemon; - public static void registerCommands(KPMDaemon daemon, CommandManager commandManager) + private HeadInstallers headInstallers; + + public void registerCommands(CommandManager commandManager) { - commandManager.registerCommand("autoremove", new CommandAutoRemove(daemon)); - commandManager.registerCommand("clean", new CommandClean(daemon)); - commandManager.registerCommand("info", new CommandInfo(daemon)); - commandManager.registerCommand("install", new CommandInstall(daemon), "add", "i"); - commandManager.registerCommand("register", new CommandRegister(daemon), "login"); - commandManager.registerCommand("reload", new CommandReload(daemon)); - commandManager.registerCommand("resolve", new CommandResolve(daemon)); - commandManager.registerCommand("status", new CommandStatus(daemon)); - commandManager.registerCommand("uninstall", new CommandUninstall(daemon), "remove", "rm"); - commandManager.registerCommand("update", new CommandUpdate(daemon)); + commandManager.registerCommand("autoremove", new CommandAutoRemove(this)); + commandManager.registerCommand("clean", new CommandClean(this)); + commandManager.registerCommand("info", new CommandInfo(this.daemon)); + commandManager.registerCommand("install", new CommandInstall(this), "add", "i"); + commandManager.registerCommand("register", new CommandRegister(this.daemon), "login"); + commandManager.registerCommand("reload", new CommandReload(this.daemon)); + commandManager.registerCommand("resolve", new CommandResolve(this.daemon)); + commandManager.registerCommand("status", new CommandStatus(this.daemon)); + commandManager.registerCommand("uninstall", new CommandUninstall(this), "remove", "rm"); + commandManager.registerCommand("update", new CommandUpdate(this, this.daemon)); commandManager.registerCommand("debug", new CommandDebug()); } @@ -89,7 +91,9 @@ public void onEnable() .build() ); - registerCommands(this.daemon, commandManager); + this.headInstallers = new HeadInstallers(this.daemon); + + registerCommands(commandManager); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java index 9524ec51..fae0f972 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java @@ -4,7 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -16,13 +16,13 @@ @AllArgsConstructor public class CommandAutoRemove extends CommandBase { - private final KPMDaemon daemon; + private final TeamKunPluginManager plugin; @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { Runner.runAsync(() -> - this.daemon.getInstallManager().runAutoRemove(terminal, new AutoRemoveArgument()) + this.plugin.getHeadInstallers().runAutoRemove(terminal, new AutoRemoveArgument()) ); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java index 76f5c738..6e2064df 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java @@ -4,7 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.CleanArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -16,13 +16,13 @@ @AllArgsConstructor public class CommandClean extends CommandBase { - private final KPMDaemon daemon; + private final TeamKunPluginManager plugin; @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { Runner.runAsync(() -> - this.daemon.getInstallManager().runGarbageClean(terminal, new CleanArgument()) + this.plugin.getHeadInstallers().runGarbageClean(terminal, new CleanArgument()) ); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java index da22b466..fe8f0709 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java @@ -4,7 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; @@ -16,7 +16,8 @@ @AllArgsConstructor public class CommandInstall extends CommandBase { - private final KPMDaemon daemon; + + private final TeamKunPluginManager plugin; @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) @@ -27,7 +28,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String query = args[0]; Runner.runAsync(() -> - this.daemon.getInstallManager().runInstall(terminal, new InstallArgument(query)) + this.plugin.getHeadInstallers().runInstall(terminal, new InstallArgument(query)) ); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java index bec8b385..3cc5ce36 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java @@ -4,7 +4,7 @@ import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; @@ -20,7 +20,7 @@ @AllArgsConstructor public class CommandUninstall extends CommandBase { - private final KPMDaemon daemon; + private final TeamKunPluginManager plugin; @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) @@ -31,7 +31,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String query = args[0]; Runner.runAsync(() -> - daemon.getInstallManager().runUninstall(terminal, new UninstallArgument(query)) + this.plugin.getHeadInstallers().runUninstall(terminal, new UninstallArgument(query)) ); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index 785847b5..a0a75ecc 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -5,25 +5,28 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.List; @AllArgsConstructor public class CommandUpdate extends CommandBase { + private final TeamKunPluginManager plugin; private final KPMDaemon daemon; @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { Runner.runAsync(() -> - this.daemon.getInstallManager().runUpdate(terminal, new UpdateArgument( - this.daemon.getSources() + this.plugin.getHeadInstallers().runUpdate(terminal, new UpdateArgument( + (HashMap) this.daemon.getEnvs().getSources() )) ); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java similarity index 66% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java index cdfc38ac..9c131855 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java @@ -1,22 +1,22 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal; +package net.kunmc.lab.teamkunpluginmanager.signal; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove.AutoRemoveFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove.AutoRemoveReadySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean.GarbageCleanFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean.GarbageCleanSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.CheckEnvSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.DownloadingSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.ModifySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.DependenciesSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall.ResolverSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.PluginIsDependencySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallReadySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall.UninstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.update.UpdateAliasesSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove.AutoRemoveFinishedSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove.AutoRemoveReadySignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean.GarbageCleanFinishedSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean.GarbageCleanSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.CheckEnvSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.DownloadingSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.ModifySignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.DependenciesSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.InstallFinishedSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.ResolverSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.PluginIsDependencySignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallFinishedSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallReadySignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.update.UpdateAliasesSignalHandler; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlingUtils.java similarity index 92% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlingUtils.java index ff78818b..b73905b2 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/SignalHandlingUtils.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlingUtils.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal; +package net.kunmc.lab.teamkunpluginmanager.signal; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java similarity index 90% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java index e06a2c64..1f5d331c 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveErrorCause; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; public class AutoRemoveFinishedSignalHandler extends InstallFinishedSignalBase { diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java similarity index 90% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java index 1116b678..3d5eb9bf 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.autoremove; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java similarity index 91% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java index 44d60451..05cb6b76 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanErrorCause; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; public class GarbageCleanFinishedSignalHandler extends InstallFinishedSignalBase { diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java similarity index 90% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java index 20aa77af..ada3c2af 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/clean/GarbageCleanSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.clean; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import org.bukkit.ChatColor; import java.util.stream.Collectors; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java similarity index 93% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java index 8f399173..a461e1a4 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java similarity index 97% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java index 0be12502..e88b4cf6 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/DownloadingSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java similarity index 96% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java index ef317c1d..13b4c8a9 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/InstallFinishedSignalBase.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; import lombok.AccessLevel; import lombok.Setter; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java similarity index 94% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java index ea84c7b8..79673193 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/common/ModifySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.signals.PluginModifiedSignal; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java similarity index 97% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java index 6cf4e5f6..cd95fdc3 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/DependenciesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java similarity index 97% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java index 03619bc0..9b8fc5b1 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -1,7 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallErrorCause; @@ -10,6 +9,7 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadErrorCause; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallErrorCause; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveErrorCause; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; import org.jetbrains.annotations.Nullable; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java similarity index 96% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java index 827f90d4..adf3aeb0 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/InstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java similarity index 98% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java index 98f6102b..ac419efd 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/intall/ResolverSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.intall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java similarity index 96% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java index aaeb82a2..f31a72e8 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/PluginIsDependencySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallFinishedSignalHandler.java similarity index 92% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallFinishedSignalHandler.java index cb8dd227..8a7b7fb5 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallErrorCause; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; import org.jetbrains.annotations.Nullable; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java similarity index 89% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java index fca04c0a..7230f2b6 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.commands.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.UninstallReadySignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java similarity index 97% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java index ee4dd1b5..bfb64318 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/uninstall/UninstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.uninstall; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginDisablingSignal; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java similarity index 96% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java index 849a5e72..4842311d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/signal/handlers/update/UpdateAliasesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.signal.handlers.update; +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.update; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.signals.UpdateFinishedSignal; From 55666cbee3971175479abfb2ce9503c7e80567ff Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 00:13:03 +0900 Subject: [PATCH 359/745] refactor: HashMap to Map --- .../installer/impls/update/AliasUpdater.java | 4 ++-- .../installer/impls/update/UpdateArgument.java | 4 ++-- .../tasks/alias/source/download/SourceDownloadArgument.java | 4 ++-- .../task/tasks/alias/source/download/SourceDownloadTask.java | 3 ++- .../lab/teamkunpluginmanager/commands/CommandUpdate.java | 3 +-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java index 2aaaa144..0c3b14af 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java @@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull; import java.io.IOException; -import java.util.HashMap; +import java.util.Map; /** * プラグインをエイリアスのアップデートするインストーラーの実装です。 @@ -38,7 +38,7 @@ public AliasUpdater(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager sign @Override public InstallResult execute(@NotNull UpdateArgument argument) throws TaskFailedException { - HashMap remotes = argument.getRemotes(); + Map remotes = argument.getRemotes(); UpdateAliasesResult result = (UpdateAliasesResult) this.submitter( diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java index 38d632ca..ea838ccf 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java @@ -5,7 +5,7 @@ import lombok.EqualsAndHashCode; import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; -import java.util.HashMap; +import java.util.Map; /** * エイリアスのアップデートの引数を格納するクラスです。 @@ -18,5 +18,5 @@ public class UpdateArgument extends AbstractInstallerArgument /** * エイリアスのソースのURLです。 */ - HashMap remotes; // TODO: Migrate to Map remotes; + Map remotes; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java index 04446b97..16f136dc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java @@ -4,7 +4,7 @@ import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; -import java.util.HashMap; +import java.util.Map; /** * ソースファイルのダウンロードを行うタスクの引数です。 @@ -17,5 +17,5 @@ public class SourceDownloadArgument extends TaskArgument * エイリアスのソースのURLです。 * キーはリモートの名前、値はHTTP(S)サーバのURLです。 */ - HashMap remotes; + Map remotes; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java index 7a14108a..b9fa5439 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java @@ -16,6 +16,7 @@ import java.net.URL; import java.nio.file.Path; import java.util.HashMap; +import java.util.Map; /** * ソースファイルのダウンロードを行うタスクです。 @@ -53,7 +54,7 @@ private static boolean isProtocolSupported(String protocolName) return new SourceDownloadResult(true, this.status, downloadSources); } - private HashMap buildURLs(HashMap sources) + private HashMap buildURLs(Map sources) { HashMap result = new HashMap<>(); diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java index a0a75ecc..88ce62c8 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java @@ -12,7 +12,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.List; @AllArgsConstructor @@ -26,7 +25,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { Runner.runAsync(() -> this.plugin.getHeadInstallers().runUpdate(terminal, new UpdateArgument( - (HashMap) this.daemon.getEnvs().getSources() + this.daemon.getEnvs().getSources() )) ); } From 7d550be679d4fd98cb14887b2f68154e28803d8f Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 00:15:15 +0900 Subject: [PATCH 360/745] refactor: Remove Unused class: HashLib --- .../teamkunpluginmanager/utils/HashLib.java | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java deleted file mode 100644 index febd02d9..00000000 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/HashLib.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.security.DigestInputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class HashLib -{ - public static String genSha1(File file, int length) - { - String digest; - if ((digest = genSha1(file)).length() <= length) - return digest; - return digest.substring(0, length); - } - - public static String genSha1(File file) - { - if (!file.exists()) - return ""; - - - try (DigestInputStream di = - new DigestInputStream( - new BufferedInputStream(new FileInputStream(file)), - MessageDigest.getInstance("SHA-1") - )) - { - int count = 0; - while (di.read() != -1 && count++ < Integer.MAX_VALUE) ; - - char[] HEX_ARRAY = "0123456789abcdef".toCharArray(); - byte[] bytes = di.getMessageDigest().digest(); - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) - { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = HEX_ARRAY[v >>> 4]; - hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F]; - } - - return new String(hexChars); - } - catch (IOException | NoSuchAlgorithmException e) - { - e.printStackTrace(); - return ""; - } - } -} From b1876c65d09c4f4875bbbf4e16f98c6c9cffe704 Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 00:16:15 +0900 Subject: [PATCH 361/745] refactor: Transactions to db --- .../kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java | 4 ++-- .../kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java | 2 +- .../lab/teamkunpluginmanager/meta/PluginMetaProvider.java | 2 +- .../lab/teamkunpluginmanager/utils/{ => db}/ResultRow.java | 2 +- .../lab/teamkunpluginmanager/utils/{ => db}/Transaction.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/{ => db}/ResultRow.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/{ => db}/Transaction.java (99%) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java index eb0352f6..b9242df9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java @@ -3,8 +3,8 @@ import com.zaxxer.hikari.HikariDataSource; import lombok.AccessLevel; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.utils.ResultRow; -import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; +import net.kunmc.lab.teamkunpluginmanager.utils.db.ResultRow; +import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java index 989e20cb..1a2b7389 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java @@ -1,7 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.alias; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; +import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; public class AliasUpdater { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java index aa3c49a1..c0bde58e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java @@ -2,7 +2,7 @@ import com.zaxxer.hikari.HikariDataSource; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.utils.Transaction; +import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java index 1c4918fb..056d6ede 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ResultRow.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.teamkunpluginmanager.utils.db; import lombok.AllArgsConstructor; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java index dd964019..5cdcecfc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Transaction.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.teamkunpluginmanager.utils.db; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; From 646885a7ad6eca71f85cfe8ae5c4593891812c36 Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 00:20:52 +0900 Subject: [PATCH 362/745] feat: oblige daemon to AbstractInstaller --- .../teamkunpluginmanager/installer/AbstractInstaller.java | 7 +++++-- .../installer/impls/autoremove/PluginAutoRemover.java | 5 +---- .../installer/impls/clean/GarbageCleaner.java | 4 ++-- .../installer/impls/install/PluginInstaller.java | 5 +---- .../installer/impls/uninstall/PluginUninstaller.java | 5 +---- .../installer/impls/update/AliasUpdater.java | 5 +---- .../net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java | 2 +- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index 79a9112a..d912c087 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -18,14 +18,17 @@ public abstract class AbstractInstaller, P extends Enum

    > { + protected final KPMDaemon daemon; @Getter protected final InstallProgress> progress; protected final SignalHandleManager signalHandler; - public AbstractInstaller(SignalHandleManager signalHandler) throws IOException + public AbstractInstaller(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { - this.progress = InstallProgress.of(this, signalHandler, null); + this.daemon = daemon; this.signalHandler = signalHandler; + + this.progress = InstallProgress.of(this, signalHandler, null); } protected void postSignal(@NotNull Signal signal) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java index cd5dcecd..04c9b256 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java @@ -30,12 +30,9 @@ */ public class PluginAutoRemover extends AbstractInstaller { - private final KPMDaemon daemon; - public PluginAutoRemover(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { - super(signalHandler); - this.daemon = daemon; + super(daemon, signalHandler); } @Override diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java index 823e3bdf..b9d1f489 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java @@ -39,9 +39,9 @@ public class GarbageCleaner extends AbstractInstaller { - private final KPMDaemon daemon; - public PluginInstaller(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { - super(signalHandler); - this.daemon = daemon; + super(daemon, signalHandler); } @Override diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java index fa17eabb..fb1318c6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java @@ -43,12 +43,9 @@ */ public class PluginUninstaller extends AbstractInstaller { - private final KPMDaemon daemon; - public PluginUninstaller(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { - super(signalHandler); - this.daemon = daemon; + super(daemon, signalHandler); } @Override diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java index 0c3b14af..df287aa5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java @@ -27,12 +27,9 @@ */ public class AliasUpdater extends AbstractInstaller { - private final KPMDaemon daemon; - public AliasUpdater(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException { - super(signalHandler); - this.daemon = daemon; + super(daemon, signalHandler); } @Override diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java index 7e2357e1..fadff8ae 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java @@ -161,7 +161,7 @@ public void runGarbageClean(@NotNull Terminal terminal, @NotNull CleanArgument a GarbageCleaner garbageCleaner; try { - garbageCleaner = new GarbageCleaner(handleManager); + garbageCleaner = new GarbageCleaner(this.daemon, handleManager); } catch (IOException e) { From 159d221095f95a76027cdb026f2518322ced489d Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 00:21:32 +0900 Subject: [PATCH 363/745] refactor: Suppress unchecked of AbstractInstaller#handleTaskError --- .../lab/teamkunpluginmanager/installer/AbstractInstaller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index d912c087..2258a649 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -89,7 +89,7 @@ public , S extends Enum> InstallFailedInstallResult handleTaskError(@NotNull TaskResult result) { if (result.getErrorCause() != null) From a7a511a7b24a071141839aaae6393c6c85e6087e Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 17:21:16 +0900 Subject: [PATCH 364/745] refactor: Separate resolver and common --- KPMCommon/pom.xml | 21 ++++++++++++++ .../common}/TokenStore.java | 2 +- .../common}/http/DownloadProgress.java | 2 +- .../common}/http/HTTPResponse.java | 2 +- .../common}/http/RequestContext.java | 2 +- .../common}/http/RequestMethod.java | 2 +- .../common}/http/Requests.java | 20 ++++++------- KPMDaemon/pom.xml | 12 ++++++++ .../lab/teamkunpluginmanager/KPMDaemon.java | 14 ++++++++-- .../AliasPluginResolver.java} | 8 ++---- .../installer/InstallManager.java | 2 +- .../task/tasks/download/DownloadTask.java | 6 ++-- .../commands/CommandRegister.java | 8 +++--- KPMResolver/pom.xml | 28 +++++++++++++++++++ .../resolver/PluginResolver.java | 0 .../resolver/QueryContext.java | 0 .../impl/BruteforceGitHubResolver.java | 0 .../resolver/impl/CurseBukkitResolver.java | 6 ++-- .../impl/CurseBukkitSuccessResult.java | 6 ++-- .../resolver/impl/GitHubSuccessResult.java | 0 .../resolver/impl/GitHubURLResolver.java | 6 ++-- .../resolver/impl/OmittedGitHubResolver.java | 0 .../resolver/impl/SpigotMCResolver.java | 6 ++-- .../resolver/impl/SpigotMCSuccessResult.java | 0 .../resolver/interfaces/BaseResolver.java | 0 .../resolver/interfaces/URLResolver.java | 2 +- .../resolver/result/ErrorResult.java | 0 .../resolver/result/MarketplaceResult.java | 0 .../resolver/result/MultiResult.java | 0 .../resolver/result/PipeResult.java | 0 .../resolver/result/ResolveResult.java | 0 .../resolver/result/SuccessResult.java | 0 .../resolver/result/VersionedResult.java | 0 pom.xml | 2 ++ 34 files changed, 112 insertions(+), 45 deletions(-) create mode 100644 KPMCommon/pom.xml rename {KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils => KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common}/TokenStore.java (99%) rename {KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils => KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common}/http/DownloadProgress.java (69%) rename {KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils => KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common}/http/HTTPResponse.java (98%) rename {KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils => KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common}/http/RequestContext.java (89%) rename {KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils => KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common}/http/RequestMethod.java (65%) rename {KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils => KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common}/http/Requests.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/{resolver/impl/KnownPluginsResolver.java => alias/AliasPluginResolver.java} (86%) create mode 100644 KPMResolver/pom.xml rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java (96%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java (91%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java (97%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java (96%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java (98%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java (100%) rename {KPMDaemon => KPMResolver}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java (100%) diff --git a/KPMCommon/pom.xml b/KPMCommon/pom.xml new file mode 100644 index 00000000..333593e8 --- /dev/null +++ b/KPMCommon/pom.xml @@ -0,0 +1,21 @@ + + + + TeamKunPluginManager + net.kunmc.lab + 3.0.0-pre5 + ../pom.xml + + 4.0.0 + + KPMCommon + + + 8 + 8 + UTF-8 + + + diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java rename to KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java index dc232e8d..9de0db6d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/TokenStore.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.teamkunpluginmanager.common; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java similarity index 69% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java rename to KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java index 033ef0c1..a7910144 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.teamkunpluginmanager.common.http; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java rename to KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java index e8c770e2..b8b037d8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.teamkunpluginmanager.common.http; import com.google.gson.Gson; import com.google.gson.JsonElement; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java similarity index 89% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java rename to KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java index 1db67c6e..7d1c3991 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.teamkunpluginmanager.common.http; import lombok.Builder; import lombok.Singular; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java similarity index 65% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java rename to KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java index 96d70756..c99a1154 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.teamkunpluginmanager.common.http; public enum RequestMethod { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java rename to KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java index 3467170b..d22200a1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.teamkunpluginmanager.common.http; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.common.TokenStore; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,12 +22,10 @@ public class Requests { - private static final KPMDaemon DAEMON; - - static - { - DAEMON = KPMDaemon.getInstance(); - } + @Setter + private static TokenStore tokenStore; + @Setter + private static String version; @Getter @Setter @@ -65,7 +63,7 @@ private static Map setupDefaultHeaders(@NotNull String host) HashMap headers = new HashMap<>(); headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + - DAEMON.getVersion()); + version); if (host.equalsIgnoreCase("github.com") || StringUtils.endsWithIgnoreCase(host, ".github.com") || @@ -73,10 +71,10 @@ private static Map setupDefaultHeaders(@NotNull String host) { headers.put("Accept", "application/vnd.github.v3+json"); - if (DAEMON.getTokenStore().isTokenAvailable()) + if (tokenStore.isTokenAvailable()) headers.put( "Authorization", - "Token " + DAEMON.getTokenStore().getToken() + "Token " + tokenStore.getToken() ); } diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index 433890ed..d7942f7f 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -18,4 +18,16 @@ UTF-8 + + + net.kunmc.lab + KPMResolver + 3.0.0-pre5 + + + net.kunmc.lab + KPMCommon + 3.0.0-pre5 + + diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 6f092dd9..f77bec4c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -2,7 +2,10 @@ import lombok.AccessLevel; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.alias.AliasPluginResolver; import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; +import net.kunmc.lab.teamkunpluginmanager.common.TokenStore; +import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.installer.InstallManager; import net.kunmc.lab.teamkunpluginmanager.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; @@ -10,10 +13,8 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.impl.BruteforceGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.KnownPluginsResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; -import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -109,6 +110,7 @@ public void setupDaemon(@NotNull Path dataFolder, @NotNull List organiza this.setupDependencyTree(); this.setupPluginResolvers(organizationNames); this.setupToken(); + this.initializeRequests(); } private void setupDependencyTree() @@ -122,7 +124,7 @@ private void setupPluginResolvers(List organizationNames) GitHubURLResolver githubResolver = new GitHubURLResolver(); this.pluginResolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); this.pluginResolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); - this.pluginResolver.addResolver(new KnownPluginsResolver(this), "local", "alias"); + this.pluginResolver.addResolver(new AliasPluginResolver(this), "local", "alias"); this.pluginResolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); this.pluginResolver.addResolver(githubResolver, "github", "gh"); @@ -157,6 +159,12 @@ private void setupToken() this.tokenStore.fromEnv(); } + private void initializeRequests() + { + Requests.setVersion(getVersion()); + Requests.setTokenStore(this.tokenStore); + } + public void shutdown() { this.pluginMetaManager.getProvider().close(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java index 4ab494ea..d91112bc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/KnownPluginsResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java @@ -1,8 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.teamkunpluginmanager.alias; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.alias.Alias; -import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; @@ -12,12 +10,12 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; -public class KnownPluginsResolver implements BaseResolver +public class AliasPluginResolver implements BaseResolver { private final PluginResolver resolver; private final AliasProvider aliasProvider; - public KnownPluginsResolver(@NotNull KPMDaemon daemon) + public AliasPluginResolver(@NotNull KPMDaemon daemon) { this.resolver = daemon.getPluginResolver(); this.aliasProvider = daemon.getAliasProvider(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java index 2fb72a7e..979de851 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java @@ -2,9 +2,9 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.common.TokenStore; import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.InstallerRunningException; import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.TokenNotAvailableException; -import net.kunmc.lab.teamkunpluginmanager.utils.TokenStore; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java index 5b7f0015..667fa826 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java @@ -1,5 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; +import net.kunmc.lab.teamkunpluginmanager.common.http.DownloadProgress; +import net.kunmc.lab.teamkunpluginmanager.common.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; @@ -7,9 +10,6 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadStartingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; -import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 7f101e52..010e0170 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -9,10 +9,10 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.common.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kyori.adventure.text.TextComponent; import org.bukkit.ChatColor; import org.bukkit.command.BlockCommandSender; diff --git a/KPMResolver/pom.xml b/KPMResolver/pom.xml new file mode 100644 index 00000000..8cb8b0ea --- /dev/null +++ b/KPMResolver/pom.xml @@ -0,0 +1,28 @@ + + + + TeamKunPluginManager + net.kunmc.lab + 3.0.0-pre5 + ../pom.xml + + 4.0.0 + + KPMResolver + + + 8 + 8 + UTF-8 + + + + + net.kunmc.lab + KPMCommon + 3.0.0-pre5 + + + diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java similarity index 96% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 6e4cd265..8d766e52 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -3,14 +3,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index 2c06971d..07ea353a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -1,11 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; +import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java similarity index 97% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 26e66e7d..325bc676 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -3,15 +3,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java similarity index 96% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index c9c22cb4..31aca8c4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -2,14 +2,14 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 6827ca6b..781b785d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -1,9 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import java.net.MalformedURLException; import java.net.URL; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java similarity index 100% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java rename to KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java diff --git a/pom.xml b/pom.xml index beb77b20..9e2da390 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,8 @@ KPMDaemon KPMPlugin + KPMResolver + KPMCommon pom From 2f5215060b9be6ca092a5436fd66635e195d06cb Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 17:41:31 +0900 Subject: [PATCH 365/745] refactor: Change pom sceop and namex --- KPMDaemon/pom.xml | 17 +++++++-- KPMPlugin/pom.xml | 67 +++++++++++++++++++++++++++++++++- KPMResolver/pom.xml | 1 + pom.xml | 88 --------------------------------------------- 4 files changed, 82 insertions(+), 91 deletions(-) diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index d7942f7f..0bdbf962 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -22,12 +22,25 @@ net.kunmc.lab KPMResolver - 3.0.0-pre5 + ${project.version} net.kunmc.lab KPMCommon - 3.0.0-pre5 + ${project.version} + compile + + + commons-io + commons-io + 2.11.0 + compile + + + com.zaxxer + HikariCP + 4.0.3 + compile diff --git a/KPMPlugin/pom.xml b/KPMPlugin/pom.xml index d217466c..c8bcc1db 100644 --- a/KPMPlugin/pom.xml +++ b/KPMPlugin/pom.xml @@ -18,12 +18,77 @@ UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + ${java.version} + ${java.version} + ${parent.artifactId}-${project.version}.jar + + + + org.apache.maven.plugins + maven-shade-plugin + 3.3.0 + + + package + + shade + + + false + + + + + true + + + org.slf4j:* + + + + + *:* + + META-INF/MANIFEST.MF + + + + com.github.TeamKUN:PeyangPaperUtils + + plugin.yml + + + + commons-io + + META-INF/*.txt + + + + + + + + + src/main/resources + true + + + net.kunmc.lab KPMDaemon - 3.0.0-pre5 + ${project.version} + compile diff --git a/KPMResolver/pom.xml b/KPMResolver/pom.xml index 8cb8b0ea..50d5cbda 100644 --- a/KPMResolver/pom.xml +++ b/KPMResolver/pom.xml @@ -23,6 +23,7 @@ net.kunmc.lab KPMCommon 3.0.0-pre5 + provided diff --git a/pom.xml b/pom.xml index 9e2da390..501cad10 100644 --- a/pom.xml +++ b/pom.xml @@ -24,76 +24,6 @@ https://kunmc.net/ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.3.0 - - - package - - shade - - - false - - - - - true - - - org.slf4j:* - - - - - *:* - - META-INF/MANIFEST.MF - - - - com.github.TeamKUN:PeyangPaperUtils - - plugin.yml - - - - commons-io - - META-INF/*.txt - - - - com.github.G00fY2:version-compare - - META-INF/proguard/* - - - - - - - - - src/main/resources - true - - - - papermc-repo @@ -120,24 +50,6 @@ 1.16.5-R0.1-SNAPSHOT provided - - commons-io - commons-io - 2.11.0 - compile - - - com.github.G00fY2 - version-compare - 1.3.7 - compile - - - com.zaxxer - HikariCP - 4.0.3 - compile - org.spigotmc spigot From 73c8888f61c6972b495e7ebf3d0cbb214efd2a98 Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 11 Oct 2022 17:45:19 +0900 Subject: [PATCH 366/745] fix: Fix finalName --- KPMPlugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMPlugin/pom.xml b/KPMPlugin/pom.xml index c8bcc1db..b39954f6 100644 --- a/KPMPlugin/pom.xml +++ b/KPMPlugin/pom.xml @@ -19,6 +19,7 @@ + ${project.parent.artifactId}-${project.version} org.apache.maven.plugins @@ -27,7 +28,6 @@ ${java.version} ${java.version} - ${parent.artifactId}-${project.version}.jar From a7491229145625e6ddbbc928a4816af67c4abf8c Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 12 Oct 2022 20:32:23 +0900 Subject: [PATCH 367/745] docs: Javadoc fulfilled --- .../common/TokenStore.java | 33 +++++ .../common/http/DownloadProgress.java | 12 ++ .../common/http/HTTPResponse.java | 122 +++++++++++++++++- .../common/http/RequestContext.java | 25 ++++ .../common/http/RequestMethod.java | 24 ++++ .../common/http/Requests.java | 33 +++-- .../lab/teamkunpluginmanager/KPMDaemon.java | 2 +- .../teamkunpluginmanager/KPMEnvironment.java | 3 + .../alias/AliasPluginResolver.java | 3 + .../alias/AliasProvider.java | 38 +++++- .../alias/AliasSource.java | 3 + .../alias/AliasUpdater.java | 15 +++ .../installer/AbstractInstaller.java | 80 ++++++++++++ .../installer/AbstractInstallerArgument.java | 3 + .../installer/InstallFailedInstallResult.java | 6 + .../installer/InstallManager.java | 2 +- .../installer/task/TaskArgument.java | 2 +- .../installer/task/TaskFailedException.java | 3 + .../loader/PluginLoadResult.java | 2 +- .../utils/PluginUtil.java | 2 +- .../resolver/PluginResolver.java | 16 ++- .../resolver/QueryContext.java | 13 +- .../impl/CurseBukkitSuccessResult.java | 4 +- .../resolver/impl/GitHubSuccessResult.java | 5 + .../resolver/interfaces/BaseResolver.java | 4 +- .../resolver/interfaces/URLResolver.java | 13 +- .../resolver/result/ErrorResult.java | 30 +++-- .../resolver/result/MarketplaceResult.java | 16 ++- .../resolver/result/MultiResult.java | 6 +- .../resolver/result/PipeResult.java | 7 +- .../resolver/result/ResolveResult.java | 6 +- .../resolver/result/SuccessResult.java | 12 +- .../resolver/result/VersionedResult.java | 5 +- 33 files changed, 483 insertions(+), 67 deletions(-) diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java index 9de0db6d..9aec45dc 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java @@ -18,6 +18,9 @@ import java.security.spec.KeySpec; import java.util.Base64; +/** + * トークンを安全に保存するためのクラスです。 + */ public class TokenStore { private static final String ALGORITHM = "AES"; @@ -140,6 +143,11 @@ private byte[] getkey(Path keyPath) throws IOException } } + /** + * トークンを保存します。 + * + * @param token トークン + */ public void storeToken(String token) throws IOException { byte[] tokenBytes = encryptToken(token); @@ -158,6 +166,12 @@ public void storeToken(String token) throws IOException this.tokenCache = token; } + /** + * トークンをファイルから読み込みます。 + * + * @return トークンの読み取りに成功したかどうか + * @throws IOException トークンの読み取りに失敗した場合(ファイルが存在しない場合は{@code false}を返します) + */ public boolean loadToken() throws IOException { if (!Files.exists(tokenPath)) @@ -175,6 +189,12 @@ public boolean loadToken() throws IOException return true; } + /** + * トークンを KPMv2 の形式から移行します。 + * + * @return 移行に成功したかどうか + * @throws IOException 移行に失敗した場合 + */ public boolean migrateToken() throws IOException { File oldToken = new File(new File("").getAbsoluteFile(), "kpm.vault"); @@ -191,11 +211,21 @@ public boolean migrateToken() throws IOException return true; } + /** + * トークンが利用可能かどうかを返します。 + * + * @return トークンが利用可能かどうか + */ public boolean isTokenAvailable() { return this.tokenCache != null; } + /** + * トークンを取得します。また、ロードされていない場合はロードします。 + * + * @return トークン + */ public String getToken() { if (this.tokenCache == null) @@ -213,6 +243,9 @@ public String getToken() return this.tokenCache; } + /** + * トークンを環境変数 {@code TOKEN} から取得します。 + */ public void fromEnv() { String token = System.getenv("TOKEN"); diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java index a7910144..63f51494 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java @@ -2,11 +2,23 @@ import lombok.Value; +/** + * ダウンロードの進捗を表すクラスです。 + */ @Value public class DownloadProgress { + /** + * ファイルのサイズです。 + */ long totalSize; + /** + * ダウンロード済みのサイズです。 + */ long downloaded; + /** + * ダウンロード済みのサイズをパーセントで表した値です。 + */ double percentage; } diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java index b8b037d8..f1884fbf 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java @@ -12,25 +12,66 @@ import java.io.InputStream; import java.util.HashMap; +/** + * HTTP レスポンスを表すクラスです。 + */ @Data public class HTTPResponse implements AutoCloseable { + /** + * リクエストのステータスです。 + */ private final RequestStatus status; + /** + * リクエストのコンテキストです。 + */ private final RequestContext request; + /** + * サーバのプロトコルです。 + */ private final String serverProtocol; + /** + * プロトコルのバージョンです。 + */ private final String protocolVersion; + /** + * HTTP ステータスコードです。 + */ private final int statusCode; + /** + * HTTP ヘッダーです。 + */ private final HashMap headers; + /** + * レスポンスボディを表すストリームです。 + */ @Nullable private final InputStream inputStream; @Getter(AccessLevel.PRIVATE) private String bodyCache = null; + /** + * エラーのレスポンスを生成します。 + * + * @param request リクエスト + * @param status ステータス + * @return エラーのレスポンス + */ + public static HTTPResponse error(@NotNull RequestContext request, @NotNull RequestStatus status) + { + return new HTTPResponse(status, request, null, null, -1, null, null); + } + + /** + * レスポンスボディを文字列として取得します。 + * + * @return レスポンスボディ + */ public String getAsString() { if (inputStream == null) @@ -56,6 +97,11 @@ else if (bodyCache != null) return bodyCache; } + /** + * レスポンスボディを JSON として取得します。 + * + * @return レスポンスボディ + */ public JsonElement getAsJson() { if (inputStream == null) @@ -65,6 +111,11 @@ public JsonElement getAsJson() return new Gson().fromJson(json, JsonElement.class); } + /** + * このクラスを破棄します。 + * + * @throws IOException I/O エラーが発生した場合 + */ @Override public void close() throws IOException { @@ -72,57 +123,118 @@ public void close() throws IOException this.inputStream.close(); } + /** + * ヘッダーを取得します。 + * ヘッダー名は大文字小文字を区別しません。 + * + * @param header ヘッダー名 + * @return ヘッダーの値 + */ @Nullable public String getHeader(@NotNull String header) { return headers.getOrDefault(header.toLowerCase(), headers.get(header)); } + /** + * リクエストに成功したかどうかを取得します。 + * + * @return リクエストに成功したかどうか + */ public boolean isSuccessful() { return statusCode >= 200 && statusCode < 300; } + /** + * リダイレクトのレスポンスかどうかを取得します。 + * + * @return リダイレクトのレスポンスかどうか + */ public boolean isRedirect() { return statusCode >= 300 && statusCode < 400; } + /** + * クライアントエラーのレスポンスかどうかを取得します。 + * + * @return クライアントエラーのレスポンスかどうか + */ public boolean isClientError() { return statusCode >= 400 && statusCode < 500; } + /** + * サーバエラーのレスポンスかどうかを取得します。 + * + * @return サーバエラーのレスポンスかどうか + */ public boolean isServerError() { return statusCode >= 500 && statusCode < 600; } + /** + * エラーのレスポンスかどうかを取得します。 + * + * @return エラーのレスポンスかどうか + * @see #isClientError() + * @see #isServerError() + */ public boolean isError() { return isClientError() || isServerError(); } + /** + * OK のレスポンスかどうかを取得します。 + * + * @return OK のレスポンスかどうか + */ public boolean isOK() { return statusCode == 200; } - public static HTTPResponse error(@NotNull RequestContext request, @NotNull RequestStatus status) - { - return new HTTPResponse(status, request, null, null, -1, null, null); - } - + /** + * リクエストのステータスを表す列挙型です。 + */ public enum RequestStatus { + /** + * リクエストが成功しました。 + */ OK, + /** + * サーバでエラーが発生しました。 + */ SERVER_ERROR, + /** + * クライアントの問題でエラーが発生しました。 + */ CLIENT_ERROR, + /** + * リダイレクト先に指定された URL が無効でした。 + */ REDIRECT_LOCATION_MALFORMED, + /** + * リダイレクト上限に達しました。 + */ REDIRECT_LIMIT_EXCEED, + /** + * ホストが見つかりませんでした。 + */ UNABLE_TO_RESOLVE_HOST, + /** + * I/O エラーが発生しました。 + */ IO_EXCEPTION_OCCURRED, + /** + * URL が無効でした。 + */ URL_MALFORMED } } diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java index 7d1c3991..fcc156b7 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java @@ -6,25 +6,50 @@ import java.util.Map; +/** + * リクエストのコンテキストを表すクラスです。 + */ @Value @Builder public class RequestContext { + /** + * URLです。 + */ String url; + /** + * リクエストのメソッドです。 + * デフォルトはGETです。 + */ @Builder.Default RequestMethod method = RequestMethod.GET; + /** + * 追加のリクエスト・ヘッダーです。 + */ @Singular("header") Map extraHeaders; + /** + * レスポンスがキャッシュ可能かどうかを表すフラグです。 + */ @Builder.Default boolean cacheable = false; + /** + * リダイレクトに従うかどうかを表すフラグです。 + */ @Builder.Default boolean followRedirects = true; + /** + * タイムアウト時間です。 + */ @Builder.Default int timeout = -1; + /** + * リクエストボディです。 + */ @Builder.Default byte[] body = null; diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java index c99a1154..9d08440e 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java @@ -1,12 +1,36 @@ package net.kunmc.lab.teamkunpluginmanager.common.http; +/** + * HTTPリクエストのメソッドを表す列挙型です。 + */ public enum RequestMethod { + /** + * GETメソッドです。 + */ GET, + /** + * POSTメソッドです。 + */ POST, + /** + * PUTメソッドです。 + */ PUT, + /** + * DELETEメソッドです。 + */ DELETE, + /** + * HEADメソッドです。 + */ HEAD, + /** + * OPTIONSメソッドです。 + */ OPTIONS, + /** + * TRACEメソッドです。 + */ TRACE } diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java index d22200a1..818d9c36 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java +++ b/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java @@ -20,6 +20,9 @@ import java.util.Map; import java.util.function.Consumer; +/** + * HTTP リクエストを補助するクラスです。 + */ public class Requests { @Setter @@ -85,6 +88,12 @@ else if (host.equalsIgnoreCase("file.io")) return headers; } + /** + * リクエストを送信し、レスポンスを受け取ります。 + * + * @param context リクエストのコンテキスト + * @return レスポンス + */ @NotNull public static HTTPResponse request(@NotNull RequestContext context) { @@ -176,14 +185,13 @@ else if (responseCode >= 400) } /** - * Download a file from a URL - * - * @param method The HTTP method to use - * @param url The URL to download from - * @param path The path to save the file to - * @param onProgress A callback to be called when the download progresses. - * @return The downloaded file size or -1 if the download failed. - * @throws IOException If the download failed + * URLを使用してファイルをダウンロードします。 + * @param method リクエストメソッド + * @param url URL + * @param path ダウンロード先のパス + * @param onProgress ダウンロードの進捗を通知するコールバック + * @return ダウンロードしたファイルのパス + * @throws IOException ダウンロードに失敗した場合 */ public static long downloadFile(@NotNull RequestMethod method, @NotNull String url, @NotNull Path path, @Nullable Consumer onProgress) throws IOException @@ -237,6 +245,15 @@ else if (response.getInputStream() == null) } } + /** + * URLを使用してファイルをダウンロードします。 + * + * @param method リクエストメソッド + * @param url URL + * @param path ダウンロード先のパス + * @return ファイルの大きさ + * @throws IOException ダウンロードに失敗した場合 + */ public static long downloadFile(@NotNull RequestMethod method, @NotNull String url, @NotNull Path path) throws IOException { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index f77bec4c..499ded4b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -23,7 +23,7 @@ import java.util.List; /** - * KPMを操作するためのクラスです。 + * KPMのデーモンです。 */ @Getter public class KPMDaemon diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java index af1615f5..dd1dc8cb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java @@ -11,6 +11,9 @@ import java.util.List; import java.util.Map; +/** + * KPM の実行環境を表すクラスです。 + */ @Builder @Getter public class KPMEnvironment diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java index d91112bc..ba962be2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java @@ -10,6 +10,9 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; +/** + * エイリアスを使用してプラグインを解決するクラスです。 + */ public class AliasPluginResolver implements BaseResolver { private final PluginResolver resolver; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java index b9242df9..c2570b88 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java @@ -45,16 +45,32 @@ private void initializeTables() }); } + /** + * このクラスを破棄します。 + */ public void close() { this.db.close(); } + /** + * アップデータを作成します。 + * + * @param sourceName ソースの名前 + * @param sourceURL ソースのURL + * @return アップデータ + */ public AliasUpdater createUpdater(@NotNull String sourceName, @NotNull String sourceURL) { return new AliasUpdater(sourceName, sourceURL, this); } + /** + * エイリアスが存在するかどうかを返します。 + * + * @param name エイリアス対象の名前 + * @return エイリアスが存在するかどうか + */ public boolean hasAlias(@NotNull String name) { return Transaction.create(this.db, "SELECT COUNT(*) FROM alias WHERE name = ?") @@ -62,6 +78,12 @@ public boolean hasAlias(@NotNull String name) .isExists(); } + /** + * ソースが存在するかどうかを返します。 + * + * @param id ソースのID + * @return ソースが存在するかどうか + */ public boolean hasSource(String id) { return Transaction.create(this.db, "SELECT COUNT(*) FROM source WHERE name = ?") @@ -69,7 +91,13 @@ public boolean hasSource(String id) .isExists(); } - public AliasSource getSource(int id) + /** + * ソースを取得します。 + * + * @param id ソースのID + * @return ソース + */ + public AliasSource getSource(String id) { try (ResultRow row = Transaction.create(this.db, "SELECT * FROM source WHERE name = ?") .set(1, id) @@ -88,7 +116,13 @@ public AliasSource getSource(int id) } } - public Alias getAlias(String name) + /** + * エイリアスを取得します。 + * + * @param name エイリアス対象の名前 + * @return エイリアス + */ + public Alias getAlias(String name) // TODO: Update method name { try (ResultRow row = Transaction.create(this.db, "SELECT * FROM alias WHERE name = ?") .set(1, name) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java index 0d2af874..ba47836d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java @@ -26,6 +26,9 @@ public class AliasSource @NotNull SourceType type; + /** + * ソースの種類を表す列挙型です。 + */ public enum SourceType { /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java index 1a2b7389..8c4bc732 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java @@ -3,6 +3,9 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; +/** + * エイリアスを更新するトランザクションを補助するクラスです。 + */ public class AliasUpdater { private final String sourceName; @@ -36,6 +39,12 @@ private void dropCheckTable() .executeUpdate(false); } + /** + * エイリアスのアップデートを行います。 + * + * @param name エイリアス対象の名前 + * @param alias エイリアス + */ public void update(String name, String alias) { this.transaction.renew("INSERT OR REPLACE INTO alias (name, alias, source_id) VALUES (?, ?, ?)") @@ -55,6 +64,9 @@ private void deleteRemovedAlias() .executeUpdate(false); } + /** + * すべてのアップデートを終了し、データベースの更新を行います。 + */ public void done() { transaction.renew("INSERT OR REPLACE INTO source (name, source, type) VALUES (?, ?, ?)") @@ -68,6 +80,9 @@ public void done() this.transaction.finishManually(); } + /** + * アップデートをキャンセルし、データベースをロールバックします。 + */ public void cancel() { this.transaction.abortManually(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index 2258a649..c53cc8cd 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -16,6 +16,13 @@ import java.io.File; import java.io.IOException; +/** + * インストーラの基底クラスです。 + * + * @param インストーラの引数の型 + * @param インストールのタスクの列挙型 + * @param

    インストールのタスクの引数の型 + */ public abstract class AbstractInstaller, P extends Enum

    > { protected final KPMDaemon daemon; @@ -31,13 +38,37 @@ public AbstractInstaller(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager this.progress = InstallProgress.of(this, signalHandler, null); } + /** + * シグナルを送信します。 + * + * @param signal シグナル + */ protected void postSignal(@NotNull Signal signal) { this.signalHandler.handleSignal(this.progress, signal); } + /** + * インストーラを実行します。 + * このメソッドを直接呼び出すことは推奨されておらず、{@link AbstractInstaller#run(AbstractInstallerArgument)}を使用してください。 + * + * @param arguments インストーラに渡す引数 + * @return インストールの結果 + * @throws IOException ファイルの読み書きに失敗した場合 + * @throws TaskFailedException インストールの途中でタスクが失敗した場合 + * @see AbstractInstaller#run(AbstractInstallerArgument) + */ protected abstract InstallResult

    execute(@NotNull A arguments) throws IOException, TaskFailedException; + /** + * インストーラを実行します。 + * このメソッドは、内部で{@link AbstractInstaller#execute(AbstractInstallerArgument)}を呼び出します。 + * + * @param arguments インストーラに渡す引数 + * @return インストールの結果 + * @throws IOException ファイルの読み書きに失敗した場合 + * @see AbstractInstaller#execute(AbstractInstallerArgument) + */ public InstallResult

    run(@NotNull A arguments) throws IOException { try @@ -50,6 +81,11 @@ public InstallResult

    run(@NotNull A arguments) throws IOException } } + /** + * インストールが成功したときの後始末を行います。 + * + * @return インストールの結果 + */ @NotNull protected InstallResult

    success() { @@ -59,6 +95,12 @@ protected InstallResult

    success() return result; } + /** + * インストールが失敗したときの後始末を引数を指定して行います。 + * + * @param customResult インストールの結果 + * @return インストールの結果 + */ @NotNull protected InstallResult

    success(InstallResult

    customResult) { @@ -70,6 +112,13 @@ protected InstallResult

    success(InstallResult

    customResult) return customResult; } + /** + * インストールが失敗したときの後始末を行います。 + * + * @param reason 失敗の理由 + * @param インストールのタスクの列挙型 + * @return インストールの結果 + */ public > InstallFailedInstallResult error(@NotNull T reason) { // TODO: Implement debug mode InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, reason); @@ -78,6 +127,15 @@ protected InstallResult

    success(InstallResult

    customResult) return result; } + /** + * インストールが失敗したときの後始末を行います。 + * + * @param reason 失敗の理由 + * @param taskStatus タスクの状態 + * @param インストールのタスクの列挙型 + * @param インストールのタスクの引数の型 + * @return インストールの結果 + */ public , S extends Enum> InstallFailedInstallResult error( @Nullable T reason, @NotNull S taskStatus) @@ -98,6 +156,16 @@ private InstallResult

    handleTaskError(@NotNull TaskResult result) return this.error(null, result.getState()); } + /** + * タスクのSubmitterを取得します。 + * + * @param taskState タスクの状態 + * @param task タスク + * @param タスクの引数の型 + * @param タスクの戻り値の型 + * @param タスクの列挙型 + * @return タスクのSubmitter + */ @NotNull protected , TT extends InstallTask> TaskChain @@ -106,6 +174,12 @@ private InstallResult

    handleTaskError(@NotNull TaskResult result) return new TaskChain<>(task, taskState, this); } + /** + * プラグインが無視リストに入っているかどうかを取得します。 + * + * @param pluginName プラグインの名前 + * @return プラグインが無視リストに入っているかどうか + */ protected boolean isPluginIgnored(@NotNull String pluginName) { return KPMDaemon.getInstance().getEnvs().getExcludes().stream() @@ -113,6 +187,12 @@ protected boolean isPluginIgnored(@NotNull String pluginName) .anyMatch(s -> s.equalsIgnoreCase(pluginName)); } + /** + * ファイルを安全に削除します。 + * + * @param f 削除するファイル + * @return 削除に成功したかどうか + */ protected boolean safeDelete(@NotNull File f) { try diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java index e15aaf44..15b5d09a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java @@ -1,5 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.installer; +/** + * インストーラの引数の基底クラスです。 + */ public abstract class AbstractInstallerArgument { } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java index b5f3daef..b06a5520 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java @@ -15,8 +15,14 @@ public class InstallFailedInstallResult

    , T extends Enum, S extends Enum> extends InstallResult

    { + /** + * 失敗した理由を表す列挙型です。 + */ @Nullable private final T reason; + /** + * タスクの状態を表す列挙型です。 + */ @Nullable private final S taskStatus; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java index 979de851..84002779 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; /** - * プラグインのインストールを管理するクラスです。 + * インストールを管理するクラスです。 */ public class InstallManager { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java index 35c14391..0b0f4af1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java @@ -1,7 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task; /** - * タスクの引数を表します。 + * タスクの引数の基底クラスです。 */ public abstract class TaskArgument { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java index 9b027f59..c7fb7190 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java @@ -2,6 +2,9 @@ import lombok.Getter; +/** + * タスクが失敗したことを表すクラスです。 + */ public class TaskFailedException extends Exception { @Getter diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoadResult.java index 96d05325..3693e670 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoadResult.java @@ -20,7 +20,7 @@ public enum PluginLoadResult */ FILE_NOT_FOUND, /** - * pluigin.yml が不適切 + * plugin.yml が不適切 */ INVALID_PLUGIN_DESCRIPTION, /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index ba9cc7b2..92054d00 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -22,7 +22,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -public class PluginUtil // TODO: Rewrite this class +public class PluginUtil { private static final Method pluginGetFile; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 92fcefe3..9e9bbb30 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -14,7 +14,7 @@ import java.util.List; /** - * プラグインを解決するクラス + * プラグインを解決するクラスです。 */ public class PluginResolver { @@ -29,6 +29,12 @@ public PluginResolver() this.allResolvers = new ArrayList<>(); } + /** + * リゾルバを追加します。 + * + * @param resolver 追加するリゾルバ + * @param names リゾルバの名前とエイリアス + */ public void addResolver(BaseResolver resolver, String... names) { for (String name : names) @@ -47,13 +53,19 @@ public void addResolver(BaseResolver resolver, String... names) } } + /** + * 代替リゾルバを追加します。 + * 代替リゾルバは、プラグインが見つからなかった場合にフォールバックとして使用されるリゾルバです。 + * + * @param resolver 追加するリゾルバ + */ public void addOnNotFoundResolver(BaseResolver resolver) { onNotFoundResolvers.add(resolver); } /** - * クエリを使用してプラグインを解決する + * クエリを使用してプラグインを解決します。 * * @param query クエリ */ diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java index bfe4ba2e..316bd4ea 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java @@ -7,16 +7,25 @@ import org.jetbrains.annotations.Nullable; /** - * 複数の情報を含んだクエリ + * 複数の情報を含んだクエリです。 */ @Data @Builder public class QueryContext { + /** + * 指定リゾルバの名前です。 + */ @Nullable String resolverName; + /** + * 指定クエリです。 + */ @NotNull String query; + /** + * 指定バージョンです。 + */ @Nullable String version; @@ -24,7 +33,7 @@ public class QueryContext private static final String versionEqualQuerySeparator = "=="; /** - * クエリ文字列からQueryContextをパースする + * クエリ文字列からQueryContextを生成します。 * * @param query クエリ文字列 * @return QueryContext diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index 07ea353a..9eb8426b 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.annotation.Nonnull; import java.io.IOException; /** @@ -39,6 +40,7 @@ public CurseBukkitSuccessResult(@NotNull CurseBukkitResolver resolver, @NotNull this.title = title; } + @Nonnull @Override public String getUrl() { @@ -48,7 +50,7 @@ public String getUrl() return "https://dev.bukkit.org/projects/" + this.slug; } - + @Nonnull @Override public String getDescription() { diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java index 49de5960..59e9e924 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java @@ -7,6 +7,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.annotation.Nonnull; + @Getter public class GitHubSuccessResult extends SuccessResult implements MarketplaceResult { @@ -56,18 +58,21 @@ public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downl this.repoName = repoName; } + @Nonnull @Override public String getTitle() { return repoName + " - " + releaseName; } + @Nonnull @Override public String getUrl() { return "https://github.com/" + owner + "/" + repoName; } + @Nonnull @Override public String getDescription() { diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java index 8bb5ef8a..fd5c00f9 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -6,7 +6,7 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; /** - * プラグインリゾルバのインターフェース + * プラグインの解決を行うクラスのインターフェースです。 */ public interface BaseResolver { @@ -26,7 +26,7 @@ public interface BaseResolver ResolveResult autoPickOnePlugin(MultiResult multiResult); /** - * 与えられたクエリが解決可能かどうかを返します。 + * 与えられたクエリがこのリゾルバで解決可能かどうかを返します。 * * @param query クエリ * @return クエリが解決可能ならばtrue diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 781b785d..b7b89ef1 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -11,16 +11,23 @@ import java.util.regex.Pattern; /** - * URLをプラグインの直リンクに変換するためのリゾルバのインタフェース + * URL を解決するリゾルバのインターフェースです。 */ public interface URLResolver extends BaseResolver { /** - * 使用可能なURLのホスト - * @return ホスト + * このリゾルバが対応してるURLのホスト名を返します。 + * + * @return このリゾルバが対応してるURLのホスト名 */ String[] getHosts(); + /** + * このリゾルバがクエリに対応しているかを返します。 + * + * @param query クエリ (URL) + * @return このリゾルバがクエリに対応しているか + */ @Override default boolean isValidResolver(QueryContext query) { diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index 7f750a6a..ae186caf 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable; /** - * プラグイン解決中のエラーの結果。 + * 解決に失敗したことを表すクエリ解決結果です。 */ @EqualsAndHashCode @Getter @@ -15,19 +15,19 @@ public class ErrorResult implements ResolveResult { /** - * エラーケース + * エラーのかんたんな理由です。 */ @NotNull private final ErrorCause cause; /** - * プラグインの供給元 + * プラグインの提供元です。 */ @NotNull private final Source source; // TODO: フロントエンドに依存しないよう、メッセージプロバイダ作る。 /** - * この結果を提供したリゾルバ + * この解決を提供したリゾルバです。 */ @Nullable private final BaseResolver resolver; @@ -40,44 +40,46 @@ public ErrorResult(@Nullable BaseResolver resolver, @NotNull ErrorCause cause, @ } /** - * エラーケース + * エラーのかんたんな理由を表す列挙型です。 */ public enum ErrorCause { /** - * リゾルバが合っていない。 + * クエリに対応するリゾルバが見つかりませんでした。 */ RESOLVER_MISMATCH("対応するリゾルバが見つかりませんでした。"), /** - * 不正なクエリ + * 不正なクエリが指定されました。 */ INVALID_QUERY("不正なクエリです。"), /** - * プラグインがみつからない。 - * サーバが404を返した場合もこのケースになる。 + * プラグインが見つかりませんでした。 */ PLUGIN_NOT_FOUND("プラグインが見つかりませんでした。"), /** - * サーバに合ったプラグインが見つからなかった + * この Minecraft サーバに適合するプラグインが見つかりませんでした。 */ MATCH_PLUGIN_NOT_FOUND("サーバに対応するプラグインが見つかりませんでした。"), /** - * プラグイン自体は見つかったが、アセット(jarファイル)が見つからない。 + * プラグインは見つかりましたが、 .jar や .zip などのファイルが見つかりませんでした。 */ ASSET_NOT_FOUND("プラグインは見つかりましたが、ファイルが見つかりませんでした。"), /** - * サーバのレスポンスが破損している/おかしい。 + * サーバが不正なレスポンスを返しました。 */ SERVER_RESPONSE_MALFORMED("サーバが不正なレスポンスを返しました。"), /** - * その他のサーバに関するエラー + * サーバがエラーを返しました。 */ SERVER_RESPONSE_ERROR("サーバがエラーを返答しました。"), /** - * その他のエラー + * 不明なエラーが発生しました。 */ UNKNOWN_ERROR("不明なエラーが発生しました。"); + /** + * エラーの詳細な理由です。 + */ @Getter private String message; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java index 1f52af46..e0fe5aa2 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java @@ -1,25 +1,31 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; +import org.jetbrains.annotations.NotNull; + /** - * 紹介文付きのリソースの解決結果を格納。 + * プラグインの説明等が掲載されいる場合に返されるクラスです。 */ public interface MarketplaceResult { /** - * 掲載されているタイトル/名前 + * 掲載されているタイトル/名前を返します。 + * * @return 掲載されているタイトル/名前 */ + @NotNull String getTitle(); /** - * 掲載されているURL - * @return 掲載されているURL + * 掲載先のURLを返します. + * @return 掲載先のURL */ + @NotNull String getUrl(); /** - * 掲載されている紹介文 + * 掲載されている紹介文を返します。 * @return 掲載されている紹介文 */ + @NotNull String getDescription(); } diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java index bcad38e3..51fb8629 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java @@ -4,17 +4,17 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; /** - * 解決結果が複数ある場合に返されるクラス。 + * 解決結果が複数ある場合に返されるクラスです。 */ @Value public class MultiResult implements ResolveResult { /** - * リゾルバ + * この解決を提供したリゾルバです。 */ BaseResolver resolver; /** - * The results. + * 解決結果の配列です。 */ ResolveResult[] results; } diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java index 8c70e55a..206dbce4 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java @@ -6,18 +6,19 @@ import org.jetbrains.annotations.NotNull; /** - * 次のリゾルバに処理を任せる. + * 他のリゾルバに解決を委譲することを表す解決結果です。 + * 通常は内部でのみで使用され、{@link net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver#resolve(String)} から返されることはありません。 */ @Value public class PipeResult implements ResolveResult { /** - * リゾルバ + * この解決を提供したリゾルバです。 */ @NotNull BaseResolver resolver; /** - * 改変したクエリ + * リゾルバがクエリを改変する場合に使用されるクエリです。 */ @NotNull QueryContext query; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java index 9bc2eaa7..89caed74 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -5,19 +5,19 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; /** - * プラグイン解決結果のインタフェース + * プラグイン解決結果のインタフェースです。 */ public interface ResolveResult { /** - * この結果を解決したリゾルバ + * この解決を提供したリゾルバです。 * * @return リゾルバ */ BaseResolver getResolver(); /** - * プラグイン供給元 + * プラグイン供給元です。 */ @AllArgsConstructor enum Source diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java index 37c8d044..057a17ca 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java @@ -6,37 +6,37 @@ import org.jetbrains.annotations.Nullable; /** - * 解決成功のResolveResult実装。 + * 解決に成功したことを表すクエリ解決結果です。 */ @Data public class SuccessResult implements ResolveResult { /** - * プラグインのダウンロードリンク + * プラグインのダウンロードリンクです。 */ @NotNull private final String downloadUrl; /** - * プラグインのファイル名 + * プラグインのファイル名です。 */ @Nullable private final String fileName; /** - * プラグインのバージョン + * プラグインのバージョンです。 */ @Nullable private final String version; /** - * プラグインの供給元 + * プラグインの供給元です。 */ @NotNull private final Source source; /** - * この結果を提供したリゾルバ + * この解決を提供したリゾルバです。 */ @NotNull private final BaseResolver resolver; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java index 5f50f1c9..6c9372d2 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java @@ -3,13 +3,12 @@ import java.util.List; /** - * プラグインの対応するバージョンを格納するインターフェース。 + * プラグインの対応するバージョンを格納するインターフェースです。 */ public interface VersionedResult { /** - * プラグインの対応する一覧。 - * + * プラグインが対応するバージョン一覧です。 */ List getVersions(); } From ffbaaf76204cf39c9fcd794a8530ae346022d9ac Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 12 Oct 2022 20:32:53 +0900 Subject: [PATCH 368/745] refactor: getAlias => getNameByAlias --- .../lab/teamkunpluginmanager/alias/AliasPluginResolver.java | 2 +- .../net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java index ba962be2..11edd399 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java @@ -27,7 +27,7 @@ public AliasPluginResolver(@NotNull KPMDaemon daemon) @Override public ResolveResult resolve(QueryContext query) { - Alias alias = this.aliasProvider.getAlias(query.getQuery()); + Alias alias = this.aliasProvider.getNameByAlias(query.getQuery()); if (alias == null) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java index c2570b88..f345557a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java @@ -122,7 +122,7 @@ public AliasSource getSource(String id) * @param name エイリアス対象の名前 * @return エイリアス */ - public Alias getAlias(String name) // TODO: Update method name + public Alias getNameByAlias(String name) { try (ResultRow row = Transaction.create(this.db, "SELECT * FROM alias WHERE name = ?") .set(1, name) From 22215ca03b3324a1a40f76b0a6cb2993235446c5 Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 12 Oct 2022 20:33:27 +0900 Subject: [PATCH 369/745] chore: Remove old todo --- .../lab/teamkunpluginmanager/installer/AbstractInstaller.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index c53cc8cd..33371fc5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -120,7 +120,7 @@ protected InstallResult

    success(InstallResult

    customResult) * @return インストールの結果 */ public > InstallFailedInstallResult error(@NotNull T reason) - { // TODO: Implement debug mode + { InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, reason); this.postSignal(new InstallFinishedSignal(result)); @@ -139,7 +139,7 @@ protected InstallResult

    success(InstallResult

    customResult) public , S extends Enum> InstallFailedInstallResult error( @Nullable T reason, @NotNull S taskStatus) - { // TODO: Implement debug mode + { InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, reason, taskStatus); this.postSignal(new InstallFinishedSignal(result)); From 90a2025719b96ca2c47d13ea005998308a02b977 Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 12 Oct 2022 20:46:04 +0900 Subject: [PATCH 370/745] refactor: Utils to KPMPlugin --- .../main/java/net/kunmc/lab/teamkunpluginmanager}/Utils.java | 2 +- .../kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java | 2 +- .../handlers/autoremove/AutoRemoveReadySignalHandler.java | 2 +- .../signal/handlers/common/DownloadingSignalHandler.java | 2 +- .../signal/handlers/common/InstallFinishedSignalBase.java | 2 +- .../signal/handlers/uninstall/UninstallReadySignalHandler.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename {KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils => KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager}/Utils.java (96%) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/Utils.java similarity index 96% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java rename to KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/Utils.java index e90ba136..cd674586 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Utils.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/Utils.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.teamkunpluginmanager; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java index 14c6edbf..9b1b1bf9 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java @@ -5,12 +5,12 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.Utils; import net.kunmc.lab.teamkunpluginmanager.meta.DependType; import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMeta; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java index 3d5eb9bf..27af8e47 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java @@ -1,10 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.Utils; import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; import java.util.List; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java index e88b4cf6..32c9ad04 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java @@ -2,11 +2,11 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.Utils; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java index 13b4c8a9..a246b62f 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java @@ -3,11 +3,11 @@ import lombok.AccessLevel; import lombok.Setter; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.Utils; import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.signals.InstallFinishedSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; /** * インストールが完了したときのシグナルを処理するハンドラーの基底クラスです。 diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java index 7230f2b6..5e6a22be 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -1,10 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.Utils; import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.UninstallReadySignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.utils.Utils; import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; From 90c03707486f08294ce0c23f7510ad9b534ddee7 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 13 Oct 2022 17:32:22 +0900 Subject: [PATCH 371/745] refactor: Remove human-readable name from Source --- .../resolver/result/ErrorResult.java | 2 +- .../resolver/result/ResolveResult.java | 25 ++++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index ae186caf..dd7ed5fd 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -24,7 +24,7 @@ public class ErrorResult implements ResolveResult * プラグインの提供元です。 */ @NotNull - private final Source source; // TODO: フロントエンドに依存しないよう、メッセージプロバイダ作る。 + private final Source source; /** * この解決を提供したリゾルバです。 diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java index 89caed74..5166f575 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.AllArgsConstructor; -import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; /** @@ -25,34 +24,30 @@ enum Source /** * GitHub */ - GITHUB("GitHub"), + GITHUB, /** - * @link https://www.spigotmc.org/resources/ + * ... */ - SPIGOT_MC("Spigot-MC"), + SPIGOT_MC, /** - * @link https://dev.bukkit.org/projects/plugins/ + * ... */ - DEV_BUKKIT("Bukkit-Project"), + DEV_BUKKIT, /** - * @link https://curseforge.com/bukkit-plugins/ + * ... */ - CURSE_FORGE("CurseForge"), + CURSE_FORGE, /** * ローカルの既知プラグイン */ - LOCAL_KNOWN("Alias"), + LOCAL_KNOWN, /** * 直リンク */ - DIRECT("Direct"), + DIRECT, /** * 不明 */ - UNKNOWN("Unknown"); - - @Getter - private final String name; - + UNKNOWN } } From 5d513c9293b8f4bfc89cc916f45b9df4d6d575fa Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 13 Oct 2022 17:46:29 +0900 Subject: [PATCH 372/745] refactor: Remove pre-filled message from ErrorCause --- .../intall/ResolverSignalHandler.java | 6 +- .../resolver/PluginResolver.java | 2 +- .../resolver/impl/CurseBukkitResolver.java | 2 +- .../resolver/impl/GitHubURLResolver.java | 6 +- .../resolver/impl/SpigotMCResolver.java | 11 ++-- .../resolver/interfaces/URLResolver.java | 40 +++++++------ .../resolver/result/ErrorResult.java | 59 ++++++++----------- 7 files changed, 64 insertions(+), 62 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java index ac419efd..f4eabfe8 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java @@ -7,6 +7,7 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolvingSignal; +import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.bukkit.ChatColor; @@ -39,7 +40,10 @@ public void onPluginResolving(PluginResolvingSignal signal) @SignalHandler public void onPluginResolveError(PluginResolveErrorSignal signal) { - terminal.error(signal.getError().getCause().getMessage()); + ErrorResult.ErrorCause errorCause = signal.getError().getCause(); + String message = signal.getError().getMessage() == null ? "": "(" + signal.getError().getMessage() + ")"; + + terminal.writeLine(ChatColor.RED + "プラグインの解決に失敗しました: " + errorCause + message); } @SignalHandler diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 9e9bbb30..8d2b3434 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -96,7 +96,7 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext if (result instanceof ErrorResult) { ErrorResult error = (ErrorResult) result; - if (error.getCause() != ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND) + if (error.getCause() != ErrorResult.ErrorCause.VERSION_MISMATCH) result = resolves(onNotFoundResolvers, queryContext, url); } diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 8d766e52..658a61f6 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -120,7 +120,7 @@ private ResolveResult processFiles(String slug, String name, long projectId, Str JsonObject pickedPlugin = pickUpValidVersion(projectFilesResult, version); if (pickedPlugin == null) - return new ErrorResult(this, ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, source); + return new ErrorResult(this, ErrorResult.ErrorCause.VERSION_MISMATCH, source); String downloadUrl = pickedPlugin.get("downloadUrl").getAsString(); String fileName = pickedPlugin.get("fileName").getAsString(); diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 325bc676..ffea4020 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -117,7 +117,7 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri if (result instanceof ErrorResult) { ErrorResult errorResult = (ErrorResult) result; - if (errorResult.getCause() == ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND) + if (errorResult.getCause() == ErrorResult.ErrorCause.VERSION_MISMATCH) isFound = true; else if (errorResult.getCause() == ErrorResult.ErrorCause.ASSET_NOT_FOUND) isNoAssets = true; @@ -131,7 +131,7 @@ else if (errorResult.getCause() == ErrorResult.ErrorCause.ASSET_NOT_FOUND) if (isFound) return new ErrorResult( this, - ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("指定されたバージョンが見つかりませんでした。"), + ErrorResult.ErrorCause.VERSION_MISMATCH, ResolveResult.Source.GITHUB ); else if (isNoAssets) @@ -156,7 +156,7 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso if (queryVersion != null && !queryVersion.equalsIgnoreCase(version) && !("v" + queryVersion).equalsIgnoreCase(queryVersion) && !queryVersion.equalsIgnoreCase("v" + queryVersion)) - return new ErrorResult(this, ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.VERSION_MISMATCH, ResolveResult.Source.GITHUB); JsonArray assets = object.getAsJsonArray("assets"); diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 31aca8c4..42049106 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -67,7 +67,7 @@ private ResolveResult buildResult(JsonObject jsonObject, @Nullable String versio { boolean external = jsonObject.get("external").getAsBoolean(); if (external) - return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("SpigotMC ではホストされていません。"), + return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.SPIGOT_MC ); @@ -80,8 +80,9 @@ private ResolveResult buildResult(JsonObject jsonObject, @Nullable String versio boolean premium = jsonObject.get("premium").getAsBoolean(); if (premium) - return new ErrorResult(this, ErrorResult.ErrorCause.MATCH_PLUGIN_NOT_FOUND.value("このプラグインはプレミアムプラグインです。"), - ResolveResult.Source.SPIGOT_MC + return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND, + ResolveResult.Source.SPIGOT_MC, + "This plugin is marked as premium plugin." ); long[] versions = StreamSupport.stream(jsonObject.get("versions").getAsJsonArray().spliterator(), false) @@ -106,8 +107,8 @@ private ResolveResult buildResult(JsonObject jsonObject, @Nullable String versio if (String.valueOf(v).equals(version)) return new SpigotMCSuccessResult(this, version, name, id, description, testedVersions); - return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND.value("指定されたバージョンのプラグインが見つかりませんでした。"), - ResolveResult.Source.SPIGOT_MC + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.SPIGOT_MC, + "Version " + version + " not found." ); } diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index b7b89ef1..d889571e 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -74,32 +74,34 @@ default ErrorResult processErrorResponse(HTTPResponse response, ResolveResult.So switch (response.getStatus()) { case URL_MALFORMED: - return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY.value("不正なURLが指定されました。"), source); + return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, source, "URL Malformed."); case UNABLE_TO_RESOLVE_HOST: - URL url = null; + URL url; try { url = new URL(response.getRequest().getUrl()); } - catch (MalformedURLException ignored) + catch (MalformedURLException e) { + throw new IllegalStateException("Illegal URL: " + response.getRequest().getUrl()); } return new ErrorResult(this, - ErrorResult.ErrorCause.INVALID_QUERY.value("ホストが解決できませんでした:" + - (url == null ? "Unknown host": url.getHost())), source + ErrorResult.ErrorCause.HOST_RESOLVE_FAILED, source, + "Unable to resolve host " + url.getHost() + "." ); case REDIRECT_LIMIT_EXCEED: return new ErrorResult(this, - ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED.value("リダイレクト回数が上限に達しました。"), source + ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED, source, "Redirect limit exceed." ); case IO_EXCEPTION_OCCURRED: return new ErrorResult(this, ErrorResult.ErrorCause.UNKNOWN_ERROR, source); case REDIRECT_LOCATION_MALFORMED: return new ErrorResult( this, - ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED.value("リダイレクト先が不正です:" + response.getHeader("Location")), - source + ErrorResult.ErrorCause.SERVER_RESPONSE_MALFORMED, + source, + "Redirect location malformed: " + response.getHeader("Location") ); } @@ -109,25 +111,27 @@ default ErrorResult processErrorResponse(HTTPResponse response, ResolveResult.So case 200: return null; case 403: - return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR - .value(errorCodeWith("サーバからリソースをダウンロードする権限がありません。", code)), source); + return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR, source, + errorCodeWith("Forbidden", code) + ); case 404: return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND - .value(errorCodeWith("サーバからリソースを見つけることができません。", code)), source); + , source, errorCodeWith("Not Found", code) + ); case 418: return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR - .value(errorCodeWith("ティーポットでコーヒーを淹れようとしました。", code)), source + , source, errorCodeWith("I'm a teapot", code) ); default: if (code >= 500 && code < 600) return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR - .value(errorCodeWith("サーバーがダウンしています。", code)), source); - - return new ErrorResult(this, ErrorResult.ErrorCause.SERVER_RESPONSE_ERROR - .value(errorCodeWith("サーバーがエラーレスポンスを返答しました。。", code)), - source - ); + , source, errorCodeWith("Server Error", code) + ); + else + return new ErrorResult(this, ErrorResult.ErrorCause.UNKNOWN_ERROR + , source, errorCodeWith("Unknown Error", code) + ); } } } diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java index dd7ed5fd..3af97005 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java @@ -32,11 +32,23 @@ public class ErrorResult implements ResolveResult @Nullable private final BaseResolver resolver; - public ErrorResult(@Nullable BaseResolver resolver, @NotNull ErrorCause cause, @NotNull Source source) + /** + * エラーの詳細な理由です。 + */ + @Nullable + private final String message; + + public ErrorResult(@Nullable BaseResolver resolver, @NotNull ErrorCause cause, @NotNull Source source, @Nullable String message) { - this.resolver = resolver; this.cause = cause; this.source = source; + this.resolver = resolver; + this.message = message; + } + + public ErrorResult(@Nullable BaseResolver resolver, @NotNull ErrorCause cause, @NotNull Source source) + { + this(resolver, cause, source, null); } /** @@ -47,57 +59,38 @@ public enum ErrorCause /** * クエリに対応するリゾルバが見つかりませんでした。 */ - RESOLVER_MISMATCH("対応するリゾルバが見つかりませんでした。"), + RESOLVER_MISMATCH, /** * 不正なクエリが指定されました。 */ - INVALID_QUERY("不正なクエリです。"), + INVALID_QUERY, + /** + * ホストの解決に失敗しました。 + */ + HOST_RESOLVE_FAILED, /** * プラグインが見つかりませんでした。 */ - PLUGIN_NOT_FOUND("プラグインが見つかりませんでした。"), + PLUGIN_NOT_FOUND, /** * この Minecraft サーバに適合するプラグインが見つかりませんでした。 */ - MATCH_PLUGIN_NOT_FOUND("サーバに対応するプラグインが見つかりませんでした。"), + VERSION_MISMATCH, /** * プラグインは見つかりましたが、 .jar や .zip などのファイルが見つかりませんでした。 */ - ASSET_NOT_FOUND("プラグインは見つかりましたが、ファイルが見つかりませんでした。"), + ASSET_NOT_FOUND, /** * サーバが不正なレスポンスを返しました。 */ - SERVER_RESPONSE_MALFORMED("サーバが不正なレスポンスを返しました。"), + SERVER_RESPONSE_MALFORMED, /** * サーバがエラーを返しました。 */ - SERVER_RESPONSE_ERROR("サーバがエラーを返答しました。"), + SERVER_RESPONSE_ERROR, /** * 不明なエラーが発生しました。 */ - UNKNOWN_ERROR("不明なエラーが発生しました。"); - - /** - * エラーの詳細な理由です。 - */ - @Getter - private String message; - - @Getter - private boolean messageChanged; - - ErrorCause(String message) - { - this.message = message; - this.messageChanged = false; - } - - public ErrorCause value(String message) - { - this.message = message; - this.messageChanged = true; - return this; - } - + UNKNOWN_ERROR } } From acac0c428a6bbbc2176b622c8daaa5bfc6b4079c Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 14 Oct 2022 18:39:11 +0900 Subject: [PATCH 373/745] refactor: Fix Hided type parameter name of A in AbstractInstaller#submitter --- .../teamkunpluginmanager/installer/AbstractInstaller.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index 33371fc5..e35e47c0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -161,14 +161,14 @@ private InstallResult

    handleTaskError(@NotNull TaskResult result) * * @param taskState タスクの状態 * @param task タスク - * @param タスクの引数の型 + * @param タスクの引数の型 * @param タスクの戻り値の型 * @param タスクの列挙型 * @return タスクのSubmitter */ @NotNull - protected , TT extends InstallTask> - TaskChain + protected , TT extends InstallTask> + TaskChain submitter(@NotNull P taskState, @NotNull TT task) { return new TaskChain<>(task, taskState, this); From 0f6ba083b606abc45adcdef97b8a7446c6676f17 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 14 Oct 2022 18:39:42 +0900 Subject: [PATCH 374/745] refactor: Fix missing @NotNull in DownloadProgressSignal. --- .../task/tasks/download/signals/DownloadProgressSignal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java index 3a95a4ca..a2d1ea7c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java @@ -32,7 +32,7 @@ public class DownloadProgressSignal extends DownloadSignal */ double percentage; - public DownloadProgressSignal(@NotNull String downloadId, String url, long totalSize, long downloaded, double percentage) + public DownloadProgressSignal(@NotNull String downloadId, @NotNull String url, long totalSize, long downloaded, double percentage) { super(downloadId); this.url = url; From fc075451ec1cb167ed279277525f35f0f7730009 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 14 Oct 2022 18:40:13 +0900 Subject: [PATCH 375/745] refactor: Replace statement with lambda in InstallManager --- .../lab/teamkunpluginmanager/installer/InstallManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java index 84002779..78c79084 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java @@ -67,9 +67,7 @@ public boolean isRunning() this.runningInstall = installer.getProgress(); - Runner.runAsync(() -> { - installer.run(arguments); - }); + Runner.runAsync(() -> installer.run(arguments)); return (InstallProgress) installer.getProgress(); } From d6b199187ea46d59e1b646bfb789ee3ec6835e1a Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 14 Oct 2022 18:41:43 +0900 Subject: [PATCH 376/745] fix: Fix unchecked warn --- .../lab/teamkunpluginmanager/installer/InstallProgress.java | 6 ++++-- .../lab/teamkunpluginmanager/installer/task/TaskChain.java | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java index 6214a632..73f3e065 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java @@ -143,9 +143,11 @@ private InstallProgress(@NotNull I installer, * @param id インストールに割り当てる一意のID * @param

    インストールの進捗状況の型 * @return インスタンス - * @throws IOException ディレクトリの作成に失敗した場合 - * @throws SecurityException ディレクトリの作成に失敗した場合 + * @throws IOException ディレクトリの作成に失敗した場合 + * @throws SecurityException ディレクトリの作成に失敗した場合 + * @throws ClassCastException 間違った型のキャッシュを取得しようとした場合 */ + @SuppressWarnings("unchecked") public static

    , PI extends AbstractInstaller> InstallProgress of( @NotNull PI installer, @NotNull SignalHandleManager signalHandler, diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java index 0136d2f3..bcee021e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java @@ -111,6 +111,7 @@ public TaskChain bridgeArgument(@NotNull Function argu * @return タスクの結果 * @throws TaskFailedException タスクの実行に失敗した場合 */ + @SuppressWarnings("unchecked") public @NotNull TaskResult submitFromThis(@NotNull TaskArgument argument) throws TaskFailedException { try From bb61605cf35929dda4e411891ed7fdd9f2ad05bb Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 14 Oct 2022 18:43:35 +0900 Subject: [PATCH 377/745] refactor: Simplify regex of SpigotMCResolver --- .../teamkunpluginmanager/resolver/impl/SpigotMCResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 42049106..3a66190c 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -22,7 +22,7 @@ public class SpigotMCResolver implements URLResolver { - private static final Pattern PATTERN = Pattern.compile("/resources/([\\w-]+\\.?(?[\\d]+))(?:/|/updates/?|/downloads/?|(?:update/?\\?update=|download/?\\?version=)(?\\d+))?"); + private static final Pattern PATTERN = Pattern.compile("/resources/([\\w-]+\\.?(?\\d+))(?:/|/updates/?|/downloads/?|(?:update/?\\?update=|download/?\\?version=)(?\\d+))?"); @Override public ResolveResult resolve(QueryContext query) From ea75c9dddc79f26a6c99fa9ce63176881eb74dd6 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 14 Oct 2022 19:28:26 +0900 Subject: [PATCH 378/745] refactor: Merge kpm-common and kpm-resolver --- KPMCommon/pom.xml | 21 -------------- KPMDaemon/pom.xml | 11 ------- .../lab/teamkunpluginmanager/KPMDaemon.java | 3 +- .../lab/teamkunpluginmanager}/TokenStore.java | 2 +- .../installer/InstallManager.java | 2 +- .../task/tasks/download/DownloadTask.java | 6 ++-- .../resolver/PluginResolver.java | 0 .../resolver/QueryContext.java | 0 .../impl/BruteforceGitHubResolver.java | 0 .../resolver/impl/CurseBukkitResolver.java | 6 ++-- .../impl/CurseBukkitSuccessResult.java | 6 ++-- .../resolver/impl/GitHubSuccessResult.java | 0 .../resolver/impl/GitHubURLResolver.java | 6 ++-- .../resolver/impl/OmittedGitHubResolver.java | 0 .../resolver/impl/SpigotMCResolver.java | 6 ++-- .../resolver/impl/SpigotMCSuccessResult.java | 0 .../resolver/interfaces/BaseResolver.java | 0 .../resolver/interfaces/URLResolver.java | 2 +- .../resolver/result/ErrorResult.java | 0 .../resolver/result/MarketplaceResult.java | 0 .../resolver/result/MultiResult.java | 0 .../resolver/result/PipeResult.java | 3 +- .../resolver/result/ResolveResult.java | 0 .../resolver/result/SuccessResult.java | 0 .../resolver/result/VersionedResult.java | 0 .../utils}/http/DownloadProgress.java | 2 +- .../utils}/http/HTTPResponse.java | 2 +- .../utils}/http/RequestContext.java | 2 +- .../utils}/http/RequestMethod.java | 2 +- .../utils}/http/Requests.java | 4 +-- .../commands/CommandRegister.java | 8 ++--- KPMResolver/pom.xml | 29 ------------------- pom.xml | 2 -- 33 files changed, 31 insertions(+), 94 deletions(-) delete mode 100644 KPMCommon/pom.xml rename {KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager}/TokenStore.java (99%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java (96%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java (91%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java (97%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java (96%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java (98%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java (77%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java (100%) rename {KPMResolver => KPMDaemon}/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java (100%) rename {KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils}/http/DownloadProgress.java (88%) rename {KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils}/http/HTTPResponse.java (99%) rename {KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils}/http/RequestContext.java (95%) rename {KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils}/http/RequestMethod.java (90%) rename {KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common => KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils}/http/Requests.java (98%) delete mode 100644 KPMResolver/pom.xml diff --git a/KPMCommon/pom.xml b/KPMCommon/pom.xml deleted file mode 100644 index 333593e8..00000000 --- a/KPMCommon/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - TeamKunPluginManager - net.kunmc.lab - 3.0.0-pre5 - ../pom.xml - - 4.0.0 - - KPMCommon - - - 8 - 8 - UTF-8 - - - diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index 0bdbf962..ead1c96e 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -19,17 +19,6 @@ - - net.kunmc.lab - KPMResolver - ${project.version} - - - net.kunmc.lab - KPMCommon - ${project.version} - compile - commons-io commons-io diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 499ded4b..3bd070dc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -4,8 +4,6 @@ import lombok.Getter; import net.kunmc.lab.teamkunpluginmanager.alias.AliasPluginResolver; import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; -import net.kunmc.lab.teamkunpluginmanager.common.TokenStore; -import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.installer.InstallManager; import net.kunmc.lab.teamkunpluginmanager.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; @@ -15,6 +13,7 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java similarity index 99% rename from KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java index 9aec45dc..5d7109b6 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/TokenStore.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.common; +package net.kunmc.lab.teamkunpluginmanager; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java index 78c79084..c875f4ca 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java @@ -2,7 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.common.TokenStore; +import net.kunmc.lab.teamkunpluginmanager.TokenStore; import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.InstallerRunningException; import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.TokenNotAvailableException; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java index 667fa826..5b7f0015 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java @@ -1,8 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; -import net.kunmc.lab.teamkunpluginmanager.common.http.DownloadProgress; -import net.kunmc.lab.teamkunpluginmanager.common.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; @@ -10,6 +7,9 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadStartingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java similarity index 96% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 658a61f6..3eda030b 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -3,14 +3,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.jetbrains.annotations.Nullable; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java similarity index 91% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java index 9eb8426b..f76d4dcc 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java @@ -1,11 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java similarity index 97% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index ffea4020..57f497f2 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -3,15 +3,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java similarity index 96% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 3a66190c..3e785416 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -2,14 +2,14 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java similarity index 98% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index d889571e..5bfbbbed 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -1,9 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; -import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; import java.net.MalformedURLException; import java.net.URL; diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java similarity index 77% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java index 206dbce4..cf719c56 100644 --- a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java @@ -1,13 +1,14 @@ package net.kunmc.lab.teamkunpluginmanager.resolver.result; import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; /** * 他のリゾルバに解決を委譲することを表す解決結果です。 - * 通常は内部でのみで使用され、{@link net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver#resolve(String)} から返されることはありません。 + * 通常は内部でのみで使用され、{@link PluginResolver#resolve(String)} から返されることはありません。 */ @Value public class PipeResult implements ResolveResult diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java diff --git a/KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java similarity index 100% rename from KPMResolver/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java similarity index 88% rename from KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java index 63f51494..9669b864 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/DownloadProgress.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.common.http; +package net.kunmc.lab.teamkunpluginmanager.utils.http; import lombok.Value; diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java similarity index 99% rename from KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index f1884fbf..9f55f717 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/HTTPResponse.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.common.http; +package net.kunmc.lab.teamkunpluginmanager.utils.http; import com.google.gson.Gson; import com.google.gson.JsonElement; diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java similarity index 95% rename from KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java index fcc156b7..0e9af511 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestContext.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.common.http; +package net.kunmc.lab.teamkunpluginmanager.utils.http; import lombok.Builder; import lombok.Singular; diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java similarity index 90% rename from KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java index 9d08440e..91d90e04 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/RequestMethod.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.common.http; +package net.kunmc.lab.teamkunpluginmanager.utils.http; /** * HTTPリクエストのメソッドを表す列挙型です。 diff --git a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java similarity index 98% rename from KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 818d9c36..5f3de598 100644 --- a/KPMCommon/src/main/java/net/kunmc/lab/teamkunpluginmanager/common/http/Requests.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.common.http; +package net.kunmc.lab.teamkunpluginmanager.utils.http; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.common.TokenStore; +import net.kunmc.lab.teamkunpluginmanager.TokenStore; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 010e0170..7f101e52 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -9,10 +9,10 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.common.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.common.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.common.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.common.http.Requests; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import net.kyori.adventure.text.TextComponent; import org.bukkit.ChatColor; import org.bukkit.command.BlockCommandSender; diff --git a/KPMResolver/pom.xml b/KPMResolver/pom.xml deleted file mode 100644 index 50d5cbda..00000000 --- a/KPMResolver/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - TeamKunPluginManager - net.kunmc.lab - 3.0.0-pre5 - ../pom.xml - - 4.0.0 - - KPMResolver - - - 8 - 8 - UTF-8 - - - - - net.kunmc.lab - KPMCommon - 3.0.0-pre5 - provided - - - diff --git a/pom.xml b/pom.xml index 501cad10..32b132a2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,6 @@ KPMDaemon KPMPlugin - KPMResolver - KPMCommon pom From ebc3b4434a341024bb35d9cc36dbf76a90106c38 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 15 Oct 2022 01:01:28 +0900 Subject: [PATCH 379/745] feat: New token register --- .../impls/register/RegisterArgument.java | 22 ++ .../impls/register/RegisterErrorCause.java | 24 ++ .../impls/register/RegisterTasks.java | 20 ++ .../impls/register/TokenRegisterer.java | 317 ++++++++++++++++++ .../pojos/UserVerificationCodeResponse.java | 45 +++ .../VerificationSubmitPollingResponse.java | 35 ++ .../signals/TokenGenerateStartingSignal.java | 21 ++ .../register/signals/TokenStoredSignal.java | 18 + .../UserDoesntCompleteVerifySignal.java | 34 ++ .../UserVerificationSuccessSignal.java | 30 ++ .../signals/UserVerifyDeniedSignal.java | 15 + .../VerificationCodeExpiredSignal.java | 18 + .../VerificationCodeReceivedSignal.java | 43 +++ .../VerificationCodeRequestFailedSignal.java | 22 ++ .../VerificationCodeRequestingSignal.java | 10 + .../utils/http/HTTPResponse.java | 16 + .../utils/http/Requests.java | 2 + .../teamkunpluginmanager/HeadInstallers.java | 29 ++ .../TeamKunPluginManager.java | 2 +- .../commands/CommandRegister.java | 183 +--------- .../signal/HeadSignalHandlers.java | 11 + .../register/TokenGenerateSignalHandler.java | 110 ++++++ .../register/TokenRegisterSignalHandler.java | 23 ++ 23 files changed, 874 insertions(+), 176 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterArgument.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterErrorCause.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterTasks.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/UserVerificationCodeResponse.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/VerificationSubmitPollingResponse.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenGenerateStartingSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenStoredSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerificationSuccessSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerifyDeniedSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeExpiredSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeReceivedSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestingSignal.java create mode 100644 KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java create mode 100644 KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterArgument.java new file mode 100644 index 00000000..cf35e69b --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterArgument.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import org.jetbrains.annotations.Nullable; + +/** + * トークン登録の引数を格納するクラスです。 + */ +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class RegisterArgument extends AbstractInstallerArgument +{ + /** + * GitHubのアクセストークンです。 + */ + @Nullable + private final String token; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterErrorCause.java new file mode 100644 index 00000000..3a6a555a --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterErrorCause.java @@ -0,0 +1,24 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; + +/** + * トークン登録のエラーを表す列挙型です。 + */ +public enum RegisterErrorCause +{ + /** + * I/Oエラーが発生したことを示します。 + */ + IO_EXCEPTION_OCCURRED, + /** + * キャンセルされたことを示します。 + */ + GENERATE_CANCELLED, + /** + * ユーザ検証コードの要求に失敗したことを示します。 + */ + VERIFICATION_CODE_REQUEST_FAILED, + /** + * コードの検証に失敗したことを示します。 + */ + VERIFICATION_FAILED, +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterTasks.java new file mode 100644 index 00000000..c45a0390 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterTasks.java @@ -0,0 +1,20 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; + +/** + * トークン登録のタスクを表す列挙型です。 + */ +public enum RegisterTasks +{ + /** + * トークンの登録中であることを示します。 + */ + REGISTERING_TOKEN, + /** + * ユーザ検証コードの要求中であることを示します。 + */ + REQUESTING_USER_VERIFICATION_CODE, + /** + * ユーザの検証コードの入力を待機していることを示します。 + */ + POLLING_USER_VERIFICATION, +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java new file mode 100644 index 00000000..fbe83302 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java @@ -0,0 +1,317 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; + +import com.google.gson.JsonObject; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos.UserVerificationCodeResponse; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos.VerificationSubmitPollingResponse; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenGenerateStartingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenStoredSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserDoesntCompleteVerifySignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerificationSuccessSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerifyDeniedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeExpiredSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeReceivedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; +import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; +import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +/** + * GitHubのトークンを登録するインストーラーの実装です。 + * トークン登録は主に以下の流れで動作します。 + * + *

      + *
    1. {@link RegisterTasks#} - トークン登録対象のプラグインを検索する。
    2. + *
    + */ +public class TokenRegisterer extends AbstractInstaller +{ + private static final String CLIENT_ID = "94c5d446dbc765895979"; + private static final String OAUTH_SCOPE = "repo&20public_repo"; + + private static final String VERIFICATION_CODE_REQUEST_URL = + "https://github.com/login/device/code"; + private static final String VERIFICATION_POLLING_URL = "https://github.com/login/oauth/access_token"; + + private static final String VERIFICATION_CODE_REQUEST_PARM = "client_id=%s&scope=%s"; + private static final String VERIFICATION_POLLING_BODY_PARM = + "client_id=%s&device_code=%s&grant_type=urn%%3Aietf%%3Aparams%%3Aoauth%%3Agrant-type%%3Adevice_code"; + + public TokenRegisterer(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException + { + super(daemon, signalHandler); + } + + private static byte[] urlEncodeAndToBytes(String str) + { + try + { + return URLEncoder.encode( + str, + StandardCharsets.UTF_8.name() + ).getBytes(StandardCharsets.UTF_8); + } + catch (UnsupportedEncodingException e) + { + // This exception will never be thrown. + throw new RuntimeException(e); + } + } + + @Override + public InstallResult execute(@NotNull RegisterArgument argument) throws TaskFailedException + { + // region Check if token is provided in argument + if (argument.getToken() != null) // Token is already prepared, so register it as is. + if (registerToken(argument.getToken())) + return this.success(); + else + return this.error(RegisterErrorCause.IO_EXCEPTION_OCCURRED); + // endregion + + // Token is not prepared, so request it from GitHub. + + // region Ask user to generate token + TokenGenerateStartingSignal signal = new TokenGenerateStartingSignal(); + this.postSignal(signal); + + boolean doContinue = signal.isContinueGenerate(); + + if (!doContinue) + return this.error(RegisterErrorCause.GENERATE_CANCELLED); + + // endregion + + return this.generateToken(); + } + + private InstallResult generateToken() + { + // region Request verification code + this.progress.setCurrentTask(RegisterTasks.REQUESTING_USER_VERIFICATION_CODE); + this.postSignal(new VerificationCodeRequestingSignal()); + UserVerificationCodeResponse userVerifyCodeResponse = requestVerificationCode(); + if (userVerifyCodeResponse == null) + return this.error(RegisterErrorCause.VERIFICATION_CODE_REQUEST_FAILED); + + this.postSignal(new VerificationCodeReceivedSignal(userVerifyCodeResponse)); + + // endregion + + String accessToken; + String tokenType; + String scope; + // region Polling user verification + + this.progress.setCurrentTask(RegisterTasks.POLLING_USER_VERIFICATION); + VerificationSubmitPollingResponse pollingResponse = pollVerifyCodeSubmit(userVerifyCodeResponse); + if (pollingResponse == null) + return this.error(RegisterErrorCause.VERIFICATION_FAILED); + + accessToken = pollingResponse.getAccessToken(); + tokenType = pollingResponse.getTokenType(); + scope = pollingResponse.getScope(); + + // endregion + + this.postSignal(new UserVerificationSuccessSignal(accessToken, tokenType, scope)); + + if (registerToken(accessToken)) + return this.success(); + else + return this.error(RegisterErrorCause.IO_EXCEPTION_OCCURRED); + } + + @Nullable + private UserVerificationCodeResponse requestVerificationCode() + { + try (HTTPResponse response = Requests.request( + RequestContext.builder() + .url(VERIFICATION_CODE_REQUEST_URL + "?" + String.format(VERIFICATION_CODE_REQUEST_PARM, CLIENT_ID, OAUTH_SCOPE)) + .method(RequestMethod.POST) + .header("Accept", "application/json") + .header("Content-Type", "application/x-www-form-urlencoded") + .build() + )) + { + if (!response.isSuccessful()) + { + String errorMessage = getErrorMessage(response); + int errorCode = response.getStatusCode(); + this.postSignal(new VerificationCodeRequestFailedSignal( + errorCode, + errorMessage + )); + + return null; + } + + return toUserVerificationCodeResponse(response); + } + catch (IOException e) + { + e.printStackTrace(); + return null; + } + } + + private UserVerificationCodeResponse toUserVerificationCodeResponse(@NotNull HTTPResponse response) + { + JsonObject json = response.getAsJson().getAsJsonObject(); + if (json == null) + return null; + + if (!json.has("device_code") + || !json.has("user_code") + || !json.has("verification_uri") + || !json.has("expires_in") + || !json.has("interval")) + return null; // Invalid response. + + return response.getAsObject(UserVerificationCodeResponse.class); + } + + private void randomSleep(long interval) + { + long sleepTime = interval + (long) (Math.random() * 500); + try + { + Thread.sleep(sleepTime); + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } + } + + @Nullable + private VerificationSubmitPollingResponse pollVerifyCodeSubmit(UserVerificationCodeResponse apiResponse) + { + long start = System.currentTimeMillis(); + long expiresIn = apiResponse.getExpiresIn() * 1000; + long intervalMillis = apiResponse.getInterval() * 1000; + + while (true) + { + long current = System.currentTimeMillis(); + long remaining = expiresIn - (current - start); + + if (remaining <= 0) + { + this.postSignal(new VerificationCodeExpiredSignal(apiResponse.getUserCode())); + return null; + } + + try (HTTPResponse response = Requests.request( + RequestContext.builder() + .url(VERIFICATION_POLLING_URL + "?" + + String.format(VERIFICATION_POLLING_BODY_PARM, CLIENT_ID, apiResponse.getDeviceCode())) + .method(RequestMethod.POST) + .header("Accept", "application/json") + .header("Content-Type", "application/x-www-form-urlencoded") + .build() + )) + { + if (!response.isSuccessful()) + { + JsonObject json = response.getAsJson().getAsJsonObject(); + String error = json.get("error").getAsString(); + + switch (error) + { + case "authorization_pending": + this.postSignal(new UserDoesntCompleteVerifySignal( + apiResponse.getUserCode(), + apiResponse.getVerificationUrl(), + expiresIn, + remaining + )); + break; + case "slow_down": + if (json.has("interval")) + intervalMillis = json.get("interval").getAsLong() * 1000; + break; + case "expired_token": + this.postSignal(new VerificationCodeExpiredSignal(apiResponse.getUserCode())); + return null; + case "access_denied": + this.postSignal(new UserVerifyDeniedSignal(apiResponse.getUserCode())); + return null; + default: + this.daemon.getLogger().warn("Unknown error occurred while polling user verification: " + error); + return null; + } + + randomSleep(intervalMillis); + continue; + } + + VerificationSubmitPollingResponse pollingResponse = toVerificationSubmitPollingResponse(response); + if (pollingResponse != null) + return pollingResponse; + } + catch (IOException e) + { + e.printStackTrace(); + return null; + } + + randomSleep(intervalMillis); + } + } + + private VerificationSubmitPollingResponse toVerificationSubmitPollingResponse(HTTPResponse response) + { + JsonObject json = response.getAsJson().getAsJsonObject(); + if (json == null) + return null; + + if (!json.has("access_token") + || !json.has("token_type") + || !json.has("scope")) + return null; // Invalid response. + + return response.getAsObject(VerificationSubmitPollingResponse.class); + } + + @NotNull + private String getErrorMessage(HTTPResponse response) + { + JsonObject json = response.getAsJson().getAsJsonObject(); + if (json == null || !json.has("error")) + return "unknown"; + + return json.get("error").getAsString(); + } + + private boolean registerToken(@NotNull String token) + { + this.progress.setCurrentTask(RegisterTasks.REGISTERING_TOKEN); + + try + { + this.daemon.getTokenStore().storeToken(token); + this.postSignal(new TokenStoredSignal(token)); + + return true; + } + catch (IOException e) + { + e.printStackTrace(); + return false; + } + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/UserVerificationCodeResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/UserVerificationCodeResponse.java new file mode 100644 index 00000000..e2700b9d --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/UserVerificationCodeResponse.java @@ -0,0 +1,45 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos; + +import com.google.gson.annotations.SerializedName; +import lombok.Value; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザ検証コード要求のレスポンスです。 + */ +@Value +public class UserVerificationCodeResponse +{ + /** + * デバイスコードです。 + */ + @NotNull + @SerializedName("device_code") + String deviceCode; + + /** + * ユーザコードです。 + */ + @NotNull + @SerializedName("user_code") + String userCode; + + /** + * 認証URLです。 + */ + @NotNull + @SerializedName("verification_uri") + String verificationUrl; + + /** + * 認証コードの有効期限です。 + */ + @SerializedName("expires_in") + long expiresIn; + + /** + * ポーリング間隔です。 + */ + @SerializedName("interval") + long interval; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/VerificationSubmitPollingResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/VerificationSubmitPollingResponse.java new file mode 100644 index 00000000..aa617ab7 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/VerificationSubmitPollingResponse.java @@ -0,0 +1,35 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos; + +import com.google.gson.annotations.SerializedName; +import lombok.EqualsAndHashCode; +import lombok.Value; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザが検証コードを入力し、トークンの取得が完了したことを示すレスポンスです。 + */ +@Value +@EqualsAndHashCode(callSuper = false) +public class VerificationSubmitPollingResponse +{ + /** + * アクセストークンです。 + */ + @NotNull + @SerializedName("access_token") + String accessToken; + + /** + * トークンの種類です。 + */ + @NotNull + @SerializedName("token_type") + String tokenType; + + /** + * トークンのスコープです。 + */ + @NotNull + @SerializedName("scope") + String scope; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenGenerateStartingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenGenerateStartingSignal.java new file mode 100644 index 00000000..7aafa017 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenGenerateStartingSignal.java @@ -0,0 +1,21 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; + +/** + * トークンの生成の開始中であることを示すシグナルです。 + */ +@Data +public class TokenGenerateStartingSignal implements Signal +{ + /** + * 生成を続けるかどうかを示すフラグです。 + */ + private boolean continueGenerate; + + public TokenGenerateStartingSignal() + { + this.continueGenerate = true; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenStoredSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenStoredSignal.java new file mode 100644 index 00000000..7823e142 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenStoredSignal.java @@ -0,0 +1,18 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * トークンが登録されたことを示すシグナルです。 + */ +@Value +public class TokenStoredSignal implements Signal +{ + /** + * 登録されたトークンです。 + */ + @NotNull + String token; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java new file mode 100644 index 00000000..9a73c184 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java @@ -0,0 +1,34 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザが検証コードの入力を完了していないことを示すシグナルです。 + */ +@Value +public class UserDoesntCompleteVerifySignal implements Signal +{ + /** + * ユーザが入力するコードです。 + */ + @NotNull + String userCode; + + /** + * 認証URLです。 + */ + @NotNull + String verificationUrl; + + /** + * コードが期限切れになる時間です。 + */ + long expiresIn; + + /** + * コードの残り有効期限です。 + */ + long remainTime; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerificationSuccessSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerificationSuccessSignal.java new file mode 100644 index 00000000..82d9c7bb --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerificationSuccessSignal.java @@ -0,0 +1,30 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザ検証に成功したことを示すシグナルです。 + */ +@Value +public class UserVerificationSuccessSignal implements Signal +{ + /** + * アクセストークンです。 + */ + @NotNull + String accessToken; + + /** + * トークンのタイプです。(例:Bearer) + */ + @NotNull + String tokenType; + + /** + * トークンのスコープです。 + */ + @NotNull + String scope; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerifyDeniedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerifyDeniedSignal.java new file mode 100644 index 00000000..869d1d52 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerifyDeniedSignal.java @@ -0,0 +1,15 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザがキャンセルをクリックしたことを示すシグナルです。 + */ +@Value +public class UserVerifyDeniedSignal implements Signal +{ + @NotNull + String userCode; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeExpiredSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeExpiredSignal.java new file mode 100644 index 00000000..98c8006f --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeExpiredSignal.java @@ -0,0 +1,18 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザの検証コードの有効期限が切れたことを示すシグナルです。 + */ +@Value +public class VerificationCodeExpiredSignal implements Signal +{ + /** + * ユーザが入力するべきだった検証コードです。 + */ + @NotNull + String userCode; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeReceivedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeReceivedSignal.java new file mode 100644 index 00000000..b740ffc0 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeReceivedSignal.java @@ -0,0 +1,43 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos.UserVerificationCodeResponse; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザ検証コードを受信したことを示すシグナルです。 + */ +@Value +public class VerificationCodeReceivedSignal implements Signal +{ + /** + * ユーザが入力する検証コードです。 + */ + @NotNull + String userCode; + + /** + * ユーザが検証コードを入力するURLです。 + */ + @NotNull + String verificationUrl; + + /** + * 認証コードの有効期限(秒)です。 + */ + long expiresIn; + + /** + * 認証コードの有効期限のUNIX時間です。 + */ + long expiresAt; + + public VerificationCodeReceivedSignal(@NotNull UserVerificationCodeResponse apiResponse) + { + this.userCode = apiResponse.getUserCode(); + this.verificationUrl = apiResponse.getVerificationUrl(); + this.expiresIn = apiResponse.getExpiresIn(); // Unit: seconds + this.expiresAt = System.currentTimeMillis() + (apiResponse.getExpiresIn() * 1000); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java new file mode 100644 index 00000000..2295855d --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java @@ -0,0 +1,22 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * ユーザ検証コード要求に失敗したときに発行されるシグナルです。 + */ +@Value +public class VerificationCodeRequestFailedSignal implements Signal +{ + /** + * HTTPステータスコードです。 + */ + int httpStatusCode; + /** + * エラーメッセージです。 + */ + @NotNull + String errorMessage; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestingSignal.java new file mode 100644 index 00000000..bff543a6 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestingSignal.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; + +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; + +/** + * ユーザ検証コードの要求中であることを示すシグナルです。 + */ +public class VerificationCodeRequestingSignal implements Signal +{ +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 9f55f717..75aa2c5f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -111,6 +111,22 @@ public JsonElement getAsJson() return new Gson().fromJson(json, JsonElement.class); } + /** + * レスポンスボディをオブジェクトとして取得します。 + * + * @param clazz クラス + * @param クラスの型 + * @return レスポンスボディ + */ + public T getAsObject(Class clazz) + { + if (inputStream == null) + return null; + + String json = getAsString(); + return new Gson().fromJson(json, clazz); + } + /** * このクラスを破棄します。 * diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 5f3de598..470be149 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -112,6 +112,8 @@ public static HTTPResponse request(@NotNull RequestContext context) if (context.getTimeout() > 0) connection.setReadTimeout(context.getTimeout()); + if (context.getMethod() == RequestMethod.POST) + connection.setDoOutput(true); for (Map.Entry entry : context.getExtraHeaders().entrySet()) connection.setRequestProperty(entry.getKey(), entry.getValue()); diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java index fadff8ae..0fed0c4f 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java @@ -12,6 +12,8 @@ import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.GarbageCleaner; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.PluginInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.RegisterArgument; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.TokenRegisterer; import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.AliasUpdater; @@ -172,4 +174,31 @@ public void runGarbageClean(@NotNull Terminal terminal, @NotNull CleanArgument a this.headRun(terminal, garbageCleaner, argument); } + + /** + * トークンの登録を実行します。 + * + * @param terminal ターミナル + * @param argument トークン登録の引数 + * @throws IllegalStateException インストールが進行中の場合 + */ + public void runRegister(@NotNull Terminal terminal, @NotNull RegisterArgument argument) throws IllegalStateException + { + SignalHandleManager handleManager = new SignalHandleManager(); + HeadSignalHandlers.getTokenRegistererHandlers(terminal).forEach(handleManager::register); + + TokenRegisterer register; + try + { + register = new TokenRegisterer(this.daemon, handleManager); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("インストーラの初期化に失敗しました:" + e.getMessage()); + return; + } + + this.headRun(terminal, register, argument); + } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 5f57c7d8..15fa603d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -40,7 +40,7 @@ public void registerCommands(CommandManager commandManager) commandManager.registerCommand("clean", new CommandClean(this)); commandManager.registerCommand("info", new CommandInfo(this.daemon)); commandManager.registerCommand("install", new CommandInstall(this), "add", "i"); - commandManager.registerCommand("register", new CommandRegister(this.daemon), "login"); + commandManager.registerCommand("register", new CommandRegister(this, this.daemon), "login"); commandManager.registerCommand("reload", new CommandReload(this.daemon)); commandManager.registerCommand("resolve", new CommandResolve(this.daemon)); commandManager.registerCommand("status", new CommandStatus(this.daemon)); diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java index 7f101e52..395a336d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java @@ -1,151 +1,26 @@ package net.kunmc.lab.teamkunpluginmanager.commands; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; import lombok.AllArgsConstructor; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; -import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.RegisterArgument; import net.kyori.adventure.text.TextComponent; -import org.bukkit.ChatColor; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; @AllArgsConstructor public class CommandRegister extends CommandBase { - private static final String CLIENT_ID = "94c5d446dbc765895979"; - private static final String OAUTH_SCOPE = "repo%20public_repo"; - private static final String OAUTH_PREPARE_URL = - "https://github.com/login/device/code?client_id=" + CLIENT_ID + "&scope=" + OAUTH_SCOPE; - private static final String OAUTH_ACCESS_URL = - "https://github.com/login/oauth/access_token?client_id=" + CLIENT_ID + - "&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&device_code="; - + private final TeamKunPluginManager plugin; private final KPMDaemon daemon; - private static void parseErrorAndPost(Terminal terminal, HTTPResponse response) - { - try - { - JsonObject json = response.getAsJson().getAsJsonObject(); - if (json.has("error")) - terminal.error("エラーが発生しました。:Server response with " + parseError(json.get("error").getAsString())); - else - terminal.error("エラーが発生しました。:Server response with code " + response.getStatusCode()); - } - catch (JsonSyntaxException | IllegalStateException e) - { - String responseString = response.getAsString(); - - terminal.error("サーバから不正なデータを受信しました。:" + - responseString.substring(0, Math.min(responseString.length(), 50))); - } - } - - private void performAction(Terminal terminal) - { - terminal.info(ChatColor.LIGHT_PURPLE + "サーバと通信しています..."); - - HTTPResponse response = Requests.request(RequestContext.builder() - .method(RequestMethod.POST) - .url(OAUTH_PREPARE_URL) - .build()); - - if (response.getStatus() != HTTPResponse.RequestStatus.OK) - { - parseErrorAndPost(terminal, response); - return; - } - - JsonObject object = response.getAsJson().getAsJsonObject(); - - String deviceCode = object.get("device_code").getAsString(); - String userCode = object.get("user_code").getAsString(); - String verifyURI = object.get("verification_uri").getAsString(); - int expireSeconds = object.get("expires_in").getAsInt(); - int pollingInterval = object.get("interval").getAsInt(); - - terminal.writeLine(ChatColor.DARK_GREEN + "こちらからコードを有効化してください:" + ChatColor.BLUE + ChatColor.UNDERLINE + verifyURI); - terminal.writeLine(ChatColor.DARK_GREEN + "コード: " + ChatColor.WHITE + userCode); - terminal.writeLine(ChatColor.DARK_GRAY + "I:なお、このコードは " + (expireSeconds / 60) + " 分で失効します。"); - if (terminal.isPlayer()) - terminal.showNotification(userCode, "GitHubでこのコードを入力して有効化してください。", expireSeconds * 20); - //ここからポーリング - - AtomicBoolean successFlag = new AtomicBoolean(false); - - BukkitTask task = Runner.runTimerAsync( - polling(terminal, deviceCode, successFlag), (exception, bukkitTask) -> bukkitTask.cancel(), - 100L, (pollingInterval * 20L) + 20L - ); - - Runner.runTimer(() -> { - if (!successFlag.get()) - return; - task.cancel(); - - throw new RuntimeException(); - }, (e, t) -> t.cancel(), 10L * 20L); - - } - - private Runner.GeneralExceptableRunner polling(Terminal terminal, String device_code, AtomicBoolean successFlag) - { - return () -> { - HTTPResponse httpResponse = Requests.request(RequestContext.builder() - .method(RequestMethod.POST) - .url(OAUTH_ACCESS_URL + device_code) - .build()); - - if (httpResponse.getStatus() != HTTPResponse.RequestStatus.OK) - { - parseErrorAndPost(terminal, httpResponse); - throw new RuntimeException(); // For cancel bukkit task - } - - JsonObject response = httpResponse.getAsJson().getAsJsonObject(); - - if (response.has("error")) - { - if (response.get("error").getAsString().equals("authorization_pending")) - return; - - terminal.error( - "エラーが発生しました。:Server response with %s", - parseError(response.get("error").getAsString()) - ); - - if (terminal.isPlayer()) - terminal.clearNotification(); - - throw new RuntimeException(); // For cancel bukkit task - } - - this.daemon.getTokenStore().storeToken(response.get("access_token").getAsString()); - terminal.success("トークンを正常に保管しました!"); - if (terminal.isPlayer()) - terminal.clearNotification(); - successFlag.set(true); - - throw new RuntimeException(); // For cancel bukkit task - }; - } - @Override public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) { @@ -155,53 +30,11 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } - if (args.length == 1) - { - try - { - this.daemon.getTokenStore().storeToken(args[0]); - } - catch (IOException e) - { - e.printStackTrace(); - terminal.error("トークンの保存に失敗しました。"); - return; - } - - terminal.success("トークンを正常に保管しました!"); - return; - } - - Runner.runAsync(() -> { - QuestionResult result = terminal.getInput(). - showQuestion("GitHubサーバを用いてトークンを生成しますか?", QuestionAttribute.YES, QuestionAttribute.CANCELLABLE) - .waitAndGetResult(); - - if (result.test(QuestionAttribute.CANCELLABLE)) - terminal.error("キャンセルしました。"); - else if (result.test(QuestionAttribute.YES)) - this.performAction(terminal); - - }, (e, b) -> { - }); - } + String tokenOrNull = args.length >= 1 ? args[0]: null; - private static String parseError(String err) - { - String response = err; - - switch (err) - { - case "expired_token": - case "incorrect_device_code": - response = "有効期限が切れています。もう一度お試しください。"; - break; - case "access_denied": - response = "キャンセルされました。"; - break; - } - - return response; + Runner.runAsync(() -> + this.plugin.getHeadInstallers().runRegister(terminal, new RegisterArgument(tokenOrNull)) + ); } @Override @@ -219,7 +52,7 @@ private static String parseError(String err) @Override public TextComponent getHelpOneLine() { - return of("事前に取得したトークンを設定または、GitHubでログインしてトークンを設定します。"); + return of("事前に取得したトークンを設定または、GitHubにログインしてトークンを設定します。"); } @Override diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java index 9c131855..f2061041 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java @@ -12,6 +12,8 @@ import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.InstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.ResolverSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.register.TokenGenerateSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.handlers.register.TokenRegisterSignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.PluginIsDependencySignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallFinishedSignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallReadySignalHandler; @@ -118,4 +120,13 @@ public static List getGarbageCleanHandlers(Terminal terminal) new GarbageCleanSignalHandler(terminal) ); } + + public static List getTokenRegistererHandlers(Terminal terminal) + { + return createHandlersList( + getCommonHandlers(terminal), + new TokenRegisterSignalHandler(terminal), + new TokenGenerateSignalHandler(terminal) + ); + } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java new file mode 100644 index 00000000..43c87570 --- /dev/null +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java @@ -0,0 +1,110 @@ +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.register; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenGenerateStartingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserDoesntCompleteVerifySignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerificationSuccessSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerifyDeniedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeExpiredSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeReceivedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestFailedSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestingSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; +import org.bukkit.ChatColor; + +public class TokenGenerateSignalHandler +{ + private final Progressbar progressbar; + private final Terminal terminal; + + public TokenGenerateSignalHandler(Terminal terminal) + { + this.terminal = terminal; + this.progressbar = terminal.createProgressbar("codeExpire"); + this.progressbar.setPrefix(ChatColor.GREEN + "コード有効期限: "); + } + + @SignalHandler + public void onTokenGenerateStarting(TokenGenerateStartingSignal signal) + { + terminal.info("GitHub へ Web ブラウザを用いてログインします。"); + terminal.info("この操作により、 KPM はあなたの GitHub アカウントにアクセスできるようになります。"); + + signal.setContinueGenerate(SignalHandlingUtils.askContinue(terminal)); + } + + @SignalHandler + public void onVerificationCodeRequesting(VerificationCodeRequestingSignal signal) + { + terminal.info("サーバに接続しています ..."); + } + + @SignalHandler + public void onVerificationCodeRequestFailed(VerificationCodeRequestFailedSignal signal) + { + terminal.removeProgressbar("codeExpire"); + + terminal.error("検証コードの取得に失敗しました:" + signal.getHttpStatusCode() + " " + signal.getErrorMessage()); + } + + @SignalHandler + public void onVerificationCodeReceived(VerificationCodeReceivedSignal signal) + { + String userCode = signal.getUserCode(); + String verificationUrl = signal.getVerificationUrl(); + long expiresInSec = signal.getExpiresIn(); + int expiresInMin = (int) (expiresInSec / 60); + + terminal.writeLine( + ChatColor.DARK_GREEN + "このリンクからコードを有効化してください:" + + ChatColor.BLUE + ChatColor.UNDERLINE + verificationUrl); + terminal.writeLine(ChatColor.DARK_GREEN + "コード: " + ChatColor.WHITE + userCode); + terminal.info("I:このコードは " + expiresInMin + " 分で失効します。"); + + int expiresInSecInt = (int) expiresInSec; + + if (terminal.isPlayer()) + terminal.showNotification(userCode, "GitHubでこのコードを入力して有効化してください。", + expiresInSecInt * 1000 + ); + + this.progressbar.setProgressMax(expiresInSecInt); + this.progressbar.setProgress(expiresInSecInt); + this.progressbar.show(); + } + + @SignalHandler + public void onVerificationCodeExpired(VerificationCodeExpiredSignal signal) + { + terminal.error("コードが失効しました: " + signal.getUserCode()); + + progressbar.hide(); + terminal.removeProgressbar("codeExpire"); + } + + @SignalHandler + public void onUserDoesntCompleteVerify(UserDoesntCompleteVerifySignal signal) + { + progressbar.setProgress((int) signal.getRemainTime()); + } + + @SignalHandler + public void onUserVerifyDenied(UserVerifyDeniedSignal signal) + { + progressbar.hide(); + terminal.removeProgressbar("codeExpire"); + + terminal.error("コードの有効化に失敗しました:ユーザがコードの有効化を拒否しました。"); + } + + @SignalHandler + public void onUserVerifySucceeded(UserVerificationSuccessSignal signal) + { + progressbar.hide(); + terminal.removeProgressbar("codeExpire"); + + terminal.success("コードの有効化に成功しました。"); + } +} diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java new file mode 100644 index 00000000..17713d5d --- /dev/null +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.teamkunpluginmanager.signal.handlers.register; + +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenStoredSignal; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; + +public class TokenRegisterSignalHandler +{ + private final Terminal terminal; + + public TokenRegisterSignalHandler(Terminal terminal) + { + this.terminal = terminal; + } + + @SignalHandler + public void onTokenStored(TokenStoredSignal signal) + { + terminal.success("トークンが登録されました。"); + } + + +} From ef609c9c02dfbad4ce1d7e0d7622dcf603d6d355 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 15 Oct 2022 01:02:28 +0900 Subject: [PATCH 380/745] fix: Invalid japanese --- .../signal/handlers/register/TokenGenerateSignalHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java index 43c87570..33a147bc 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java @@ -61,7 +61,7 @@ public void onVerificationCodeReceived(VerificationCodeReceivedSignal signal) ChatColor.DARK_GREEN + "このリンクからコードを有効化してください:" + ChatColor.BLUE + ChatColor.UNDERLINE + verificationUrl); terminal.writeLine(ChatColor.DARK_GREEN + "コード: " + ChatColor.WHITE + userCode); - terminal.info("I:このコードは " + expiresInMin + " 分で失効します。"); + terminal.info("このコードは " + expiresInMin + " 分で失効します。"); int expiresInSecInt = (int) expiresInSec; From bce26a2e7d1423bb076cc99a2db9f4cc8b01a55f Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 15 Oct 2022 01:15:53 +0900 Subject: [PATCH 381/745] style: Add this qualifier --- .../lab/teamkunpluginmanager/KPMDaemon.java | 2 +- .../lab/teamkunpluginmanager/TokenStore.java | 26 ++++++------ .../alias/AliasPluginResolver.java | 2 +- .../alias/AliasUpdater.java | 10 ++--- .../installer/InstallManager.java | 2 +- .../installer/InstallResult.java | 24 +++++------ .../impls/autoremove/AutoRemoveArgument.java | 2 +- .../installer/impls/clean/CleanArgument.java | 2 +- .../impls/install/PluginInstaller.java | 16 +++---- .../impls/register/TokenRegisterer.java | 18 ++++---- .../collector/DependsCollectStatus.java | 12 +++--- .../collector/DependsCollectTask.java | 4 +- .../signals/DependencyNameMismatchSignal.java | 2 +- .../task/tasks/download/DownloadTask.java | 4 +- .../tasks/install/PluginsInstallTask.java | 8 ++-- .../task/tasks/resolve/PluginResolveTask.java | 2 +- .../task/tasks/uninstall/UnInstallTask.java | 4 +- .../loader/CommandsPatcher.java | 4 +- .../meta/PluginMetaManager.java | 2 +- .../meta/PluginMetaProvider.java | 18 ++++---- .../resolver/PluginResolver.java | 20 ++++----- .../impl/BruteforceGitHubResolver.java | 4 +- .../resolver/impl/CurseBukkitResolver.java | 10 ++--- .../resolver/impl/GitHubSuccessResult.java | 6 +-- .../resolver/impl/GitHubURLResolver.java | 12 +++--- .../resolver/impl/SpigotMCResolver.java | 10 ++--- .../resolver/interfaces/BaseResolver.java | 2 +- .../resolver/interfaces/URLResolver.java | 4 +- .../signal/SignalHandleManager.java | 10 ++--- .../signal/SignalHandlerList.java | 16 +++---- .../utils/ReflectionUtils.java | 8 ++-- .../utils/db/ResultRow.java | 20 ++++----- .../utils/db/Transaction.java | 32 +++++++------- .../utils/http/HTTPResponse.java | 36 ++++++++-------- .../TeamKunPluginManager.java | 6 +-- .../commands/debug/CommandDepTreeDebug.java | 10 ++--- .../commands/debug/DebugSignalHandler.java | 4 +- .../deptree/CommandMarkAsDependency.java | 6 +-- .../commands/debug/deptree/CommandPurge.java | 10 ++--- .../debug/deptree/CommandRelation.java | 18 ++++---- .../AutoRemoveReadySignalHandler.java | 4 +- .../clean/GarbageCleanSignalHandler.java | 2 +- .../common/CheckEnvSignalHandler.java | 26 ++++++------ .../common/DownloadingSignalHandler.java | 10 ++--- .../common/InstallFinishedSignalBase.java | 8 ++-- .../handlers/common/ModifySignalHandler.java | 2 +- .../intall/DependenciesSignalHandler.java | 12 +++--- .../intall/InstallerSignalHandler.java | 8 ++-- .../intall/ResolverSignalHandler.java | 14 +++---- .../register/TokenGenerateSignalHandler.java | 42 +++++++++---------- .../register/TokenRegisterSignalHandler.java | 2 +- .../PluginIsDependencySignalHandler.java | 16 +++---- .../UninstallReadySignalHandler.java | 10 ++--- .../uninstall/UninstallerSignalHandler.java | 10 ++--- .../update/UpdateAliasesSignalHandler.java | 16 +++---- 55 files changed, 295 insertions(+), 295 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 3bd070dc..b1a437f1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -160,7 +160,7 @@ private void setupToken() private void initializeRequests() { - Requests.setVersion(getVersion()); + Requests.setVersion(this.getVersion()); Requests.setTokenStore(this.tokenStore); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java index 5d7109b6..d3638365 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java @@ -39,7 +39,7 @@ public TokenStore(@NotNull Path tokenPath, @NotNull Path keyPath) this.tokenPath = tokenPath; try { - this.key = getkey(keyPath); + this.key = this.getkey(keyPath); this.SECONDARY_KEY_SPEC = getKeySpec(SECONDARY_KEY); } catch (IOException e) @@ -88,10 +88,10 @@ private byte[] encryptToken(String token) try { Cipher cipher = Cipher.getInstance("AES"); - cipher.init(Cipher.ENCRYPT_MODE, SECONDARY_KEY_SPEC); + cipher.init(Cipher.ENCRYPT_MODE, this.SECONDARY_KEY_SPEC); byte[] encrypted = cipher.doFinal(token.getBytes()); - cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, ALGORITHM)); + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(this.key, ALGORITHM)); return cipher.doFinal(encrypted); } @@ -106,11 +106,11 @@ private String decryptToken(byte[] encryptedToken) try { Cipher cipher = Cipher.getInstance(ALGORITHM); - cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, ALGORITHM)); + cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(this.key, ALGORITHM)); byte[] decrypted = cipher.doFinal(encryptedToken); - cipher.init(Cipher.DECRYPT_MODE, SECONDARY_KEY_SPEC); + cipher.init(Cipher.DECRYPT_MODE, this.SECONDARY_KEY_SPEC); return new String(cipher.doFinal(decrypted)); } @@ -150,7 +150,7 @@ private byte[] getkey(Path keyPath) throws IOException */ public void storeToken(String token) throws IOException { - byte[] tokenBytes = encryptToken(token); + byte[] tokenBytes = this.encryptToken(token); long time = System.currentTimeMillis(); String tokenBody = Base64.getEncoder().encodeToString(tokenBytes); String tokenString = String.format( @@ -159,9 +159,9 @@ public void storeToken(String token) throws IOException time ); - Files.write(tokenPath, tokenString.getBytes()); + Files.write(this.tokenPath, tokenString.getBytes()); - setPermission(tokenPath); + setPermission(this.tokenPath); this.tokenCache = token; } @@ -174,17 +174,17 @@ public void storeToken(String token) throws IOException */ public boolean loadToken() throws IOException { - if (!Files.exists(tokenPath)) + if (!Files.exists(this.tokenPath)) return false; - String tokenString = new String(Files.readAllBytes(tokenPath)); + String tokenString = new String(Files.readAllBytes(this.tokenPath)); String[] tokenParts = tokenString.split(","); if (tokenParts.length != 2) return false; String tokenBody = tokenParts[0]; - this.tokenCache = decryptToken(Base64.getDecoder().decode(tokenBody)); + this.tokenCache = this.decryptToken(Base64.getDecoder().decode(tokenBody)); return true; } @@ -203,7 +203,7 @@ public boolean migrateToken() throws IOException return false; String token = new String(Files.readAllBytes(oldToken.toPath())); - storeToken(token); + this.storeToken(token); //noinspection ResultOfMethodCallIgnored oldToken.delete(); @@ -232,7 +232,7 @@ public String getToken() { try { - loadToken(); + this.loadToken(); } catch (IOException e) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java index 11edd399..e2380085 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java @@ -34,7 +34,7 @@ public ResolveResult resolve(QueryContext query) try { - ResolveResult detailedResult = resolver.resolve(alias.getName()); + ResolveResult detailedResult = this.resolver.resolve(alias.getName()); if (detailedResult instanceof SuccessResult) return new SuccessResult(this, ((SuccessResult) detailedResult).getDownloadUrl(), ResolveResult.Source.LOCAL_KNOWN); else diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java index 8c4bc732..c810df71 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java @@ -50,7 +50,7 @@ public void update(String name, String alias) this.transaction.renew("INSERT OR REPLACE INTO alias (name, alias, source_id) VALUES (?, ?, ?)") .set(1, name) .set(2, alias) - .set(3, sourceName) + .set(3, this.sourceName) .executeUpdate(false); this.aliasesCount++; @@ -60,7 +60,7 @@ private void deleteRemovedAlias() { this.transaction.renew("DELETE FROM alias WHERE name IN " + "(SELECT name FROM v_exists_alias EXCEPT SELECT name FROM alias WHERE source_id = ?)") - .set(1, sourceName) + .set(1, this.sourceName) .executeUpdate(false); } @@ -69,9 +69,9 @@ private void deleteRemovedAlias() */ public void done() { - transaction.renew("INSERT OR REPLACE INTO source (name, source, type) VALUES (?, ?, ?)") - .set(1, sourceName) - .set(2, sourceURL) + this.transaction.renew("INSERT OR REPLACE INTO source (name, source, type) VALUES (?, ?, ?)") + .set(1, this.sourceName) + .set(2, this.sourceURL) .set(3, AliasSource.SourceType.WEB_SERVER.name()) .executeUpdate(false); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java index c875f4ca..f6786064 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java @@ -60,7 +60,7 @@ public boolean isRunning() @NotNull A arguments ) { - if (isRunning()) + if (this.isRunning()) throw new InstallerRunningException("Install is already running."); if (!this.tokenStore.isTokenAvailable()) throw new TokenNotAvailableException("Token is not available."); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java index a55004c3..68044a3e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java @@ -60,7 +60,7 @@ private static TextComponent getResultStatusComponent(@NotNull String[] componen */ public int getUpgradedCount() { - return progress.getUpgraded().size(); + return this.progress.getUpgraded().size(); } /** @@ -70,7 +70,7 @@ public int getUpgradedCount() */ public int getInstalledCount() { - return progress.getInstalled().size(); + return this.progress.getInstalled().size(); } /** @@ -80,7 +80,7 @@ public int getInstalledCount() */ public int getRemovedCount() { - return progress.getRemoved().size(); + return this.progress.getRemoved().size(); } /** @@ -90,7 +90,7 @@ public int getRemovedCount() */ public int getPendingCount() { - return progress.getPending().size(); + return this.progress.getPending().size(); } /** @@ -100,7 +100,7 @@ public int getPendingCount() */ public String[] getUpgraded() { - return progress.getUpgraded().toArray(new String[0]); + return this.progress.getUpgraded().toArray(new String[0]); } /** @@ -110,7 +110,7 @@ public String[] getUpgraded() */ public String[] getInstalled() { - return progress.getInstalled().toArray(new String[0]); + return this.progress.getInstalled().toArray(new String[0]); } /** @@ -120,7 +120,7 @@ public String[] getInstalled() */ public String[] getRemoved() { - return progress.getRemoved().toArray(new String[0]); + return this.progress.getRemoved().toArray(new String[0]); } /** @@ -130,7 +130,7 @@ public String[] getRemoved() */ public String[] getPending() { - return progress.getPending().toArray(new String[0]); + return this.progress.getPending().toArray(new String[0]); } /** @@ -142,13 +142,13 @@ public void printResultStatus(@NotNull Terminal terminal) { TextComponent component = Component.text("") .append(Component.text("アップグレード:") - .append(getResultStatusComponent(getUpgraded(), "アップグレードされたプラグイン"))) + .append(getResultStatusComponent(this.getUpgraded(), "アップグレードされたプラグイン"))) .append(Component.text("、インストール:") - .append(getResultStatusComponent(getInstalled(), "インストールされたプラグイン"))) + .append(getResultStatusComponent(this.getInstalled(), "インストールされたプラグイン"))) .append(Component.text("、削除:") - .append(getResultStatusComponent(getRemoved(), "削除されたプラグイン"))) + .append(getResultStatusComponent(this.getRemoved(), "削除されたプラグイン"))) .append(Component.text("、保留:") - .append(getResultStatusComponent(getPending(), "保留されたプラグイン"))); + .append(getResultStatusComponent(this.getPending(), "保留されたプラグイン"))); terminal.write(component); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java index dd25493d..79957978 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java @@ -40,7 +40,7 @@ public AutoRemoveArgument() */ public AutoRemoveArgument addExcludePlugin(@NotNull String pluginName) { - excludePlugins.add(pluginName); + this.excludePlugins.add(pluginName); return this; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java index 8bba8dbd..c0b961db 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java @@ -39,7 +39,7 @@ public CleanArgument() */ public CleanArgument addExcludeDataName(@NotNull String dataName) { - excludeDataNames.add(dataName); + this.excludeDataNames.add(dataName); return this; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index 502c8b89..fb000f7c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -66,16 +66,16 @@ public InstallResult execute(@NotNull InstallArgument argument) th TaskResult pluginDescriptionResult = this.submitter( InstallTasks.RESOLVING_QUERY, - new PluginResolveTask(this.daemon, progress, signalHandler) + new PluginResolveTask(this.daemon, this.progress, this.signalHandler) ) - .then(InstallTasks.DOWNLOADING, new DownloadTask(progress, signalHandler)) + .then(InstallTasks.DOWNLOADING, new DownloadTask(this.progress, this.signalHandler)) .bridgeArgument(result -> { if (result.getResolveResult() == null) throw new IllegalArgumentException("Plugin Resolving must be successful"); return new DownloadArgument(result.getResolveResult().getDownloadUrl()); }) - .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(progress, signalHandler)) + .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(this.progress, this.signalHandler)) .bridgeArgument(result -> new DescriptionLoadArgument(result.getPath())) .submitAll(new PluginResolveArgument(query)); @@ -136,13 +136,13 @@ public InstallResult execute(@NotNull InstallArgument argument) th TaskResult installResult = this.submitter( InstallTasks.COLLECTING_DEPENDENCIES, - new DependsCollectTask(this.daemon, progress, signalHandler) + new DependsCollectTask(this.daemon, this.progress, this.signalHandler) ) - .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(progress, signalHandler)) + .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(this.progress, this.signalHandler)) .bridgeArgument(result -> new DependsComputeOrderArgument(result.getCollectedPlugins())) .then( InstallTasks.INSTALLING_PLUGINS, - new PluginsInstallTask(this.daemon, progress, signalHandler) + new PluginsInstallTask(this.daemon, this.progress, this.signalHandler) ) .bridgeArgument(result -> new PluginsInstallArgument( pluginFilePath, pluginDescription, query, result.getOrder() @@ -166,7 +166,7 @@ private void removeOldPlugin(Plugin plugin) this.daemon.getPluginLoader().unloadPlugin(plugin); // TODO: Replace with uninstall. - if (!safeDelete(oldPluginFile)) - Runner.runLater(() -> safeDelete(oldPluginFile), 10L); + if (!this.safeDelete(oldPluginFile)) + Runner.runLater(() -> this.safeDelete(oldPluginFile), 10L); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java index fbe83302..a19b4146 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java @@ -76,7 +76,7 @@ public InstallResult execute(@NotNull RegisterArgument argument) { // region Check if token is provided in argument if (argument.getToken() != null) // Token is already prepared, so register it as is. - if (registerToken(argument.getToken())) + if (this.registerToken(argument.getToken())) return this.success(); else return this.error(RegisterErrorCause.IO_EXCEPTION_OCCURRED); @@ -103,7 +103,7 @@ private InstallResult generateToken() // region Request verification code this.progress.setCurrentTask(RegisterTasks.REQUESTING_USER_VERIFICATION_CODE); this.postSignal(new VerificationCodeRequestingSignal()); - UserVerificationCodeResponse userVerifyCodeResponse = requestVerificationCode(); + UserVerificationCodeResponse userVerifyCodeResponse = this.requestVerificationCode(); if (userVerifyCodeResponse == null) return this.error(RegisterErrorCause.VERIFICATION_CODE_REQUEST_FAILED); @@ -117,7 +117,7 @@ private InstallResult generateToken() // region Polling user verification this.progress.setCurrentTask(RegisterTasks.POLLING_USER_VERIFICATION); - VerificationSubmitPollingResponse pollingResponse = pollVerifyCodeSubmit(userVerifyCodeResponse); + VerificationSubmitPollingResponse pollingResponse = this.pollVerifyCodeSubmit(userVerifyCodeResponse); if (pollingResponse == null) return this.error(RegisterErrorCause.VERIFICATION_FAILED); @@ -129,7 +129,7 @@ private InstallResult generateToken() this.postSignal(new UserVerificationSuccessSignal(accessToken, tokenType, scope)); - if (registerToken(accessToken)) + if (this.registerToken(accessToken)) return this.success(); else return this.error(RegisterErrorCause.IO_EXCEPTION_OCCURRED); @@ -149,7 +149,7 @@ private UserVerificationCodeResponse requestVerificationCode() { if (!response.isSuccessful()) { - String errorMessage = getErrorMessage(response); + String errorMessage = this.getErrorMessage(response); int errorCode = response.getStatusCode(); this.postSignal(new VerificationCodeRequestFailedSignal( errorCode, @@ -159,7 +159,7 @@ private UserVerificationCodeResponse requestVerificationCode() return null; } - return toUserVerificationCodeResponse(response); + return this.toUserVerificationCodeResponse(response); } catch (IOException e) { @@ -255,11 +255,11 @@ private VerificationSubmitPollingResponse pollVerifyCodeSubmit(UserVerificationC return null; } - randomSleep(intervalMillis); + this.randomSleep(intervalMillis); continue; } - VerificationSubmitPollingResponse pollingResponse = toVerificationSubmitPollingResponse(response); + VerificationSubmitPollingResponse pollingResponse = this.toVerificationSubmitPollingResponse(response); if (pollingResponse != null) return pollingResponse; } @@ -269,7 +269,7 @@ private VerificationSubmitPollingResponse pollVerifyCodeSubmit(UserVerificationC return null; } - randomSleep(intervalMillis); + this.randomSleep(intervalMillis); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index 81ee3a05..1bae3739 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -55,8 +55,8 @@ public DependsCollectStatus(InstallProgress progress) */ public void addDependency(@NotNull String dependencyName) { - if (!enumeratedDependencies.containsKey(dependencyName)) - enumeratedDependencies.put(dependencyName, null); + if (!this.enumeratedDependencies.containsKey(dependencyName)) + this.enumeratedDependencies.put(dependencyName, null); } /** @@ -67,7 +67,7 @@ public void addDependency(@NotNull String dependencyName) */ public boolean isCollected(@NotNull String dependencyName) { - return enumeratedDependencies.containsKey(dependencyName); + return this.enumeratedDependencies.containsKey(dependencyName); } /** @@ -77,7 +77,7 @@ public boolean isCollected(@NotNull String dependencyName) */ public boolean isErrors() { - return enumeratedDependencies.containsValue(null); + return this.enumeratedDependencies.containsValue(null); } /** @@ -88,8 +88,8 @@ public boolean isErrors() */ public void onCollect(@NotNull String dependencyName, DependencyElement dependencyElement) { - if (enumeratedDependencies.containsKey(dependencyName)) - enumeratedDependencies.put(dependencyName, dependencyElement); + if (this.enumeratedDependencies.containsKey(dependencyName)) + this.enumeratedDependencies.put(dependencyName, dependencyElement); } /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 32147b95..f51752c8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -107,7 +107,7 @@ public DependsCollectTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress dependsDescriptions = downloadResultsToPluginDescriptionFiles(downloadResults); + HashMap dependsDescriptions = this.downloadResultsToPluginDescriptionFiles(downloadResults); // Remove failed dependencies from load description results dependsDescriptions.entrySet().removeIf(entry -> entry.getValue() == null); @@ -233,7 +233,7 @@ private HashMap downloadDepends(@NotNull HashMap downloadResults = resolvedPlugins.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> { SuccessResult successResult = (SuccessResult) entry.getValue(); - return passDownloader(successResult.getDownloadUrl()); // Actual downloading + return this.passDownloader(successResult.getDownloadUrl()); // Actual downloading })); downloadResults.entrySet().stream() diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java index f457b3b0..dac4daaf 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java @@ -26,6 +26,6 @@ public DependencyNameMismatchSignal(String actualDependencyName, String excepted */ public String getActualDependencyName() { - return getFailedDependency(); + return this.getFailedDependency(); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java index 5b7f0015..62213e5d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java @@ -53,7 +53,7 @@ private void onDownload(DownloadProgress downloadProgress, String url) { Path downloadPath = arguments.getPath(); if (downloadPath == null) - downloadPath = progress.getInstallTempDir().resolve(this.randomDownloadID + ".kpmcache"); + downloadPath = this.progress.getInstallTempDir().resolve(this.randomDownloadID + ".kpmcache"); DownloadStartingSignal downloadingSignal = new DownloadStartingSignal( this.randomDownloadID, @@ -69,7 +69,7 @@ private void onDownload(DownloadProgress downloadProgress, String url) try { - long size = Requests.downloadFile(RequestMethod.GET, url, path, progress -> onDownload(progress, url)); + long size = Requests.downloadFile(RequestMethod.GET, url, path, progress -> this.onDownload(progress, url)); this.postSignal(new DownloadSucceedSignal(this.randomDownloadID, path, size)); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java index 11935ef8..fcc43cb7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java @@ -216,8 +216,8 @@ private boolean moveFile(@NotNull Path source, @NotNull Path target, boolean ove } catch (FileAlreadyExistsException e) { - String sourceHash = generateSHA1(source); - String targetHash = generateSHA1(target); + String sourceHash = this.generateSHA1(source); + String targetHash = this.generateSHA1(target); if (sourceHash == null || targetHash == null) return false; @@ -225,7 +225,7 @@ private boolean moveFile(@NotNull Path source, @NotNull Path target, boolean ove if (sourceHash.equals(targetHash)) return true; else - return moveFile(source, target, true); + return this.moveFile(source, target, true); } } @@ -239,7 +239,7 @@ private PluginsInstallResult movePlugin(@NotNull Path source, @NotNull Path targ try { - if (!moveFile(source, target, false)) + if (!this.moveFile(source, target, false)) return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.RELOCATE_FAILED); else return null; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java index 6a110ca6..4244fd45 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java @@ -81,7 +81,7 @@ else if (queryResolveResult instanceof MultiResult) this.taskState = PluginResolveState.MULTI_RESOLVING; MultiResult multiResult = (MultiResult) queryResolveResult; - ResolveResult actualResolveResult = resolveMultipleResults(arguments.getQuery(), multiResult); + ResolveResult actualResolveResult = this.resolveMultipleResults(arguments.getQuery(), multiResult); if (actualResolveResult == null) return new PluginResolveResult(false, this.taskState, diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java index de064d71..d781ad00 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java @@ -107,7 +107,7 @@ public UnInstallTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress p this.daemon.getPluginMetaManager().preparePluginModify(plugin.getName()); PluginDescriptionFile description = plugin.getDescription(); - UnInstallErrorCause errorCause = uninstallOnePlugin(plugin); + UnInstallErrorCause errorCause = this.uninstallOnePlugin(plugin); if (errorCause == UnInstallErrorCause.INTERNAL_UNINSTALL_OK) uninstalledPlugins.add(description); @@ -137,7 +137,7 @@ public UnInstallTask(@NotNull KPMDaemon daemon, @NotNull InstallProgress p boolean success = errors.isEmpty(); - return new UnInstallResult(success, taskState, success ? null: UnInstallErrorCause.SOME_UNINSTALL_FAILED, + return new UnInstallResult(success, this.taskState, success ? null: UnInstallErrorCause.SOME_UNINSTALL_FAILED, uninstalledPlugins, errors ); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/CommandsPatcher.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/CommandsPatcher.java index 38a0efef..1eac570b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/CommandsPatcher.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/CommandsPatcher.java @@ -146,7 +146,7 @@ private void initReflections() // Get commandMap field try { - fCommandMap = ReflectionUtils.getAccessibleField(cCraftServer, true, "commandMap"); + this.fCommandMap = ReflectionUtils.getAccessibleField(cCraftServer, true, "commandMap"); } catch (NoSuchFieldException e) { @@ -217,7 +217,7 @@ public void syncCommandsCraftBukkit() public void unWrapCommand(String command) { - iBrigadierCommandDispatcher.getRoot().removeCommand(command); + this.iBrigadierCommandDispatcher.getRoot().removeCommand(command); } /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java index ced86f05..cf244c79 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java @@ -128,7 +128,7 @@ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operato */ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operator, @Nullable String resolveQuery, boolean isDependency) { - onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis(), isDependency); + this.onInstalled(plugin, operator, resolveQuery, System.currentTimeMillis(), isDependency); } /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java index c0bde58e..a83dd1f1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java @@ -45,7 +45,7 @@ public PluginMetaProvider(@NotNull Plugin plugin, @NotNull Path databasePath) */ public void close() { - db.close(); + this.db.close(); } /** @@ -56,7 +56,7 @@ public void close() */ public List getDependOn(@NotNull String pluginName) { - return getDependDataFromTable("depend", pluginName, "dependency", + return this.getDependDataFromTable("depend", pluginName, "dependency", DependType.HARD_DEPEND, false ); } @@ -69,7 +69,7 @@ public List getDependOn(@NotNull String pluginName) */ public List getSoftDependOn(@NotNull String pluginName) { - return getDependDataFromTable("soft_depend", pluginName, "soft_dependency", + return this.getDependDataFromTable("soft_depend", pluginName, "soft_dependency", DependType.SOFT_DEPEND, false ); } @@ -83,7 +83,7 @@ public List getSoftDependOn(@NotNull String pluginName) */ public List getLoadBefore(@NotNull String pluginName) { - return getDependDataFromTable("load_before", pluginName, "load_before", + return this.getDependDataFromTable("load_before", pluginName, "load_before", DependType.LOAD_BEFORE, false ); } @@ -96,7 +96,7 @@ public List getLoadBefore(@NotNull String pluginName) */ public List getDependedBy(@NotNull String pluginName) { - return getDependDataFromTable("depend", pluginName, "dependency", + return this.getDependDataFromTable("depend", pluginName, "dependency", DependType.HARD_DEPEND, true ); } @@ -109,7 +109,7 @@ public List getDependedBy(@NotNull String pluginName) */ public List getSoftDependedBy(@NotNull String pluginName) { - return getDependDataFromTable("soft_depend", pluginName, "soft_dependency", + return this.getDependDataFromTable("soft_depend", pluginName, "soft_dependency", DependType.SOFT_DEPEND, true ); } @@ -123,7 +123,7 @@ public List getSoftDependedBy(@NotNull String pluginName) */ public List getLoadBeforeBy(@NotNull String pluginName) { - return getDependDataFromTable("load_before", pluginName, "load_before", + return this.getDependDataFromTable("load_before", pluginName, "load_before", DependType.LOAD_BEFORE, true ); } @@ -637,7 +637,7 @@ private int isUnusedRecursive(Connection con, @NotNull String pluginName, int de statement.setString(1, pluginName); ResultSet resultSet = statement.executeQuery(); - if (isNotDependencyInternal(con, checkIsDependency, pluginName)) + if (this.isNotDependencyInternal(con, checkIsDependency, pluginName)) return 0; while (resultSet.next()) @@ -645,7 +645,7 @@ private int isUnusedRecursive(Connection con, @NotNull String pluginName, int de String name = resultSet.getString("name"); String parent = resultSet.getString("parent"); - if (isNotDependencyInternal(con, checkIsDependency, name)) + if (this.isNotDependencyInternal(con, checkIsDependency, name)) return 1; int checkUnused = this.isUnusedRecursive(con, name, depth + 1); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java index 8d2b3434..03ec3812 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java @@ -42,14 +42,14 @@ public void addResolver(BaseResolver resolver, String... names) if (name.equalsIgnoreCase("http") || name.equalsIgnoreCase("https")) throw new IllegalArgumentException("HTTP and HTTPS are reserved names."); - List resolverList = resolvers.get(name.toLowerCase()); + List resolverList = this.resolvers.get(name.toLowerCase()); if (resolverList == null) - resolvers.put(name.toLowerCase(), new ArrayList<>(Collections.singletonList(resolver))); + this.resolvers.put(name.toLowerCase(), new ArrayList<>(Collections.singletonList(resolver))); else resolverList.add(resolver); - allResolvers.add(resolver); + this.allResolvers.add(resolver); } } @@ -61,7 +61,7 @@ public void addResolver(BaseResolver resolver, String... names) */ public void addOnNotFoundResolver(BaseResolver resolver) { - onNotFoundResolvers.add(resolver); + this.onNotFoundResolvers.add(resolver); } /** @@ -74,12 +74,12 @@ public ResolveResult resolve(String query) QueryContext context = QueryContext.fromString(query); if (context.getResolverName() == null) - return actuallyResolve(allResolvers, context); + return this.actuallyResolve(this.allResolvers, context); - if (!resolvers.containsKey(context.getResolverName().toLowerCase())) + if (!this.resolvers.containsKey(context.getResolverName().toLowerCase())) return new ErrorResult(null, ErrorResult.ErrorCause.RESOLVER_MISMATCH, ResolveResult.Source.UNKNOWN); - return actuallyResolve(resolvers.get(context.getResolverName().toLowerCase()), context); + return this.actuallyResolve(this.resolvers.get(context.getResolverName().toLowerCase()), context); } private ResolveResult actuallyResolve(List resolvers, QueryContext queryContext) @@ -90,14 +90,14 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext if (resolverName != null) url = toURL(queryContext.getQuery()); - ResolveResult result = resolves(resolvers, queryContext, url); + ResolveResult result = this.resolves(resolvers, queryContext, url); if (result instanceof ErrorResult) { ErrorResult error = (ErrorResult) result; if (error.getCause() != ErrorResult.ErrorCause.VERSION_MISMATCH) - result = resolves(onNotFoundResolvers, queryContext, url); + result = this.resolves(this.onNotFoundResolvers, queryContext, url); } return result; @@ -115,7 +115,7 @@ private ResolveResult resolves(List resolvers, QueryContext queryC finishedResolvers.add(resolver); - ResolveResult result = actuallyResolve(resolver, queryContext, url); + ResolveResult result = this.actuallyResolve(resolver, queryContext, url); if (result == null || result instanceof PipeResult) continue; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java index 9075e135..6949de9c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java @@ -20,10 +20,10 @@ public ResolveResult resolve(QueryContext query) { ResolveResult result = new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); - for (String str : gitHubName) + for (String str : this.gitHubName) { query.setQuery("https://github.com/" + str + "/" + query.getQuery()); - result = gitHubURLResolver.resolve(query); + result = this.gitHubURLResolver.resolve(query); if (result instanceof ErrorResult) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java index 3eda030b..f29699c8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java @@ -43,9 +43,9 @@ public ResolveResult resolve(QueryContext query) Matcher matcher; if (bukkitFlag) - matcher = urlMatcher(BUKKIT_PATTERN, query.getQuery()); + matcher = this.urlMatcher(BUKKIT_PATTERN, query.getQuery()); else - matcher = urlMatcher(CURSE_PATTERN, query.getQuery()); + matcher = this.urlMatcher(CURSE_PATTERN, query.getQuery()); if (matcher == null) return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, errorSource); @@ -72,7 +72,7 @@ public ResolveResult resolve(QueryContext query) .build()); if (response.getStatus() != HTTPResponse.RequestStatus.OK) - return processErrorResponse(response, errorSource); + return this.processErrorResponse(response, errorSource); JsonElement json = response.getAsJson(); if (!json.isJsonArray()) @@ -97,7 +97,7 @@ public ResolveResult resolve(QueryContext query) if (projectId == -1) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, errorSource); - return processFiles(slug, name, projectId, version, errorSource); + return this.processFiles(slug, name, projectId, version, errorSource); } private ResolveResult processFiles(String slug, String name, long projectId, String version, ResolveResult.Source source) @@ -106,7 +106,7 @@ private ResolveResult processFiles(String slug, String name, long projectId, Str .url("https://servermods.forgesvc.net/servermods/files?projectIds=" + projectId) .build()); - ErrorResult mayError = processErrorResponse(response, source); + ErrorResult mayError = this.processErrorResponse(response, source); if (mayError != null) return mayError; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java index 59e9e924..a6b6fa2f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java @@ -62,20 +62,20 @@ public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downl @Override public String getTitle() { - return repoName + " - " + releaseName; + return this.repoName + " - " + this.releaseName; } @Nonnull @Override public String getUrl() { - return "https://github.com/" + owner + "/" + repoName; + return "https://github.com/" + this.owner + "/" + this.repoName; } @Nonnull @Override public String getDescription() { - return releaseBody; + return this.releaseBody; } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 57f497f2..0c87bcec 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -32,7 +32,7 @@ public class GitHubURLResolver implements URLResolver @Override public ResolveResult resolve(QueryContext query) { - Matcher matcher = urlMatcher(GITHUB_REPO_PATTERN, query.getQuery()); + Matcher matcher = this.urlMatcher(GITHUB_REPO_PATTERN, query.getQuery()); if (matcher == null) return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); @@ -72,13 +72,13 @@ else if (tagGroup != null && !tagGroup.isEmpty()) if (repository == null) return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.GITHUB); - return processGitHubAPI(owner, repositoryName, repository, tag, query.getVersion()); + return this.processGitHubAPI(owner, repositoryName, repository, tag, query.getVersion()); } @Override public ResolveResult autoPickOnePlugin(MultiResult multiResult) { - return autoPickFirst(multiResult, ResolveResult.Source.GITHUB); + return this.autoPickFirst(multiResult, ResolveResult.Source.GITHUB); } private ResolveResult processGitHubAPI(String owner, String repositoryName, String repository, String tag, @Nullable String version) @@ -93,7 +93,7 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri .url(apiURL) .build()); - ErrorResult mayError = processErrorResponse(response, ResolveResult.Source.GITHUB); + ErrorResult mayError = this.processErrorResponse(response, ResolveResult.Source.GITHUB); if (mayError != null) return mayError; @@ -102,7 +102,7 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri { JsonObject jsonObject = response.getAsJson().getAsJsonObject(); - return buildResultSingle(owner, repositoryName, jsonObject, version); + return this.buildResultSingle(owner, repositoryName, jsonObject, version); } JsonArray jsonArray = response.getAsJson().getAsJsonArray(); @@ -112,7 +112,7 @@ private ResolveResult processGitHubAPI(String owner, String repositoryName, Stri boolean isNoAssets = false; for (JsonElement jsonElement : jsonArray) { - ResolveResult result = buildResultSingle(owner, repositoryName, jsonElement.getAsJsonObject(), version); + ResolveResult result = this.buildResultSingle(owner, repositoryName, jsonElement.getAsJsonObject(), version); if (result instanceof ErrorResult) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java index 3e785416..85f240a7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java @@ -27,7 +27,7 @@ public class SpigotMCResolver implements URLResolver @Override public ResolveResult resolve(QueryContext query) { - Matcher matcher = urlMatcher(PATTERN, query.getQuery()); + Matcher matcher = this.urlMatcher(PATTERN, query.getQuery()); if (matcher == null) return new ErrorResult(this, ErrorResult.ErrorCause.INVALID_QUERY, ResolveResult.Source.SPIGOT_MC); @@ -55,12 +55,12 @@ public ResolveResult resolve(QueryContext query) .url(spigotAPIUrl) .build()); - ErrorResult mayError = processErrorResponse(data, ResolveResult.Source.SPIGOT_MC); + ErrorResult mayError = this.processErrorResponse(data, ResolveResult.Source.SPIGOT_MC); if (mayError != null) return mayError; - return buildResult(data.getAsJson().getAsJsonObject(), version); + return this.buildResult(data.getAsJson().getAsJsonObject(), version); } private ResolveResult buildResult(JsonObject jsonObject, @Nullable String version) @@ -71,7 +71,7 @@ private ResolveResult buildResult(JsonObject jsonObject, @Nullable String versio ResolveResult.Source.SPIGOT_MC ); - String description = b64Decode(jsonObject.get("description").getAsString()); + String description = this.b64Decode(jsonObject.get("description").getAsString()); String name = jsonObject.get("name").getAsString(); List testedVersions = StreamSupport.stream(jsonObject.get("testedVersions").getAsJsonArray().spliterator(), false) .map(JsonElement::getAsString) @@ -130,7 +130,7 @@ private String b64Decode(String str) @Override public ResolveResult autoPickOnePlugin(MultiResult multiResult) { - return autoPickFirst(multiResult, ResolveResult.Source.SPIGOT_MC); + return this.autoPickFirst(multiResult, ResolveResult.Source.SPIGOT_MC); } @Override diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java index fd5c00f9..d4bfd6d8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java @@ -47,7 +47,7 @@ default ResolveResult autoPickFirst(MultiResult multiResult, ResolveResult.Sourc ResolveResult result = results[0]; if (result instanceof MultiResult) - return autoPickFirst((MultiResult) result, source); + return this.autoPickFirst((MultiResult) result, source); return result; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java index 5bfbbbed..d1594a69 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java @@ -35,10 +35,10 @@ default boolean isValidResolver(QueryContext query) { URL url = new URL(query.getQuery()); - if (getHosts().length == 0) + if (this.getHosts().length == 0) return true; - for (String host : getHosts()) + for (String host : this.getHosts()) if (url.getHost().equalsIgnoreCase(host)) return true; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java index a1b18b74..e8b3ced4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java @@ -21,7 +21,7 @@ public class SignalHandleManager public SignalHandleManager() { - handlerLists = new ArrayList<>(); + this.handlerLists = new ArrayList<>(); } @SuppressWarnings({"rawtypes", "unchecked"}) @@ -53,7 +53,7 @@ public void register(Object object) { List> handleTargetClasses = enumerateHandlers(object); - for (SignalHandlerList handlerList : handlerLists) + for (SignalHandlerList handlerList : this.handlerLists) { handlerList.bakeAll(object); handleTargetClasses.removeIf(handlerList::isSignalType); @@ -62,7 +62,7 @@ public void register(Object object) for (Class handleTargetClass : handleTargetClasses) { SignalHandlerList handlerList = new SignalHandlerList<>(handleTargetClass); - handlerLists.add(handlerList); + this.handlerLists.add(handlerList); handlerList.bakeAll(object); } } @@ -75,7 +75,7 @@ public void register(Object object) */ public void handleSignal(@NotNull InstallProgress installProgress, Signal signal) { - for (SignalHandlerList handlerList : handlerLists) + for (SignalHandlerList handlerList : this.handlerLists) invokeHandler(installProgress, handlerList, signal); } @@ -87,7 +87,7 @@ public void handleSignal(@NotNull InstallProgress installProgress, Signal public SignalHandleManager copy() { SignalHandleManager manager = new SignalHandleManager(); - manager.handlerLists.addAll(handlerLists); + manager.handlerLists.addAll(this.handlerLists); return manager; } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java index 2e8b30b1..01f713c4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java @@ -28,36 +28,36 @@ class SignalHandlerList private boolean isBaked(Method method) { - return handlers.stream().parallel() + return this.handlers.stream().parallel() .map(Pair::getRight) .anyMatch(method::equals); } public void bakeAll(Object object) { - synchronized (handlers) + synchronized (this.handlers) { Arrays.stream(object.getClass().getMethods()).parallel() .filter(method -> method.isAnnotationPresent(SignalHandler.class)) .filter(method -> !this.isBaked(method)) .filter(method -> method.getParameterCount() == 1) - .filter(method -> signalType.isAssignableFrom(method.getParameterTypes()[0])) + .filter(method -> this.signalType.isAssignableFrom(method.getParameterTypes()[0])) .forEach(method -> { method.setAccessible(true); if (Modifier.isStatic(method.getModifiers())) - handlers.add(new Pair<>(null, method)); + this.handlers.add(new Pair<>(null, method)); else - handlers.add(new Pair<>(object, method)); + this.handlers.add(new Pair<>(object, method)); }); } } void onSignal(InstallProgress installProgress, T signal) { - synchronized (handlers) + synchronized (this.handlers) { - handlers.forEach(pair -> { + this.handlers.forEach(pair -> { try { pair.getRight().invoke(pair.getLeft(), signal); @@ -73,6 +73,6 @@ void onSignal(InstallProgress installProgress, T signal) boolean isSignalType(Class type) { - return signalType.isAssignableFrom(type); + return this.signalType.isAssignableFrom(type); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java index c279fb72..5dac71ba 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java @@ -538,7 +538,7 @@ public static String getServerVersion() */ public String getPath() { - return path; + return this.path; } /** @@ -557,7 +557,7 @@ public Class getClass(String className) throws ClassNotFoundException @Override public String toString() { - return path; + return this.path; } } @@ -741,7 +741,7 @@ public static boolean compare(Class[] primary, Class[] secondary) */ public Class getPrimitive() { - return primitive; + return this.primitive; } /** @@ -751,7 +751,7 @@ public Class getPrimitive() */ public Class getReference() { - return reference; + return this.reference; } } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java index 056d6ede..cceac57a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java @@ -66,7 +66,7 @@ public String getString(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -79,7 +79,7 @@ public int getInt(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -92,7 +92,7 @@ public long getLong(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -105,7 +105,7 @@ public float getFloat(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -118,7 +118,7 @@ public double getDouble(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -131,7 +131,7 @@ public boolean getBoolean(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -144,7 +144,7 @@ public Date getDate(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -157,7 +157,7 @@ public Time getTime(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -170,7 +170,7 @@ public Timestamp getTimestamp(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } @@ -183,7 +183,7 @@ public Object getObject(String columnLabel) } catch (SQLException e) { - handleException(); + this.handleException(); throw new IllegalStateException(e); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java index 5cdcecfc..12b38968 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java @@ -172,7 +172,7 @@ private boolean checkPrepareCondition() */ public Transaction set(int index, @Nullable String value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -196,7 +196,7 @@ public Transaction set(int index, @Nullable String value) */ public Transaction set(int index, int value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -219,7 +219,7 @@ public Transaction set(int index, int value) */ public Transaction set(int index, boolean value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -242,7 +242,7 @@ public Transaction set(int index, boolean value) */ public Transaction set(int index, long value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -265,7 +265,7 @@ public Transaction set(int index, long value) */ public Transaction set(int index, double value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -288,7 +288,7 @@ public Transaction set(int index, double value) */ public Transaction set(int index, float value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -311,7 +311,7 @@ public Transaction set(int index, float value) */ public Transaction set(int index, byte value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -334,7 +334,7 @@ public Transaction set(int index, byte value) */ public Transaction set(int index, short value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -357,7 +357,7 @@ public Transaction set(int index, short value) */ public Transaction set(int index, byte[] value) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -380,7 +380,7 @@ public Transaction set(int index, byte[] value) */ public Transaction setNull(int index, int type) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -402,7 +402,7 @@ public Transaction setNull(int index, int type) */ public int executeUpdate(boolean autoFinish) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -454,7 +454,7 @@ public int executeUpdate(boolean autoFinish) */ public int executeUpdate() { - return executeUpdate(true); + return this.executeUpdate(true); } /** @@ -464,7 +464,7 @@ public int executeUpdate() */ public QueryResult executeQuery() { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -599,7 +599,7 @@ public void abortManually() */ public boolean isExists(boolean closeConnection) { - if (!checkPrepareCondition()) + if (!this.checkPrepareCondition()) throw new IllegalStateException("This TransactionHelper is not prepared."); try @@ -637,7 +637,7 @@ public boolean isExists(boolean closeConnection) */ public boolean isExists() { - return isExists(true); + return this.isExists(true); } public void close() throws Exception @@ -774,7 +774,7 @@ public ArrayList mapToList(Function resultMapper, long max) */ public ArrayList mapToList(Function resultMapper) { - return mapToList(resultMapper, -1); + return this.mapToList(resultMapper, -1); } /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java index 75aa2c5f..106a4114 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java @@ -74,10 +74,10 @@ public static HTTPResponse error(@NotNull RequestContext request, @NotNull Reque */ public String getAsString() { - if (inputStream == null) + if (this.inputStream == null) return null; - else if (bodyCache != null) - return bodyCache; + else if (this.bodyCache != null) + return this.bodyCache; StringBuilder sb = new StringBuilder(); @@ -85,7 +85,7 @@ else if (bodyCache != null) int len; try { - while ((len = inputStream.read(buffer)) != -1) + while ((len = this.inputStream.read(buffer)) != -1) sb.append(new String(buffer, 0, len)); } catch (Exception e) @@ -93,8 +93,8 @@ else if (bodyCache != null) e.printStackTrace(); } - bodyCache = sb.toString(); - return bodyCache; + this.bodyCache = sb.toString(); + return this.bodyCache; } /** @@ -104,10 +104,10 @@ else if (bodyCache != null) */ public JsonElement getAsJson() { - if (inputStream == null) + if (this.inputStream == null) return null; - String json = getAsString(); + String json = this.getAsString(); return new Gson().fromJson(json, JsonElement.class); } @@ -120,10 +120,10 @@ public JsonElement getAsJson() */ public T getAsObject(Class clazz) { - if (inputStream == null) + if (this.inputStream == null) return null; - String json = getAsString(); + String json = this.getAsString(); return new Gson().fromJson(json, clazz); } @@ -135,7 +135,7 @@ public T getAsObject(Class clazz) @Override public void close() throws IOException { - if (inputStream != null) + if (this.inputStream != null) this.inputStream.close(); } @@ -149,7 +149,7 @@ public void close() throws IOException @Nullable public String getHeader(@NotNull String header) { - return headers.getOrDefault(header.toLowerCase(), headers.get(header)); + return this.headers.getOrDefault(header.toLowerCase(), this.headers.get(header)); } /** @@ -159,7 +159,7 @@ public String getHeader(@NotNull String header) */ public boolean isSuccessful() { - return statusCode >= 200 && statusCode < 300; + return this.statusCode >= 200 && this.statusCode < 300; } /** @@ -169,7 +169,7 @@ public boolean isSuccessful() */ public boolean isRedirect() { - return statusCode >= 300 && statusCode < 400; + return this.statusCode >= 300 && this.statusCode < 400; } /** @@ -179,7 +179,7 @@ public boolean isRedirect() */ public boolean isClientError() { - return statusCode >= 400 && statusCode < 500; + return this.statusCode >= 400 && this.statusCode < 500; } /** @@ -189,7 +189,7 @@ public boolean isClientError() */ public boolean isServerError() { - return statusCode >= 500 && statusCode < 600; + return this.statusCode >= 500 && this.statusCode < 600; } /** @@ -201,7 +201,7 @@ public boolean isServerError() */ public boolean isError() { - return isClientError() || isServerError(); + return this.isClientError() || this.isServerError(); } /** @@ -211,7 +211,7 @@ public boolean isError() */ public boolean isOK() { - return statusCode == 200; + return this.statusCode == 200; } /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java index 15fa603d..251308d1 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java @@ -72,9 +72,9 @@ private HashMap setupSources() @Override public void onEnable() { - saveDefaultConfig(); + this.saveDefaultConfig(); plugin = this; - this.pluginConfig = getConfig(); + this.pluginConfig = this.getConfig(); this.commandManager = new CommandManager(this, "kunpluginmanager", "TeamKUNPluginManager", "kpm"); @@ -93,7 +93,7 @@ public void onEnable() this.headInstallers = new HeadInstallers(this.daemon); - registerCommands(commandManager); + this.registerCommands(this.commandManager); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java index 468640e4..b3d51030 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java @@ -20,11 +20,11 @@ public class CommandDepTreeDebug extends SubCommandWith public CommandDepTreeDebug(PluginMetaManager manager) { - COMMANDS = new HashMap<>(); + this.COMMANDS = new HashMap<>(); - COMMANDS.put("markAsDependency", new CommandMarkAsDependency(manager.getProvider())); - COMMANDS.put("relation", new CommandRelation(manager.getProvider())); - COMMANDS.put("purge", new CommandPurge(manager.getProvider())); + this.COMMANDS.put("markAsDependency", new CommandMarkAsDependency(manager.getProvider())); + this.COMMANDS.put("relation", new CommandRelation(manager.getProvider())); + this.COMMANDS.put("purge", new CommandPurge(manager.getProvider())); } @Override @@ -36,7 +36,7 @@ protected String getName() @Override protected Map getSubCommands(@NotNull CommandSender sender) { - return COMMANDS; + return this.COMMANDS; } @Override diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java index 08318b9d..6a1fabc7 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java @@ -247,8 +247,8 @@ public static SignalHandleManager toManager(Terminal terminal) public void handleAll(@NotNull InstallProgress installProgress, Signal signal) { if (!(signal instanceof DownloadProgressSignal)) - printSignal(signal, terminal); + printSignal(signal, this.terminal); - handleInputSignals(signal, terminal); + handleInputSignals(signal, this.terminal); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java index 9f918f24..811b89d5 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java @@ -27,7 +27,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; String pluginName = args[0]; - if (!provider.isPluginMetaExists(pluginName)) + if (!this.provider.isPluginMetaExists(pluginName)) { terminal.error("Cannot find plugin meta of " + pluginName); return; @@ -36,7 +36,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (args.length < 2) { - boolean isDependency = provider.getPluginMeta(pluginName, false, false).isDependency(); + boolean isDependency = this.provider.getPluginMeta(pluginName, false, false).isDependency(); terminal.success("Plugin " + pluginName + " is " + (isDependency ? "dependency": "not dependency")); return; @@ -44,7 +44,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, boolean isDependency = Boolean.parseBoolean(args[1]); - provider.setDependencyFlag(pluginName, isDependency); + this.provider.setDependencyFlag(pluginName, isDependency); terminal.success("Marked " + pluginName + " as " + (isDependency ? "dependency": "not dependency")); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java index df472a0f..7701f522 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java @@ -32,21 +32,21 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, { Arrays.stream(Bukkit.getPluginManager().getPlugins()) .forEach(plugin -> { - provider.deleteFromDependencyTree(pluginName); - provider.removePluginMeta(pluginName); + this.provider.deleteFromDependencyTree(pluginName); + this.provider.removePluginMeta(pluginName); terminal.success("Purged " + pluginName); }); } - if (!provider.isPluginMetaExists(pluginName)) + if (!this.provider.isPluginMetaExists(pluginName)) { terminal.error("Cannot find plugin meta of " + pluginName); return; } - provider.deleteFromDependencyTree(pluginName); - provider.removePluginMeta(pluginName); + this.provider.deleteFromDependencyTree(pluginName); + this.provider.removePluginMeta(pluginName); terminal.success("Purged " + pluginName); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java index 01e224d6..2dc3e147 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java @@ -32,7 +32,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; String pluginName = args[0]; - if (!provider.isPluginMetaExists(pluginName)) + if (!this.provider.isPluginMetaExists(pluginName)) { terminal.error("Cannot find plugin meta of " + pluginName); return; @@ -40,7 +40,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, if (args.length < 2) { - List dependencies = provider.getPluginMeta(pluginName, false, false).getDependsOn(); + List dependencies = this.provider.getPluginMeta(pluginName, false, false).getDependsOn(); terminal.success("Plugin " + pluginName + " depends on " + dependencies.stream() .map(DependencyNode::getDependsOn) @@ -56,7 +56,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, return; } - PluginMeta meta = provider.getPluginMeta(pluginName, true, false); + PluginMeta meta = this.provider.getPluginMeta(pluginName, true, false); if (args.length < 3) { List dependencies = meta.getDependsOn(); @@ -70,7 +70,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, } String targetPluginName = args[2]; - if (!provider.isPluginMetaExists(targetPluginName)) + if (!this.provider.isPluginMetaExists(targetPluginName)) { terminal.error("Cannot find plugin meta of " + targetPluginName); return; @@ -89,19 +89,19 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, meta.getDependsOn().add(new DependencyNode(pluginName, targetPluginName, type.get())); terminal.success("Added dependency " + targetPluginName + " to " + pluginName + " with type " + type.get()); - provider.savePluginMeta(meta); + this.provider.savePluginMeta(meta); } else { assert node != null; terminal.success("Removed dependency " + targetPluginName + " from " + pluginName + " with type " + node.getDependType()); - provider.savePluginMeta(meta); + this.provider.savePluginMeta(meta); } - provider.deleteFromDependencyTree(pluginName); - provider.deleteFromDependencyTree(targetPluginName); - provider.buildDependencyTree(pluginName); + this.provider.deleteFromDependencyTree(pluginName); + this.provider.deleteFromDependencyTree(targetPluginName); + this.provider.buildDependencyTree(pluginName); } @Override diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java index 27af8e47..89f0b7b2 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java @@ -29,7 +29,7 @@ private void printUninstallInfo(List uninstallTargets) this.terminal.writeLine(" " + uninstallTargets.stream() .sorted() .collect(Collectors.joining(" "))); - Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); + Utils.printInstallStatistics(this.terminal, 0, uninstallTargets.size(), 0, 0); } @@ -37,6 +37,6 @@ private void printUninstallInfo(List uninstallTargets) public void onPluginEnumerated(PluginEnumeratedSignal signal) { this.printUninstallInfo(signal.getTargetPlugins()); - signal.setCancel(!SignalHandlingUtils.askContinue(terminal)); + signal.setCancel(!SignalHandlingUtils.askContinue(this.terminal)); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java index ada3c2af..ea471409 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java @@ -31,7 +31,7 @@ public void onGarbageEnumerated(GarbageEnumeratedSignal signal) .map(path -> path.getFileName().toString()) .collect(Collectors.joining(" "))); - signal.setCancel(!SignalHandlingUtils.askContinue(terminal)); + signal.setCancel(!SignalHandlingUtils.askContinue(this.terminal)); } @SignalHandler diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java index a461e1a4..2e7c0288 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java @@ -24,35 +24,35 @@ public CheckEnvSignalHandler(Terminal terminal) @SignalHandler public void onPluginIsIgnored(IgnoredPluginSignal signal) { - terminal.warn(PluginUtil.getPluginString(signal.getPluginDescription()) + + this.terminal.warn(PluginUtil.getPluginString(signal.getPluginDescription()) + " は ignore としてマークされていますが強制的にインストールが可能です。"); - terminal.writeLine(ChatColor.DARK_RED + "W: 強制的なインストールは予期しない問題を引き起こす可能性があります。"); + this.terminal.writeLine(ChatColor.DARK_RED + "W: 強制的なインストールは予期しない問題を引き起こす可能性があります。"); - signal.setCancelInstall(!SignalHandlingUtils.askContinue(terminal)); + signal.setCancelInstall(!SignalHandlingUtils.askContinue(this.terminal)); } private void printKeyValue(String key, String value) { - terminal.writeLine(ChatColor.DARK_GREEN + key + ChatColor.WHITE + ": " + ChatColor.GREEN + value); + this.terminal.writeLine(ChatColor.DARK_GREEN + key + ChatColor.WHITE + ": " + ChatColor.GREEN + value); } private void printPluginInfo(PluginDescriptionFile descriptionFile) { - printKeyValue("バージョン", descriptionFile.getVersion()); - printKeyValue("作者", String.join(", ", descriptionFile.getAuthors())); - printKeyValue("コマンド", String.join(", ", descriptionFile.getCommands().keySet())); + this.printKeyValue("バージョン", descriptionFile.getVersion()); + this.printKeyValue("作者", String.join(", ", descriptionFile.getAuthors())); + this.printKeyValue("コマンド", String.join(", ", descriptionFile.getCommands().keySet())); } @SignalHandler public void onPluginIsDuplicated(AlreadyInstalledPluginSignal signal) { - terminal.warn(signal.getInstalledPlugin().getName() + " は既にインストールされています。"); - terminal.writeLine(ChatColor.BLUE + "== 既にインストールされているプラグイン =="); - printPluginInfo(signal.getInstalledPlugin()); - terminal.writeLine(ChatColor.BLUE + "== インストールしようとしているプラグイン =="); - printPluginInfo(signal.getInstallingPlugin()); + this.terminal.warn(signal.getInstalledPlugin().getName() + " は既にインストールされています。"); + this.terminal.writeLine(ChatColor.BLUE + "== 既にインストールされているプラグイン =="); + this.printPluginInfo(signal.getInstalledPlugin()); + this.terminal.writeLine(ChatColor.BLUE + "== インストールしようとしているプラグイン =="); + this.printPluginInfo(signal.getInstallingPlugin()); - signal.setReplacePlugin(SignalHandlingUtils.askContinue(terminal)); + signal.setReplacePlugin(SignalHandlingUtils.askContinue(this.terminal)); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java index 32c9ad04..649d8e88 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java @@ -32,14 +32,14 @@ private void startDownloads(String id) this.currentDownload = id; this.downloadTotalSize = 0; this.downloadStarted = System.currentTimeMillis(); - this.downloadProgressBar = terminal.createProgressbar("ダウンロード"); + this.downloadProgressBar = this.terminal.createProgressbar("ダウンロード"); this.downloadProgressBar.setProgressMax(100); } private void addDownloadArtifact(String url, long size) { this.downloadTotalSize += size; - terminal.writeLine(ChatColor.GREEN + "取得 " + url + " [" + Utils.roundSizeUnit(size) + "]"); + this.terminal.writeLine(ChatColor.GREEN + "取得 " + url + " [" + Utils.roundSizeUnit(size) + "]"); } private void endDownloads() @@ -49,7 +49,7 @@ private void endDownloads() if (elapsedSec == 0) elapsedSec = 1; long bytesPerSec = this.downloadTotalSize / elapsedSec; - terminal.writeLine( + this.terminal.writeLine( ChatColor.GREEN + Utils.roundSizeUnit(this.downloadTotalSize) + " を " + ChatColor.YELLOW + elapsedSec + "秒" + ChatColor.GREEN + "で取得しました (" + @@ -63,7 +63,7 @@ private void endDownloads() @SignalHandler public void onDownloadingSignal(DownloadProgressSignal signal) { - if (currentDownload == null) + if (this.currentDownload == null) { this.startDownloads(signal.getDownloadId()); this.addDownloadArtifact(signal.getUrl(), signal.getTotalSize()); @@ -76,7 +76,7 @@ public void onDownloadingSignal(DownloadProgressSignal signal) @SignalHandler public void onDownloadFailed(DownloadErrorSignal signal) { - terminal.writeLine(String.format(ChatColor.RED + "失敗 %s: %s(%s)", + this.terminal.writeLine(String.format(ChatColor.RED + "失敗 %s: %s(%s)", signal.getUrl(), signal.getCause(), signal.getValue() )); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java index a246b62f..ccd67dcd 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java @@ -33,15 +33,15 @@ public void onFinished(InstallFinishedSignal finished) { InstallResult installResult = finished.getResult(); - if (printResult) - Utils.printInstallStatistics(terminal, installResult); + if (this.printResult) + Utils.printInstallStatistics(this.terminal, installResult); if (finished.getResult() instanceof InstallFailedInstallResult) { - onFail((InstallFailedInstallResult) finished.getResult()); + this.onFail((InstallFailedInstallResult) finished.getResult()); } else - onSuccess(installResult); + this.onSuccess(installResult); } /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java index 79673193..57e22922 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java @@ -40,6 +40,6 @@ public void onPluginModify(PluginModifiedSignal signal) break; } - terminal.writeLine(printMessage); + this.terminal.writeLine(printMessage); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java index cd95fdc3..db72fb7f 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java @@ -30,32 +30,32 @@ public DependenciesSignalHandler(Terminal terminal) @SignalHandler public void onDependencyResolveFailed(DependencyResolveFailedSignal signal) { - terminal.error("依存関係の解決に失敗しました: " + signal.getFailedDependency()); + this.terminal.error("依存関係の解決に失敗しました: " + signal.getFailedDependency()); } @SignalHandler public void onDepsDepsFailed(DependencyCollectDependencysDependsFailedSignal signal) { signal.getCollectFailedDependencies().forEach(dependency -> - terminal.error("依存関係の取得に失敗しました: " + dependency)); + this.terminal.error("依存関係の取得に失敗しました: " + dependency)); } @SignalHandler public void onDependencyLoadDescriptionFailed(DependencyLoadDescriptionFailedSignal signal) { - terminal.error("依存関係の読み取りに失敗しました: " + signal.getFailedDependency()); + this.terminal.error("依存関係の読み取りに失敗しました: " + signal.getFailedDependency()); } @SignalHandler public void onDependencyNameMismatch(DependencyNameMismatchSignal signal) { - terminal.error("依存関係の整合性が確認できませんでした: " + signal.getFailedDependency()); - terminal.info("他のバージョンのプラグインを使用することで解決できる可能性があります。"); + this.terminal.error("依存関係の整合性が確認できませんでした: " + signal.getFailedDependency()); + this.terminal.info("他のバージョンのプラグインを使用することで解決できる可能性があります。"); } @SignalHandler public void onDependencyTreeBuilt(DependsLoadOrderComputingSignal.Pre signal) { - terminal.writeLine(ChatColor.GREEN + "依存関係ツリーを構築中 ..."); + this.terminal.writeLine(ChatColor.GREEN + "依存関係ツリーを構築中 ..."); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java index adf3aeb0..277230c9 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java @@ -26,7 +26,7 @@ public InstallerSignalHandler(Terminal terminal) @SignalHandler public void onPluginInstallStart(PluginInstallingSignal signal) { - terminal.writeLine(ChatColor.GREEN + signal.getPluginDescription().getName() + " をインストールする準備をしています ..."); + this.terminal.writeLine(ChatColor.GREEN + signal.getPluginDescription().getName() + " をインストールする準備をしています ..."); } @SignalHandler @@ -34,20 +34,20 @@ public void onPluginRelocating(PluginRelocatingSignal signal) { String src = ".../" + signal.getSource().getFileName(); String dest = ".../" + signal.getTarget().getFileName(); - terminal.writeLine(ChatColor.GREEN + src + " を " + dest + " に再配置しています ..."); + this.terminal.writeLine(ChatColor.GREEN + src + " を " + dest + " に再配置しています ..."); } @SignalHandler public void onPluginLoadPre(PluginLoadSignal.Pre signal) { - terminal.writeLine(ChatColor.GREEN + + this.terminal.writeLine(ChatColor.GREEN + PluginUtil.getPluginString(signal.getPluginDescription()) + " を読み込んでいます ..."); } @SignalHandler public void onPluginLoading(PluginEnablingSignal.Pre signal) { - terminal.writeLine(ChatColor.GREEN + + this.terminal.writeLine(ChatColor.GREEN + PluginUtil.getPluginString(signal.getPlugin()) + " のトリガを処理しています ..."); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java index f4eabfe8..b267d193 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java @@ -34,7 +34,7 @@ public ResolverSignalHandler(Terminal terminal) @SignalHandler public void onPluginResolving(PluginResolvingSignal signal) { - terminal.writeLine(ChatColor.GREEN + "プラグインを解決しています ..."); + this.terminal.writeLine(ChatColor.GREEN + "プラグインを解決しています ..."); } @SignalHandler @@ -43,13 +43,13 @@ public void onPluginResolveError(PluginResolveErrorSignal signal) ErrorResult.ErrorCause errorCause = signal.getError().getCause(); String message = signal.getError().getMessage() == null ? "": "(" + signal.getError().getMessage() + ")"; - terminal.writeLine(ChatColor.RED + "プラグインの解決に失敗しました: " + errorCause + message); + this.terminal.writeLine(ChatColor.RED + "プラグインの解決に失敗しました: " + errorCause + message); } @SignalHandler public void onPluginsResolve(MultiplePluginResolvedSignal signal) { - terminal.warn("複数のプラグインが見つかりました。"); + this.terminal.warn("複数のプラグインが見つかりました。"); AtomicLong index = new AtomicLong(0); @@ -68,7 +68,7 @@ public void onPluginsResolve(MultiplePluginResolvedSignal signal) try { - QuestionResult result = terminal.getInput().showQuestion( + QuestionResult result = this.terminal.getInput().showQuestion( "使用するプラグインを選択してください", new AttributeChoice(keywordToTitle), QuestionAttribute.CANCELLABLE @@ -76,7 +76,7 @@ public void onPluginsResolve(MultiplePluginResolvedSignal signal) if (result.test(QuestionAttribute.CANCELLABLE)) { - terminal.error(ChatColor.RED + "インストールをキャンセルしました。"); + this.terminal.error(ChatColor.RED + "インストールをキャンセルしました。"); signal.setCancel(true); return; } @@ -87,12 +87,12 @@ else if (result.getRawAnswer().equalsIgnoreCase("a")) if (selected == null) { - terminal.error("不明な回答が選択されました。"); + this.terminal.error("不明な回答が選択されました。"); signal.setCancel(true); return; } - terminal.writeLine(ChatColor.GREEN + selected.getFileName() + "(" + selected.getVersion() + ") が解決されました。"); + this.terminal.writeLine(ChatColor.GREEN + selected.getFileName() + "(" + selected.getVersion() + ") が解決されました。"); signal.setSpecifiedResult(selected); } catch (InterruptedException ex) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java index 33a147bc..06879350 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java @@ -29,24 +29,24 @@ public TokenGenerateSignalHandler(Terminal terminal) @SignalHandler public void onTokenGenerateStarting(TokenGenerateStartingSignal signal) { - terminal.info("GitHub へ Web ブラウザを用いてログインします。"); - terminal.info("この操作により、 KPM はあなたの GitHub アカウントにアクセスできるようになります。"); + this.terminal.info("GitHub へ Web ブラウザを用いてログインします。"); + this.terminal.info("この操作により、 KPM はあなたの GitHub アカウントにアクセスできるようになります。"); - signal.setContinueGenerate(SignalHandlingUtils.askContinue(terminal)); + signal.setContinueGenerate(SignalHandlingUtils.askContinue(this.terminal)); } @SignalHandler public void onVerificationCodeRequesting(VerificationCodeRequestingSignal signal) { - terminal.info("サーバに接続しています ..."); + this.terminal.info("サーバに接続しています ..."); } @SignalHandler public void onVerificationCodeRequestFailed(VerificationCodeRequestFailedSignal signal) { - terminal.removeProgressbar("codeExpire"); + this.terminal.removeProgressbar("codeExpire"); - terminal.error("検証コードの取得に失敗しました:" + signal.getHttpStatusCode() + " " + signal.getErrorMessage()); + this.terminal.error("検証コードの取得に失敗しました:" + signal.getHttpStatusCode() + " " + signal.getErrorMessage()); } @SignalHandler @@ -57,16 +57,16 @@ public void onVerificationCodeReceived(VerificationCodeReceivedSignal signal) long expiresInSec = signal.getExpiresIn(); int expiresInMin = (int) (expiresInSec / 60); - terminal.writeLine( + this.terminal.writeLine( ChatColor.DARK_GREEN + "このリンクからコードを有効化してください:" + ChatColor.BLUE + ChatColor.UNDERLINE + verificationUrl); - terminal.writeLine(ChatColor.DARK_GREEN + "コード: " + ChatColor.WHITE + userCode); - terminal.info("このコードは " + expiresInMin + " 分で失効します。"); + this.terminal.writeLine(ChatColor.DARK_GREEN + "コード: " + ChatColor.WHITE + userCode); + this.terminal.info("このコードは " + expiresInMin + " 分で失効します。"); int expiresInSecInt = (int) expiresInSec; - if (terminal.isPlayer()) - terminal.showNotification(userCode, "GitHubでこのコードを入力して有効化してください。", + if (this.terminal.isPlayer()) + this.terminal.showNotification(userCode, "GitHubでこのコードを入力して有効化してください。", expiresInSecInt * 1000 ); @@ -78,33 +78,33 @@ public void onVerificationCodeReceived(VerificationCodeReceivedSignal signal) @SignalHandler public void onVerificationCodeExpired(VerificationCodeExpiredSignal signal) { - terminal.error("コードが失効しました: " + signal.getUserCode()); + this.terminal.error("コードが失効しました: " + signal.getUserCode()); - progressbar.hide(); - terminal.removeProgressbar("codeExpire"); + this.progressbar.hide(); + this.terminal.removeProgressbar("codeExpire"); } @SignalHandler public void onUserDoesntCompleteVerify(UserDoesntCompleteVerifySignal signal) { - progressbar.setProgress((int) signal.getRemainTime()); + this.progressbar.setProgress((int) signal.getRemainTime()); } @SignalHandler public void onUserVerifyDenied(UserVerifyDeniedSignal signal) { - progressbar.hide(); - terminal.removeProgressbar("codeExpire"); + this.progressbar.hide(); + this.terminal.removeProgressbar("codeExpire"); - terminal.error("コードの有効化に失敗しました:ユーザがコードの有効化を拒否しました。"); + this.terminal.error("コードの有効化に失敗しました:ユーザがコードの有効化を拒否しました。"); } @SignalHandler public void onUserVerifySucceeded(UserVerificationSuccessSignal signal) { - progressbar.hide(); - terminal.removeProgressbar("codeExpire"); + this.progressbar.hide(); + this.terminal.removeProgressbar("codeExpire"); - terminal.success("コードの有効化に成功しました。"); + this.terminal.success("コードの有効化に成功しました。"); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java index 17713d5d..7a384fdd 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java @@ -16,7 +16,7 @@ public TokenRegisterSignalHandler(Terminal terminal) @SignalHandler public void onTokenStored(TokenStoredSignal signal) { - terminal.success("トークンが登録されました。"); + this.terminal.success("トークンが登録されました。"); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java index f31a72e8..a2ebfbe9 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java @@ -24,39 +24,39 @@ public PluginIsDependencySignalHandler(Terminal terminal) @SignalHandler public void onPluginIsDependency(PluginIsDependencySignal signal) { - terminal.warn(PluginUtil.getPluginString(signal.getPlugin()) + " は以下のプラグインの依存関係です。"); - terminal.writeLine(" " + signal.getDependedBy().stream() + this.terminal.warn(PluginUtil.getPluginString(signal.getPlugin()) + " は以下のプラグインの依存関係です。"); + this.terminal.writeLine(" " + signal.getDependedBy().stream() .map(Plugin::getName) .sorted() .collect(Collectors.joining(" "))); - terminal.warn("このプラグインのアンインストールにより、これらのプラグインが動作しなくなる可能性があります。"); + this.terminal.warn("このプラグインのアンインストールにより、これらのプラグインが動作しなくなる可能性があります。"); - boolean uninstallThem = pollUninstallDeps(signal.getDependedBy()); + boolean uninstallThem = this.pollUninstallDeps(signal.getDependedBy()); signal.setForceUninstall(uninstallThem); } private boolean pollUninstallDeps(List dependencies) { - if (yesForAll) + if (this.yesForAll) return true; try { - QuestionResult result = terminal.getInput().showYNQuestion( + QuestionResult result = this.terminal.getInput().showYNQuestion( "これらのプラグインもアンインストールを行いますか?", QuestionAttribute.APPLY_FOR_ALL ).waitAndGetResult(); if (result.test(QuestionAttribute.APPLY_FOR_ALL)) - yesForAll = true; + this.yesForAll = true; return result.test(QuestionAttribute.YES); } catch (InterruptedException e) { e.printStackTrace(); - terminal.error("不明なエラーが発生しました: " + e.getMessage()); + this.terminal.error("不明なエラーが発生しました: " + e.getMessage()); return false; } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java index 5e6a22be..1b1da4cd 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -22,19 +22,19 @@ public UninstallReadySignalHandler(Terminal terminal) private void printUninstallInfo(List uninstallTargets) { - terminal.writeLine(ChatColor.GREEN + "以下のプラグインは「" + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); - terminal.writeLine(" " + uninstallTargets.stream() + this.terminal.writeLine(ChatColor.GREEN + "以下のプラグインは「" + ChatColor.RED + "削除" + ChatColor.GREEN + "」されます。"); + this.terminal.writeLine(" " + uninstallTargets.stream() .map(Plugin::getName) .sorted() .collect(Collectors.joining(" "))); - Utils.printInstallStatistics(terminal, 0, uninstallTargets.size(), 0, 0); + Utils.printInstallStatistics(this.terminal, 0, uninstallTargets.size(), 0, 0); } @SignalHandler public void onPluginsEnumerated(UninstallReadySignal signal) { - printUninstallInfo(signal.getPlugins()); - signal.setContinueUninstall(SignalHandlingUtils.askContinue(terminal)); + this.printUninstallInfo(signal.getPlugins()); + signal.setContinueUninstall(SignalHandlingUtils.askContinue(this.terminal)); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java index bfb64318..2eecd21e 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java @@ -35,31 +35,31 @@ private static String getErrorCauseMessage(PluginUninstallErrorSignal signal) @SignalHandler public void onPluginUninstall(PluginUninstallingSignal signal) { - terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " をアンインストールしています ..."); + this.terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " をアンインストールしています ..."); } @SignalHandler public void onRecipeRemove(PluginRegisteredRecipeSignal.Removing signal) { - terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " のレシピを削除しています ..."); + this.terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " のレシピを削除しています ..."); } @SignalHandler public void onDisabling(PluginDisablingSignal.Pre signal) { - terminal.writeLine(ChatColor.GREEN + PluginUtil.getPluginString(signal.getPlugin()) + " のトリガを処理しています ..."); + this.terminal.writeLine(ChatColor.GREEN + PluginUtil.getPluginString(signal.getPlugin()) + " のトリガを処理しています ..."); } @SignalHandler public void onUnloading(PluginUnloadingSignal.Pre signal) { - terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " を削除しています ..."); + this.terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " を削除しています ..."); } @SignalHandler public void onError(PluginUninstallErrorSignal signal) { - terminal.error( + this.terminal.error( ChatColor.GREEN + PluginUtil.getPluginString(signal.getDescription()) + " のアンインストールに失敗しました: ", getErrorCauseMessage(signal) ); diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java index 4842311d..18eefc61 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java @@ -19,14 +19,14 @@ public UpdateAliasesSignalHandler(Terminal terminal) @SignalHandler public void onUpdateAliases(UpdateFinishedSignal signal) { - terminal.success("エイリアスが更新されました。"); - terminal.success("登録数:%d", signal.getAliases()); + this.terminal.success("エイリアスが更新されました。"); + this.terminal.success("登録数:%d", signal.getAliases()); } @SignalHandler public void onURLMalformed(MalformedURLSignal signal) { - terminal.warn("不正なURLが指定されました(%s): %s", signal.getRemoteName(), signal.getRemoteURL()); + this.terminal.warn("不正なURLが指定されました(%s): %s", signal.getRemoteName(), signal.getRemoteURL()); } @SignalHandler @@ -35,13 +35,13 @@ public void onInvalidSources(InvalidSourceSignal signal) switch (signal.getErrorCause()) { case IO_ERROR: - terminal.warn("不正なソースファイルが指定されました(%s):IOError", signal.getSourceName()); + this.terminal.warn("不正なソースファイルが指定されました(%s):IOError", signal.getSourceName()); break; case SOURCE_FILE_MALFORMED: - terminal.warn("不正なソースファイルが指定されました(%s):Malformed", signal.getSourceName()); + this.terminal.warn("不正なソースファイルが指定されました(%s):Malformed", signal.getSourceName()); break; default: - terminal.warn("不正なソースファイルが指定されました(%s):Unknown", signal.getSourceName()); + this.terminal.warn("不正なソースファイルが指定されました(%s):Unknown", signal.getSourceName()); } } @@ -49,9 +49,9 @@ public void onInvalidSources(InvalidSourceSignal signal) public void onInstallFinished(InstallFinishedSignal signal) { if (signal.getResult().isSuccess()) - terminal.success("エイリアスの更新に成功しました。"); + this.terminal.success("エイリアスの更新に成功しました。"); else - terminal.warn("エイリアスの更新に失敗しました。"); + this.terminal.warn("エイリアスの更新に失敗しました。"); } } From f3230b64e6ccb00a1dad4d737e35d5d3b1bfaa85 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 03:58:52 +0900 Subject: [PATCH 382/745] refactor: Change tasks argument signature --- .../installer/AbstractInstaller.java | 1 + .../installer/impls/clean/GarbageCleaner.java | 4 ++-- .../impls/install/PluginInstaller.java | 12 ++++++------ .../impls/uninstall/PluginUninstaller.java | 4 ++-- .../installer/impls/update/AliasUpdater.java | 4 ++-- .../source/download/SourceDownloadTask.java | 10 +++++----- .../tasks/alias/update/UpdateAliasesTask.java | 9 ++++----- .../collector/DependsCollectTask.java | 18 +++++++++--------- .../computer/DependsComputeOrderTask.java | 7 +++---- .../tasks/description/DescriptionLoadTask.java | 7 +++---- .../task/tasks/download/DownloadTask.java | 7 +++---- .../tasks/garbage/clean/GarbageCleanTask.java | 7 +++---- .../garbage/search/GarbageSearchTask.java | 7 +++---- .../task/tasks/install/PluginsInstallTask.java | 9 ++++----- .../task/tasks/resolve/PluginResolveTask.java | 10 ++++------ .../task/tasks/uninstall/UnInstallTask.java | 9 ++++----- 16 files changed, 58 insertions(+), 67 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java index e35e47c0..3a9393d6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java @@ -25,6 +25,7 @@ */ public abstract class AbstractInstaller, P extends Enum

    > { + @Getter protected final KPMDaemon daemon; @Getter protected final InstallProgress> progress; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java index b9d1f489..37a811e2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java @@ -55,11 +55,11 @@ public InstallResult execute(@NotNull CleanArgument argument) throws GarbageCleanResult result = (GarbageCleanResult) this.submitter( CleanTasks.SEARCHING_GARBAGE, - new GarbageSearchTask(this.progress, this.signalHandler) + new GarbageSearchTask(this) ) .then( CleanTasks.DELETING_GARBAGE, - new GarbageCleanTask(this.progress, this.signalHandler) + new GarbageCleanTask(this) ) .bridgeArgument(searchResult -> new GarbageCleanArgument(searchResult.getGarbageFiles())) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index fb000f7c..6e31f5c9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -66,16 +66,16 @@ public InstallResult execute(@NotNull InstallArgument argument) th TaskResult pluginDescriptionResult = this.submitter( InstallTasks.RESOLVING_QUERY, - new PluginResolveTask(this.daemon, this.progress, this.signalHandler) + new PluginResolveTask(this) ) - .then(InstallTasks.DOWNLOADING, new DownloadTask(this.progress, this.signalHandler)) + .then(InstallTasks.DOWNLOADING, new DownloadTask(this)) .bridgeArgument(result -> { if (result.getResolveResult() == null) throw new IllegalArgumentException("Plugin Resolving must be successful"); return new DownloadArgument(result.getResolveResult().getDownloadUrl()); }) - .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(this.progress, this.signalHandler)) + .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(this)) .bridgeArgument(result -> new DescriptionLoadArgument(result.getPath())) .submitAll(new PluginResolveArgument(query)); @@ -136,13 +136,13 @@ public InstallResult execute(@NotNull InstallArgument argument) th TaskResult installResult = this.submitter( InstallTasks.COLLECTING_DEPENDENCIES, - new DependsCollectTask(this.daemon, this.progress, this.signalHandler) + new DependsCollectTask(this) ) - .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(this.progress, this.signalHandler)) + .then(InstallTasks.COMPUTING_LOAD_ORDER, new DependsComputeOrderTask(this)) .bridgeArgument(result -> new DependsComputeOrderArgument(result.getCollectedPlugins())) .then( InstallTasks.INSTALLING_PLUGINS, - new PluginsInstallTask(this.daemon, this.progress, this.signalHandler) + new PluginsInstallTask(this) ) .bridgeArgument(result -> new PluginsInstallArgument( pluginFilePath, pluginDescription, query, result.getOrder() diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java index fb1318c6..0ad81132 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java @@ -134,11 +134,11 @@ public InstallResult execute(@NotNull UninstallArgument argument UnInstallResult uninstallResult = (UnInstallResult) this.submitter( UnInstallTasks.COMPUTING_UNINSTALL_ORDER, - new DependsComputeOrderTask(this.progress, this.signalHandler) + new DependsComputeOrderTask(this) ) .then( UnInstallTasks.UNINSTALLING_PLUGINS, - new UnInstallTask(this.daemon, this.progress, this.signalHandler) + new UnInstallTask(this) ) .bridgeArgument(computeResult -> { List ordered = computeResult.getOrder(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java index df287aa5..b561e673 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java @@ -40,11 +40,11 @@ public InstallResult execute(@NotNull UpdateArgument argument) thro UpdateAliasesResult result = (UpdateAliasesResult) this.submitter( UpdateTasks.DOWNLOADING_SOURCES, - new SourceDownloadTask(this.progress, this.signalHandler) + new SourceDownloadTask(this) ) .then( UpdateTasks.UPDATING_ALIASES, - new UpdateAliasesTask(this.daemon, this.progress, this.signalHandler) + new UpdateAliasesTask(this) ) .bridgeArgument(sourceDownloadResult -> new UpdateAliasesArgument(sourceDownloadResult.getDownloadedSources())) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java index b9fa5439..0543f38f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java @@ -1,6 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.SourceDownloadFailedSignal; @@ -26,11 +26,11 @@ public class SourceDownloadTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public SourceDownloadTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); - this.signalHandler = signalHandler; + this.signalHandler = installer.getProgress().getSignalHandler(); this.status = SourceDownloadState.INITIALIZED; } @@ -110,7 +110,7 @@ private HashMap> downloadSources(HashMap re private Path downloadSource(String remoteName, URL remoteURL) { - DownloadResult result = new DownloadTask(this.progress, this.signalHandler) + DownloadResult result = new DownloadTask(this.progress.getInstaller()) .runTask(new DownloadArgument(remoteURL.toString())); boolean success = result.isSuccess(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java index 427b6816..42101f0c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java @@ -5,12 +5,11 @@ import com.google.gson.stream.JsonToken; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.alias.AliasUpdater; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.AliasUpdateSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.InvalidSourceSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.SourcePreparedSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import org.jetbrains.annotations.NotNull; @@ -32,10 +31,10 @@ public class UpdateAliasesTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public UpdateAliasesTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); - this.daemon = daemon; + super(installer.getProgress(), installer.getProgress().getSignalHandler()); + this.daemon = installer.getDaemon(); this.status = UpdateAliasesState.INITIALIZED; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java index f51752c8..6ef33289 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -1,7 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; @@ -58,13 +58,13 @@ public class DependsCollectTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public DependsCollectTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); - this.daemon = daemon; - this.signalHandler = signalHandler; - this.status = progress.getDependsCollectStatus(); + this.daemon = installer.getDaemon(); + this.signalHandler = installer.getProgress().getSignalHandler(); + this.status = this.progress.getDependsCollectStatus(); this.taskState = DependsCollectState.INITIALIZED; } @@ -162,7 +162,7 @@ private DependsCollectResult passCollector(@NotNull PluginDescriptionFile plugin { DependsCollectArgument arguments = new DependsCollectArgument(pluginDescription, alreadyCollectedPlugins); - return new DependsCollectTask(this.daemon, this.progress, this.signalHandler) // do new() because DependsCollectTask is stateful. + return new DependsCollectTask(this.progress.getInstaller()) // do new() because DependsCollectTask is stateful. .runTask(arguments); } @@ -224,7 +224,7 @@ private DownloadResult passDownloader(@NotNull String url) { DownloadArgument argument = new DownloadArgument(url); - return new DownloadTask(this.progress, this.signalHandler) + return new DownloadTask(this.progress.getInstaller()) .runTask(argument); } @@ -252,7 +252,7 @@ private PluginResolveResult passResolver(@NotNull String dependency) { PluginResolveArgument resolveArgument = new PluginResolveArgument(dependency); - return new PluginResolveTask(this.daemon, this.progress, this.signalHandler) + return new PluginResolveTask(this.progress.getInstaller()) .runTask(resolveArgument); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index 95c36f1d..ca17a809 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -1,10 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -27,9 +26,9 @@ public class DependsComputeOrderTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public DependsComputeOrderTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); this.state = DependsComputeOrderState.INITIALIZED; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java index 34f49a92..c0e106c4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java @@ -1,9 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; @@ -19,9 +18,9 @@ public class DescriptionLoadTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public DescriptionLoadTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); this.taskState = DescriptionLoadState.INITIALIZED; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java index 62213e5d..2b117de2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java @@ -1,12 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadStartingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; @@ -26,9 +25,9 @@ public class DownloadTask extends InstallTask private DownloadState taskState; - public DownloadTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) + public DownloadTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); this.randomDownloadID = UUID.randomUUID().toString(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java index 3088970f..60a13d09 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java @@ -1,12 +1,11 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageDeleteSkippedSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageDeletingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.InvalidIntegritySignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; @@ -22,9 +21,9 @@ public class GarbageCleanTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public GarbageCleanTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); this.status = GarbageCleanState.INITIALIZED; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java index 1f8eac25..b3f2974b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java @@ -1,9 +1,8 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -20,9 +19,9 @@ public class GarbageSearchTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public GarbageSearchTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); this.status = GarbageSearchState.INITIALIZED; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java index fcc43cb7..b98ba1d3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java @@ -2,7 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; @@ -14,7 +14,6 @@ import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.entity.Player; @@ -56,11 +55,11 @@ public class PluginsInstallTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public PluginsInstallTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); - PluginMetaManager pluginMetaManager = daemon.getPluginMetaManager(); + PluginMetaManager pluginMetaManager = installer.getDaemon().getPluginMetaManager(); this.pluginMetaManager = pluginMetaManager; this.pluginMetaProvider = pluginMetaManager.getProvider(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java index 4244fd45..91ffd0c1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java @@ -1,7 +1,6 @@ package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; @@ -11,7 +10,6 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,10 +22,10 @@ public class PluginResolveTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public PluginResolveTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); - this.resolver = daemon.getPluginResolver(); + super(installer.getProgress(), installer.getProgress().getSignalHandler()); + this.resolver = installer.getDaemon().getPluginResolver(); this.taskState = PluginResolveState.INITIALIZED; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java index d781ad00..c71b1b7c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java @@ -2,7 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginDisablingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; @@ -11,7 +11,6 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.StartingGCSignal; import net.kunmc.lab.teamkunpluginmanager.loader.CommandsPatcher; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.Keyed; @@ -83,10 +82,10 @@ public class UnInstallTask extends InstallTask progress, @NotNull SignalHandleManager signalHandler) + public UnInstallTask(@NotNull AbstractInstaller installer) { - super(progress, signalHandler); - this.daemon = daemon; + super(installer.getProgress(), installer.getProgress().getSignalHandler()); + this.daemon = installer.getDaemon(); this.taskState = UnInstallState.INITIALIZED; } From 115ce2638c50d014b41020dd6756400ce3dce09b Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 16:18:40 +0900 Subject: [PATCH 383/745] fix: Private repo supporting --- .../resolver/impl/GitHubURLResolver.java | 2 +- .../utils/http/Requests.java | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java index 0c87bcec..81bf9e46 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java @@ -170,7 +170,7 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso JsonObject assetObject = asset.getAsJsonObject(); - String downloadURL = assetObject.get("browser_download_url").getAsString(); + String downloadURL = assetObject.get("url").getAsString(); String fileName = assetObject.get("name").getAsString(); long size = assetObject.get("size").getAsLong(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java index 470be149..07adb923 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java @@ -61,9 +61,10 @@ private static HTTPResponse doRedirect(HTTPResponse response, int redirectCount) return doRedirect(newResponse, redirectCount + 1); } - private static Map setupDefaultHeaders(@NotNull String host) + @NotNull + private static Map setupDefaultHeaders(@NotNull String host, @NotNull Map currentHeaders) { - HashMap headers = new HashMap<>(); + HashMap headers = new HashMap<>(currentHeaders); headers.put("User-Agent", "Mozilla/8.10 (X931; Peyantu; Linux x86_64) PeyangWebKit/114.514(KUN, like Gacho) TeamKunPluginManager/" + version); @@ -72,9 +73,10 @@ private static Map setupDefaultHeaders(@NotNull String host) StringUtils.endsWithIgnoreCase(host, ".github.com") || StringUtils.endsWithIgnoreCase(host, ".githubusercontent.com")) { - headers.put("Accept", "application/vnd.github.v3+json"); + if (!headers.containsKey("Accept")) + headers.put("Accept", "application/vnd.github.v3+json"); - if (tokenStore.isTokenAvailable()) + if (!headers.containsKey("Authorization") && tokenStore.isTokenAvailable()) headers.put( "Authorization", "Token " + tokenStore.getToken() @@ -118,7 +120,7 @@ public static HTTPResponse request(@NotNull RequestContext context) for (Map.Entry entry : context.getExtraHeaders().entrySet()) connection.setRequestProperty(entry.getKey(), entry.getValue()); - setupDefaultHeaders(url.getHost()) + setupDefaultHeaders(url.getHost(), context.getExtraHeaders()) .forEach(connection::setRequestProperty); connection.connect(); @@ -198,11 +200,15 @@ else if (responseCode >= 400) public static long downloadFile(@NotNull RequestMethod method, @NotNull String url, @NotNull Path path, @Nullable Consumer onProgress) throws IOException { - try (HTTPResponse response = request(RequestContext.builder() + RequestContext.RequestContextBuilder context = RequestContext.builder() .url(url) .method(method) - .followRedirects(true) - .build()); + .followRedirects(true); + + if (url.matches("^https?://api\\.github\\.com/.+?/releases/assets/\\d+$")) + context.header("Accept", "application/octet-stream"); + + try (HTTPResponse response = request(context.build()); OutputStream output = Files.newOutputStream(path)) { if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) From 503771d7c2af307f7411ecaafc14edd8eda540a8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 16:45:37 +0900 Subject: [PATCH 384/745] fix: Connection leaking with AliasProvider --- .../alias/AliasProvider.java | 22 ++++++++++--------- .../utils/db/Transaction.java | 15 +++++++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java index f345557a..512029d3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java @@ -99,11 +99,12 @@ public boolean hasSource(String id) */ public AliasSource getSource(String id) { - try (ResultRow row = Transaction.create(this.db, "SELECT * FROM source WHERE name = ?") - .set(1, id) - .executeQuery() - .stream() - .findFirst().orElse(null)) + try (Transaction transaction = Transaction.create(this.db, "SELECT * FROM source WHERE name = ?") + .set(1, id); + ResultRow row = transaction + .executeQuery() + .stream() + .findFirst().orElse(null)) { if (row == null) return null; @@ -124,11 +125,12 @@ public AliasSource getSource(String id) */ public Alias getNameByAlias(String name) { - try (ResultRow row = Transaction.create(this.db, "SELECT * FROM alias WHERE name = ?") - .set(1, name) - .executeQuery() - .stream() - .findFirst().orElse(null)) + try (Transaction transaction = Transaction.create(this.db, "SELECT * FROM alias WHERE name = ?") + .set(1, name); + ResultRow row = transaction + .executeQuery() + .stream() + .findFirst().orElse(null)) { if (row == null) return null; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java index 12b38968..a84c4f26 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java @@ -23,7 +23,7 @@ /** * DBのトランザクションを簡単に行うためのクラスです。 */ -public class Transaction +public class Transaction implements AutoCloseable { /** * Dbのコネクションです。 @@ -640,10 +640,17 @@ public boolean isExists() return this.isExists(true); } - public void close() throws Exception + @Override + public void close() { - if (!this.connection.isClosed()) - this.connection.close(); + try + { + if (!this.connection.isClosed()) + this.connection.close(); + } + catch (SQLException ignored) + { + } } /** From 5448bf513f2a195617189893013a1516f9f072ce Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 04:10:21 +0900 Subject: [PATCH 385/745] feat: KPM info file --- .../lab/teamkunpluginmanager/KPMDaemon.java | 14 +- .../impls/install/InstallErrorCause.java | 1 + .../impls/install/PluginInstaller.java | 51 ++++- .../PluginIncompatibleWithKPMSignal.java | 45 +++++ .../InvalidInformationFileException.java | 14 ++ .../kpminfo/KPMInfoManager.java | 90 +++++++++ .../kpminfo/KPMInformationFile.java | 87 +++++++++ .../InvalidVersionSyntaxException.java | 12 ++ .../utils/versioning/Version.java | 180 ++++++++++++++++++ .../utils/versioning/VersionComparator.java | 12 ++ .../utils/versioning/VersionElement.java | 44 +++++ 11 files changed, 537 insertions(+), 13 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/PluginIncompatibleWithKPMSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/InvalidInformationFileException.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionComparator.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index b1a437f1..649483ef 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.alias.AliasPluginResolver; import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; import net.kunmc.lab.teamkunpluginmanager.installer.InstallManager; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInfoManager; import net.kunmc.lab.teamkunpluginmanager.loader.PluginLoader; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; @@ -14,6 +15,7 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -48,6 +50,11 @@ public class KPMDaemon */ @NotNull private final PluginMetaManager pluginMetaManager; + /** + * プラグインのKPM情報ファイルを管理するクラスです。 + */ + @NotNull + private final KPMInfoManager kpmInfoManager; /** * トークンを保管しセキュアに管理するクラスです。 */ @@ -84,6 +91,7 @@ public KPMDaemon(@NotNull KPMEnvironment env) this.envs = env; this.logger = env.getLogger(); this.pluginMetaManager = new PluginMetaManager(env.getPlugin(), env.getMetadataDBPath()); + this.kpmInfoManager = new KPMInfoManager(this); this.tokenStore = new TokenStore(env.getTokenPath(), env.getTokenKeyPath()); this.pluginResolver = new PluginResolver(); this.aliasProvider = new AliasProvider(env.getAliasesDBPath()); @@ -160,7 +168,7 @@ private void setupToken() private void initializeRequests() { - Requests.setVersion(this.getVersion()); + Requests.setVersion(this.getVersion().toString()); Requests.setTokenStore(this.tokenStore); } @@ -170,8 +178,8 @@ public void shutdown() this.aliasProvider.close(); } - public String getVersion() + public Version getVersion() { - return this.getEnvs().getPlugin().getDescription().getVersion(); + return Version.ofUnsafe(this.getEnvs().getPlugin().getDescription().getVersion()); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java index b8d8f76c..6327d7c8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java @@ -16,4 +16,5 @@ public enum InstallErrorCause * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 */ PLUGIN_ALREADY_INSTALLED, + INCOMPATIBLE_KPM_VERSION, } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index 6e31f5c9..67a8c12a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.PluginIncompatibleWithKPMSignal; import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; @@ -21,12 +22,14 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -88,21 +91,19 @@ public InstallResult execute(@NotNull InstallArgument argument) th pluginName = pluginDescription.getName(); // endregion + // Load kpmInfo + KPMInformationFile kpmInfo = this.daemon.getKpmInfoManager().loadInfo(pluginFilePath, pluginDescription); + if (kpmInfo == null) + return null; // No kpmInfo file. + boolean replacePlugin = false; // region Do assertions. this.progress.setCurrentTask(InstallTasks.CHECKING_ENVIRONMENT); - // region Check if plugin is ignored. - if (this.isPluginIgnored(pluginName)) - { - IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(pluginDescription); - this.postSignal(ignoredPluginSignal); - - if (ignoredPluginSignal.isCancelInstall()) - return this.error(InstallErrorCause.PLUGIN_IGNORED); - } - // endregion + InstallErrorCause checkEnvErrorResult = this.checkEnvironment(pluginDescription, kpmInfo); + if (checkEnvErrorResult != null) + return this.error(checkEnvErrorResult); // region Check if plugin is already installed. @@ -158,6 +159,36 @@ public InstallResult execute(@NotNull InstallArgument argument) th return this.success(); } + @Nullable + private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescription, KPMInformationFile kpmInfo) + { + String pluginName = pluginDescription.getName(); + + // region Check if the plugin is marked as ignored + if (this.isPluginIgnored(pluginName)) + { + IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(pluginDescription); + this.postSignal(ignoredPluginSignal); + + if (ignoredPluginSignal.isCancelInstall()) + return InstallErrorCause.PLUGIN_IGNORED; + } + // endregion + + // region Check if the plugin is incompatible with the server. + if (!kpmInfo.getKpmVersion().isGreaterThanOrEqualTo(this.daemon.getVersion())) + { + PluginIncompatibleWithKPMSignal incompatibleSignal = + new PluginIncompatibleWithKPMSignal(pluginDescription, kpmInfo, this.daemon.getVersion()); + this.postSignal(incompatibleSignal); + + if (!incompatibleSignal.isForceInstall()) + return InstallErrorCause.INCOMPATIBLE_KPM_VERSION; + } + + return null; // No error with environment. + } + private void removeOldPlugin(Plugin plugin) { this.progress.setCurrentTask(InstallTasks.REMOVING_OLD_PLUGIN); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/PluginIncompatibleWithKPMSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/PluginIncompatibleWithKPMSignal.java new file mode 100644 index 00000000..b2a167cf --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/PluginIncompatibleWithKPMSignal.java @@ -0,0 +1,45 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +/** + * プラグインがこのKPMと互換性がない場合に投げられるシグナルです。 + */ +@Data +public class PluginIncompatibleWithKPMSignal implements Signal +{ + /** + * プラグインの説明ファイルです。 + */ + @NotNull + private final PluginDescriptionFile pluginDescription; + /** + * プラグインのKPM情報です。 + */ + @NotNull + private final KPMInformationFile kpmInformation; + /** + * このKPMのバージョンです。 + */ + @NotNull + private final Version kpmVersion; + + /** + * 強制的にインストールするかどうかを示すフラグです。 + */ + private boolean forceInstall; + + public PluginIncompatibleWithKPMSignal(@NotNull PluginDescriptionFile pluginDescription, @NotNull KPMInformationFile kpmInformation, @NotNull Version kpmVersion) + { + this.pluginDescription = pluginDescription; + this.kpmInformation = kpmInformation; + this.kpmVersion = kpmVersion; + + this.forceInstall = false; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/InvalidInformationFileException.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/InvalidInformationFileException.java new file mode 100644 index 00000000..33a56607 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/InvalidInformationFileException.java @@ -0,0 +1,14 @@ +package net.kunmc.lab.teamkunpluginmanager.kpminfo; + +public class InvalidInformationFileException extends Exception +{ + public InvalidInformationFileException(String message) + { + super(message); + } + + public InvalidInformationFileException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java new file mode 100644 index 00000000..67024e88 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java @@ -0,0 +1,90 @@ +package net.kunmc.lab.teamkunpluginmanager.kpminfo; + +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.FileNotFoundException; +import java.nio.file.Path; +import java.util.HashMap; + +/** + * KPM情報ファイルを管理するクラスです。 + */ +public class KPMInfoManager +{ + private final KPMDaemon daemon; + private final HashMap lookupNames; + + public KPMInfoManager(KPMDaemon daemon) + { + this.daemon = daemon; + this.lookupNames = new HashMap<>(); + } + + /** + * KPM情報ファイルを読み込み追加します。 + * + * @param path KPM情報ファイルのパス + * @param descriptionFile プラグインの説明ファイル + * @return 読み込みに成功した場合はKPM情報ファイル、失敗した場合はnull + */ + @Nullable + public KPMInformationFile loadInfo(@NotNull Path path, @NotNull PluginDescriptionFile descriptionFile) + { + KPMInformationFile info = null; + try + { + info = KPMInformationFile.load(path); + this.lookupNames.put(descriptionFile.getName(), info); + } + catch (InvalidInformationFileException e) + { + this.daemon.getLogger().warn( + "The plugin " + descriptionFile.getName() + " has invalid KPM information file: " + e.getMessage()); + this.daemon.getLogger().warn("The plugin's KPM information will be ignored."); + } + catch (FileNotFoundException ignored) + { + } + + return info; + } + + /** + * プラグインのKPM情報ファイルを取得します。 + * + * @param plugin プラグイン + * @return プラグインのKPM情報ファイル + */ + @Nullable + public KPMInformationFile getInfo(@NotNull Plugin plugin) + { + return this.lookupNames.get(plugin.getDescription().getName()); + } + + /** + * プラグインのKPM情報ファイルを取得します。 + * + * @param pluginName プラグイン名 + * @return プラグインのKPM情報ファイル + */ + + @Nullable + public KPMInformationFile getInfo(@NotNull String pluginName) + { + return this.lookupNames.get(pluginName); + } + + /** + * プラグインのKPM情報ファイルを削除します。 + * + * @param plugin プラグイン + */ + public void removeInfo(@NotNull Plugin plugin) + { + this.lookupNames.remove(plugin.getDescription().getName()); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java new file mode 100644 index 00000000..7f482ce7 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java @@ -0,0 +1,87 @@ +package net.kunmc.lab.teamkunpluginmanager.kpminfo; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import org.jetbrains.annotations.NotNull; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.Map; +import java.util.zip.ZipFile; + +/** + * KPMの情報ファイルを表すクラスです。 + */ +@Value +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class KPMInformationFile +{ + private static final Yaml YAML_PARSER; + + static + { + YAML_PARSER = new Yaml(); + } + + /** + * 対応するKPMのバージョンです。 + * このバージョンより古いKPMではこの情報ファイルを読み込むことができません。 + */ + Version kpmVersion; + + @NotNull + public static KPMInformationFile load(InputStream stream) throws InvalidInformationFileException + { + return loadFromMap(YAML_PARSER.load(stream)); + } + + @NotNull + public static KPMInformationFile load(Path jarFile) throws InvalidInformationFileException, FileNotFoundException + { + File file = jarFile.toFile(); + if (!file.exists()) + throw new FileNotFoundException("File not found: " + file.getAbsolutePath()); + + try (ZipFile zip = new ZipFile(file)) + { + InputStream stream = zip.getInputStream(zip.getEntry("kpm.yml")); + if (stream == null) + throw new InvalidInformationFileException("kpm.yml not found in " + file.getAbsolutePath()); + + return load(stream); + } + catch (IOException e) + { + throw new InvalidInformationFileException("Failed to load kpm.yml from " + file.getAbsolutePath(), e); + } + } + + private static KPMInformationFile loadFromMap(Map map) throws InvalidInformationFileException + { + if (map == null) + throw new InvalidInformationFileException("Information file is empty."); + + Version version; + // region Parse kpm => kpmVersion [required] + if (!map.containsKey("kpm")) + throw new InvalidInformationFileException("kpm is not found."); + + Object kpmVersionObj = map.get("kpm"); + if (!(kpmVersionObj instanceof String)) + throw new InvalidInformationFileException("kpmVersion is not a string."); + + if ((version = Version.of((String) kpmVersionObj)) == null) + throw new InvalidInformationFileException("Invalid syntax of kpm version: " + kpmVersionObj); + // endregion + + return new KPMInformationFile(version); + + } + +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java new file mode 100644 index 00000000..8dc962c3 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.versioning; + +/** + * バージョンの構文が不正な場合に投げられる例外です。 + */ +public class InvalidVersionSyntaxException extends Exception +{ + public InvalidVersionSyntaxException(String message) + { + super(message); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java new file mode 100644 index 00000000..4f4a1205 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java @@ -0,0 +1,180 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.versioning; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Getter +@AllArgsConstructor +public class Version implements Comparable +{ + private static final Pattern VERSION_PATTERN; + + static + { + VERSION_PATTERN = Pattern.compile( + "^v?" + + "(?0|[1-9]\\d*)" + + "\\.(?0|[1-9]\\d*)\\." + + "(?0|[1-9]\\d*)" + + "(?:-(?(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?" + + "(?:\\+(?[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"); + } + + @Getter(AccessLevel.NONE) + @NotNull + private final String rawVersion; + @NotNull + private final VersionElement major; + @NotNull + private final VersionElement minor; + @NotNull + private final VersionElement patch; + @Nullable + private final VersionElement preRelease; + @Nullable + private final VersionElement buildMetadata; + + private static Version compileVersion(String rawVersion) throws InvalidVersionSyntaxException + { + Matcher matcher = VERSION_PATTERN.matcher(rawVersion); + + if (!matcher.find()) + throw new InvalidVersionSyntaxException(rawVersion); + + String major = matcher.group("major"); + String minor = matcher.group("minor"); + String patch = matcher.group("patch"); + String preRelease = matcher.group("preRelease"); + String buildMetadata = matcher.group("buildMetadata"); + + return new Version( + rawVersion, + new VersionElement(major), + new VersionElement(minor), + new VersionElement(patch), + preRelease == null ? null: new VersionElement(preRelease), + buildMetadata == null ? null: new VersionElement(buildMetadata) + ); + } + + public static boolean isValidVersionString(@NotNull String versionString) + { + return VERSION_PATTERN.matcher(versionString).find(); + } + + @Nullable + public static Version of(@NotNull String rawVersion) + { + if (rawVersion.isEmpty() || !isValidVersionString(rawVersion)) + return null; + + try + { + return compileVersion(rawVersion); + } + catch (InvalidVersionSyntaxException e) + { + return null; + } + } + + @NotNull + public static Version ofUnsafe(@NotNull String rawVersion) + { + try + { + return compileVersion(rawVersion); + } + catch (InvalidVersionSyntaxException e) + { + throw new IllegalArgumentException(e); + } + } + + public boolean isPreRelease() + { + return this.preRelease != null; + } + + public boolean isGreaterThan(@Nonnull Version other) + { + return this.compareTo(other) > 0; + } + + public boolean isLessThan(@Nonnull Version other) + { + return this.compareTo(other) < 0; + } + + public boolean isGreaterThanOrEqualTo(@Nonnull Version other) + { + return this.compareTo(other) >= 0; + } + + public boolean isLessThanOrEqualTo(@Nonnull Version other) + { + return this.compareTo(other) <= 0; + } + + public boolean isEqualTo(@Nonnull Version other) + { + return this.compareTo(other) == 0; + } + + @Override + public String toString() + { + return this.rawVersion; + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + return true; + + if (!(obj instanceof Version)) + return false; + + return this.isEqualTo((Version) obj); + } + + @Override + public int compareTo(@Nonnull Version o) + { + int majorCompare = this.major.compareTo(o.major); + int minorCompare = this.minor.compareTo(o.minor); + int patchCompare = this.patch.compareTo(o.patch); + + if (majorCompare != 0) + return majorCompare; + else if (minorCompare != 0) + return minorCompare; + else if (patchCompare != 0) + return patchCompare; + + if (this.preRelease != null) + { + if (o.preRelease == null) + return 1; + else + return this.preRelease.compareTo(o.preRelease); + } + else if (this.buildMetadata != null) + { + if (o.buildMetadata == null) + return 1; + else + return this.buildMetadata.compareTo(o.buildMetadata); + } + + return 0; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionComparator.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionComparator.java new file mode 100644 index 00000000..cc720408 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionComparator.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.versioning; + +import java.util.Comparator; + +public class VersionComparator implements Comparator +{ + @Override + public int compare(Version o1, Version o2) + { + return o1.compareTo(o2); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java new file mode 100644 index 00000000..eaf4a14a --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java @@ -0,0 +1,44 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.versioning; + +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; + +/** + * バージョンの要素を表すクラスです。 + */ +@Getter +public class VersionElement implements Comparable +{ + @NotNull + private final String rawValue; + + private final int intValue; + + public VersionElement(@NotNull String rawValue) + { + this.rawValue = rawValue; + + int intValue; + try + { + intValue = Integer.parseInt(rawValue); + } + catch (NumberFormatException e) + { + intValue = -1; + } + + this.intValue = intValue; + } + + @Override + public int compareTo(@Nonnull VersionElement o) + { + if (this.intValue != -1 && o.intValue != -1) + return Integer.compare(this.intValue, o.intValue); + else + return this.rawValue.compareTo(o.rawValue); + } +} From 597f7232aac24500b120b3daecc7c0e9cc780451 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 15:42:40 +0900 Subject: [PATCH 386/745] feat: old versioning compatible --- .../lab/teamkunpluginmanager/utils/versioning/Version.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java index 4f4a1205..50b31feb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java @@ -21,8 +21,8 @@ public class Version implements Comparable VERSION_PATTERN = Pattern.compile( "^v?" + "(?0|[1-9]\\d*)" + - "\\.(?0|[1-9]\\d*)\\." + - "(?0|[1-9]\\d*)" + + "\\.(?0|[1-9]\\d*)" + + "(?:\\.(?0|[1-9]\\d*))" + "(?:-(?(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?" + "(?:\\+(?[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"); } From be6b006e00fed7b8fefe839eb5c2dbd2902240a6 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 16:35:07 +0900 Subject: [PATCH 387/745] feat: API version check --- .../installer/impls/install/InstallErrorCause.java | 8 ++++++++ .../installer/impls/install/PluginInstaller.java | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java index 6327d7c8..4162900e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java @@ -16,5 +16,13 @@ public enum InstallErrorCause * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 */ PLUGIN_ALREADY_INSTALLED, + /** + * プラグインのapi-versionが、このサーバーバージョンと互換性がありません。 + */ + INCOMPATIBLE_API_VERSION, + /** + * プラグインのKPM指定バージョンと、このKPMのバージョンが互換性がなく、 + * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.PluginIncompatibleWithKPMSignal} でも強制インストールが選択されませんでした。 + */ INCOMPATIBLE_KPM_VERSION, } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index 67a8c12a..c0bc06b8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -160,10 +160,12 @@ public InstallResult execute(@NotNull InstallArgument argument) th } @Nullable + @SuppressWarnings("deprecation") private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescription, KPMInformationFile kpmInfo) { String pluginName = pluginDescription.getName(); + // region Check if the plugin is marked as ignored if (this.isPluginIgnored(pluginName)) { @@ -176,6 +178,13 @@ private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescripti // endregion // region Check if the plugin is incompatible with the server. + if (pluginDescription.getAPIVersion() != null) + { + String apiVersion = pluginDescription.getAPIVersion(); + if (Bukkit.getUnsafe().isSupportedApiVersion(apiVersion)) + return InstallErrorCause.INCOMPATIBLE_API_VERSION; + } + if (!kpmInfo.getKpmVersion().isGreaterThanOrEqualTo(this.daemon.getVersion())) { PluginIncompatibleWithKPMSignal incompatibleSignal = @@ -185,6 +194,7 @@ private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescripti if (!incompatibleSignal.isForceInstall()) return InstallErrorCause.INCOMPATIBLE_KPM_VERSION; } + // endregion return null; // No error with environment. } From 8df8aa11d5b538b0d08cb5f17dfe3603e2d8d955 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 16:37:08 +0900 Subject: [PATCH 388/745] fix: Invalid japanese --- .../signal/handlers/common/CheckEnvSignalHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java index 2e7c0288..587a254d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java @@ -25,9 +25,9 @@ public CheckEnvSignalHandler(Terminal terminal) public void onPluginIsIgnored(IgnoredPluginSignal signal) { this.terminal.warn(PluginUtil.getPluginString(signal.getPluginDescription()) + - " は ignore としてマークされていますが強制的にインストールが可能です。"); + " は ignore としてマークされていますが強制的な操作が可能です。"); - this.terminal.writeLine(ChatColor.DARK_RED + "W: 強制的なインストールは予期しない問題を引き起こす可能性があります。"); + this.terminal.writeLine(ChatColor.DARK_RED + "W: 強制的な操作は予期しない問題を引き起こす可能性があります。"); signal.setCancelInstall(!SignalHandlingUtils.askContinue(this.terminal)); } From 746ed75a0381df1833a2ba03a3d34c4b6dcd72d1 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 16:37:18 +0900 Subject: [PATCH 389/745] feat: Frontend compatible --- .../signal/handlers/common/CheckEnvSignalHandler.java | 11 +++++++++++ .../handlers/intall/InstallFinishedSignalHandler.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java index 587a254d..5aced915 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java @@ -2,6 +2,7 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.PluginIncompatibleWithKPMSignal; import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; @@ -21,6 +22,16 @@ public CheckEnvSignalHandler(Terminal terminal) this.terminal = terminal; } + @SignalHandler + public void onIncompatibleWithKPM(PluginIncompatibleWithKPMSignal signal) + { + this.terminal.warn(PluginUtil.getPluginString(signal.getPluginDescription()) + + " はこの TeamKunPluginManager と互換性がありません。"); + this.terminal.info("強制的なインストールが可能ですが、強制的な操作は予期しない問題を引き起こす可能性があります。"); + + signal.setForceInstall(SignalHandlingUtils.askContinue(this.terminal)); + } + @SignalHandler public void onPluginIsIgnored(IgnoredPluginSignal signal) { diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java index 9b8fc5b1..745cae44 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -41,6 +41,12 @@ private boolean handleGeneralErrors(@Nullable InstallErrorCause cause) case PLUGIN_ALREADY_INSTALLED: this.terminal.error("指定されたプラグインは既にインストールされています。"); return true; + case INCOMPATIBLE_API_VERSION: + this.terminal.error("指定されたプラグインは、このサーバーバージョンと互換性がありません(プラグインのapi-versionがより新しい可能性があります)。"); + return true; + case INCOMPATIBLE_KPM_VERSION: + this.terminal.error("指定されたプラグインは、このKPMのバージョンと互換性がありません。"); + return true; } return false; From 860873676db676e535827b49cf55e8c19db7b4c3 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 21:04:09 +0900 Subject: [PATCH 390/745] fix: Version if --- .../installer/impls/install/PluginInstaller.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index c0bc06b8..5062782e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -181,11 +181,11 @@ private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescripti if (pluginDescription.getAPIVersion() != null) { String apiVersion = pluginDescription.getAPIVersion(); - if (Bukkit.getUnsafe().isSupportedApiVersion(apiVersion)) + if (!Bukkit.getUnsafe().isSupportedApiVersion(apiVersion)) return InstallErrorCause.INCOMPATIBLE_API_VERSION; } - if (!kpmInfo.getKpmVersion().isGreaterThanOrEqualTo(this.daemon.getVersion())) + if (kpmInfo.getKpmVersion().isGreaterThanOrEqualTo(this.daemon.getVersion())) { PluginIncompatibleWithKPMSignal incompatibleSignal = new PluginIncompatibleWithKPMSignal(pluginDescription, kpmInfo, this.daemon.getVersion()); From 465b954360dfbb207e33b9d96a0e9e4f6e6283f4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 16 Oct 2022 21:47:54 +0900 Subject: [PATCH 391/745] feat: Schema --- kpm-info.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 kpm-info.json diff --git a/kpm-info.json b/kpm-info.json new file mode 100644 index 00000000..97dff331 --- /dev/null +++ b/kpm-info.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "KPM Information File Schema", + "type": "object", + "definitions": { + "version": { + "type": "string", + "pattern": "^v?(?[3-9]\\d*)\\.(?0|[1-9]\\d*)(\\.(?0|[1-9]\\d*))(-(?(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))(?:\\+(?[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" + } + }, + "properties": { + "kpm": { + "$ref": "#/definitions/version", + "description": "対応するKPMのバージョンです。このバージョンより古いKPMではプラグインを読み込めません。", + "examples": [ + "3.0.0", + "v3.0-pre1" + ] + } + }, + "required": [ + "kpm" + ], + "additionalProperties": false +} From bfc1561bead1e3608b078ab74952b534f8977128 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 17 Oct 2022 23:16:55 +0900 Subject: [PATCH 392/745] docs: key docs --- .../lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java | 1 + 1 file changed, 1 insertion(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java index 7f482ce7..3739dc7a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java @@ -32,6 +32,7 @@ public class KPMInformationFile /** * 対応するKPMのバージョンです。 * このバージョンより古いKPMではこの情報ファイルを読み込むことができません。 + * YAMLのキーは{@code kpm}です。 */ Version kpmVersion; From 69b39b27fafde06e3a27e5673eb6b1bc6559c301 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 20 Oct 2022 18:30:06 +0900 Subject: [PATCH 393/745] fix: Pre-release version judged as equal as non-pre-release version --- .../teamkunpluginmanager/utils/versioning/Version.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java index 50b31feb..5450011c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java @@ -163,17 +163,22 @@ else if (patchCompare != 0) if (this.preRelease != null) { if (o.preRelease == null) - return 1; + return -1; else return this.preRelease.compareTo(o.preRelease); } - else if (this.buildMetadata != null) + else if (o.preRelease != null) + return 1; + + if (this.buildMetadata != null) { if (o.buildMetadata == null) return 1; else return this.buildMetadata.compareTo(o.buildMetadata); } + else if (o.buildMetadata != null) + return -1; return 0; } From 00d015ed7ef8dd79d051a35e032da5a5efea4ae1 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 20 Oct 2022 19:54:19 +0900 Subject: [PATCH 394/745] refactor: Change version predicate method name --- .../installer/impls/install/PluginInstaller.java | 2 +- .../teamkunpluginmanager/utils/versioning/Version.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index 5062782e..e4c596b8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -185,7 +185,7 @@ private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescripti return InstallErrorCause.INCOMPATIBLE_API_VERSION; } - if (kpmInfo.getKpmVersion().isGreaterThanOrEqualTo(this.daemon.getVersion())) + if (kpmInfo.getKpmVersion().isOlderThan(this.daemon.getVersion())) { PluginIncompatibleWithKPMSignal incompatibleSignal = new PluginIncompatibleWithKPMSignal(pluginDescription, kpmInfo, this.daemon.getVersion()); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java index 5450011c..c0f17d55 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java @@ -103,22 +103,22 @@ public boolean isPreRelease() return this.preRelease != null; } - public boolean isGreaterThan(@Nonnull Version other) + public boolean isNewerThan(@Nonnull Version other) { return this.compareTo(other) > 0; } - public boolean isLessThan(@Nonnull Version other) + public boolean isOlderThan(@Nonnull Version other) { return this.compareTo(other) < 0; } - public boolean isGreaterThanOrEqualTo(@Nonnull Version other) + public boolean isNewerThanOrEqualTo(@Nonnull Version other) { return this.compareTo(other) >= 0; } - public boolean isLessThanOrEqualTo(@Nonnull Version other) + public boolean isOlderThanOrEqualTo(@Nonnull Version other) { return this.compareTo(other) <= 0; } From 5ff080ce2b1e46f1ed2d247c40b7230f83165092 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 20 Oct 2022 19:58:40 +0900 Subject: [PATCH 395/745] refactor: Change version create method name --- .../lab/teamkunpluginmanager/KPMDaemon.java | 2 +- .../kpminfo/KPMInformationFile.java | 19 +++++++------ .../InvalidVersionSyntaxException.java | 2 +- .../utils/versioning/Version.java | 27 ++----------------- 4 files changed, 15 insertions(+), 35 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 649483ef..1db70d99 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -180,6 +180,6 @@ public void shutdown() public Version getVersion() { - return Version.ofUnsafe(this.getEnvs().getPlugin().getDescription().getVersion()); + return Version.of(this.getEnvs().getPlugin().getDescription().getVersion()); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java index 3739dc7a..50bc789c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java @@ -70,15 +70,18 @@ private static KPMInformationFile loadFromMap(Map map) throws InvalidInfor Version version; // region Parse kpm => kpmVersion [required] - if (!map.containsKey("kpm")) - throw new InvalidInformationFileException("kpm is not found."); - - Object kpmVersionObj = map.get("kpm"); - if (!(kpmVersionObj instanceof String)) - throw new InvalidInformationFileException("kpmVersion is not a string."); + if (map.containsKey("kpm")) + { + Object kpmVersionObj = map.get("kpm"); + if (!(kpmVersionObj instanceof String)) + throw new InvalidInformationFileException("kpmVersion is not a string."); - if ((version = Version.of((String) kpmVersionObj)) == null) - throw new InvalidInformationFileException("Invalid syntax of kpm version: " + kpmVersionObj); + if (Version.isValidVersionString((String) kpmVersionObj)) + throw new InvalidInformationFileException("Invalid syntax of kpm version: " + kpmVersionObj); + version = Version.of((String) kpmVersionObj); + } + else + throw new InvalidInformationFileException("kpm is not found."); // endregion return new KPMInformationFile(version); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java index 8dc962c3..8a8391fb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java @@ -3,7 +3,7 @@ /** * バージョンの構文が不正な場合に投げられる例外です。 */ -public class InvalidVersionSyntaxException extends Exception +public class InvalidVersionSyntaxException extends IllegalArgumentException { public InvalidVersionSyntaxException(String message) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java index c0f17d55..c73214d9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java @@ -69,33 +69,10 @@ public static boolean isValidVersionString(@NotNull String versionString) return VERSION_PATTERN.matcher(versionString).find(); } - @Nullable - public static Version of(@NotNull String rawVersion) - { - if (rawVersion.isEmpty() || !isValidVersionString(rawVersion)) - return null; - - try - { - return compileVersion(rawVersion); - } - catch (InvalidVersionSyntaxException e) - { - return null; - } - } - @NotNull - public static Version ofUnsafe(@NotNull String rawVersion) + public static Version of(@NotNull String rawVersion) throws InvalidVersionSyntaxException { - try - { - return compileVersion(rawVersion); - } - catch (InvalidVersionSyntaxException e) - { - throw new IllegalArgumentException(e); - } + return compileVersion(rawVersion); } public boolean isPreRelease() From 2fa72e7487130179c3e12d84e2641ed7a13f3e23 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 20 Oct 2022 20:05:02 +0900 Subject: [PATCH 396/745] test: Version test --- .../utils/versioning/VersionTest.java | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 KPMDaemon/src/test/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionTest.java diff --git a/KPMDaemon/src/test/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionTest.java b/KPMDaemon/src/test/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionTest.java new file mode 100644 index 00000000..a531c31d --- /dev/null +++ b/KPMDaemon/src/test/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionTest.java @@ -0,0 +1,151 @@ +package net.kunmc.lab.teamkunpluginmanager.utils.versioning; + +import org.junit.jupiter.api.Test; + +import java.util.Random; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +@SuppressWarnings("NonAsciiCharacters") +public class VersionTest +{ + + private static void testVersionEqual(int maj, int min, int pat, String pre, String build, Version version) + { + System.out.println("Testing:"); + System.out.println(" Major: " + maj); + System.out.println(" Major (from Version): " + version.getMajor().getIntValue() + "(" + version.getMajor().getRawValue() + ")"); + System.out.println(" Minor: " + min); + System.out.println(" Minor (from Version): " + version.getMinor().getIntValue() + "(" + version.getMinor().getRawValue() + ")"); + System.out.println(" Patch: " + pat); + System.out.println(" Patch (from Version): " + version.getPatch().getIntValue() + "(" + version.getPatch().getRawValue() + ")"); + + if (pre != null) + { + System.out.println(" Pre release: " + pre); + System.out.println(" Pre release (from Version): " + version.getPreRelease()); + assertTrue(version.isPreRelease()); + // noinspection ConstantConditions + assertEquals(pre, version.getPreRelease().getRawValue()); + } + + if (build != null) + { + System.out.println(" Build: " + build); + assertNotNull(version.getBuildMetadata(), "Expected the version to have build metadata"); + System.out.println(" Build (from Version): " + version.getBuildMetadata().getRawValue()); + assertEquals(build, version.getBuildMetadata().getRawValue()); + } + + assertEquals(maj, version.getMajor().getIntValue()); + assertEquals(min, version.getMinor().getIntValue()); + assertEquals(pat, version.getPatch().getIntValue()); + + System.out.println("=============="); + } + + private static void checkVersion(boolean isOlderExcepted, Version base, Version target) + { + if (isOlderExcepted) + { + assertTrue(base.isOlderThan(target)); + assertFalse(target.isOlderThan(base)); + assertTrue(target.isNewerThan(base)); + assertFalse(base.isNewerThan(target)); + } + else + { + assertTrue(target.isOlderThan(base)); + assertFalse(base.isOlderThan(target)); + assertTrue(base.isNewerThan(target)); + assertFalse(target.isNewerThan(base)); + } + } + + @Test + void バージョンが正しくパースされるか() + { + for (int i = 0; i < 10; i++) + { + Random random = new Random(); + StringBuilder versionString = new StringBuilder(); + int maj = random.nextInt(100); + int min = random.nextInt(100); + int pat = random.nextInt(100); + + versionString.append(String.format("%d.%d.%d", maj, min, pat)); + + String pre = null; + if (random.nextBoolean()) + { + pre = UUID.randomUUID().toString().replace("-", ""); + versionString.append("-").append(pre); + } + String build = null; + if (random.nextBoolean()) + { + build = UUID.randomUUID().toString().replace("-", ""); + versionString.append("+").append(build); + } + + Version version = Version.of(versionString.toString()); + + assertNotNull(version, "Expected the version to be non-null"); + + testVersionEqual(maj, min, pat, pre, build, version); + } + } + + @Test + void バージョン同士の大小比較ができるか() + { + for (int i = 0; i < 10; i++) + { + Random random = new Random(); + int seed1 = random.nextInt(100); + int seed2 = random.nextInt(100); + if (seed1 == seed2) + seed2++; + + boolean isOlder = seed1 < seed2; + + Version version1 = Version.of(String.format("v%d.0.0", seed1)); + Version version2 = Version.of(String.format("v%d.0.0", seed2)); + checkVersion(isOlder, version1, version2); + + version1 = Version.of(String.format("v0.%d.0", seed1)); + version2 = Version.of(String.format("v0.%d.0", seed2)); + checkVersion(isOlder, version1, version2); + + version1 = Version.of(String.format("v0.0.%d", seed1)); + version2 = Version.of(String.format("v0.0.%d", seed2)); + checkVersion(isOlder, version1, version2); + } + } + + @Test + void プレリリースが下方バージョンと判定されるか() + { + for (int i = 0; i < 10; i++) + { + + Random random = new Random(); + StringBuilder versionString = new StringBuilder(); + StringBuilder lesserVersionString = new StringBuilder(); + int maj = random.nextInt(100); + int min = random.nextInt(100); + int pat = random.nextInt(100); + + Version version = + Version.of(versionString.append(String.format("%d.%d.%d", maj, min, pat)).toString()); + lesserVersionString.append(version); + lesserVersionString.append("-").append(UUID.randomUUID().toString().replaceAll("-", "")); + + Version lesserAsVersion = Version.of(lesserVersionString.toString()); + + assertEquals(-1, lesserAsVersion.compareTo(version)); + assertEquals(1, version.compareTo(lesserAsVersion)); + } + } +} From 9cd202163b3b30ca0cfd9f27d9b3b027c9d4aa18 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 20 Oct 2022 20:13:05 +0900 Subject: [PATCH 397/745] feat: VersionElement toString --- .../utils/versioning/VersionElement.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java index eaf4a14a..b1830fb9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java @@ -11,9 +11,16 @@ @Getter public class VersionElement implements Comparable { + /** + * 生のバージョン要素です。 + */ @NotNull private final String rawValue; + /** + * int型に変換されたバージョン要素です。 + * 変換できない場合は-1が代入されます。 + */ private final int intValue; public VersionElement(@NotNull String rawValue) @@ -41,4 +48,10 @@ public int compareTo(@Nonnull VersionElement o) else return this.rawValue.compareTo(o.rawValue); } + + @Override + public String toString() + { + return this.rawValue; + } } From 3376fbcfcaf68ca5bdecf9f6189f2a1df56958dd Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 20 Oct 2022 20:20:17 +0900 Subject: [PATCH 398/745] refactor: Migrate info loading methods to KPMInfoParser --- .../kpminfo/KPMInfoManager.java | 2 +- .../kpminfo/KPMInfoParser.java | 75 +++++++++++++++++++ .../kpminfo/KPMInformationFile.java | 70 +---------------- 3 files changed, 77 insertions(+), 70 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java index 67024e88..36381ef5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java @@ -37,7 +37,7 @@ public KPMInformationFile loadInfo(@NotNull Path path, @NotNull PluginDescriptio KPMInformationFile info = null; try { - info = KPMInformationFile.load(path); + info = KPMInfoParser.load(path); this.lookupNames.put(descriptionFile.getName(), info); } catch (InvalidInformationFileException e) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java new file mode 100644 index 00000000..bb88c364 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java @@ -0,0 +1,75 @@ +package net.kunmc.lab.teamkunpluginmanager.kpminfo; + +import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import org.jetbrains.annotations.NotNull; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.Map; +import java.util.zip.ZipFile; + +public class KPMInfoParser +{ + private static final Yaml YAML_PARSER; + + static + { + YAML_PARSER = new Yaml(); + } + + @NotNull + public static KPMInformationFile load(InputStream stream) throws InvalidInformationFileException + { + return loadFromMap(YAML_PARSER.load(stream)); + } + + @NotNull + public static KPMInformationFile load(Path jarFile) throws InvalidInformationFileException, FileNotFoundException + { + File file = jarFile.toFile(); + if (!file.exists()) + throw new FileNotFoundException("File not found: " + file.getAbsolutePath()); + + try (ZipFile zip = new ZipFile(file)) + { + InputStream stream = zip.getInputStream(zip.getEntry("kpm.yml")); + if (stream == null) + throw new InvalidInformationFileException("kpm.yml not found in " + file.getAbsolutePath()); + + return load(stream); + } + catch (IOException e) + { + throw new InvalidInformationFileException("Failed to load kpm.yml from " + file.getAbsolutePath(), e); + } + } + + private static KPMInformationFile loadFromMap(Map map) throws InvalidInformationFileException + { + if (map == null) + throw new InvalidInformationFileException("Information file is empty."); + + Version version; + // region Parse kpm => kpmVersion [required] + if (map.containsKey("kpm")) + { + Object kpmVersionObj = map.get("kpm"); + if (!(kpmVersionObj instanceof String)) + throw new InvalidInformationFileException("kpmVersion is not a string."); + + if (Version.isValidVersionString((String) kpmVersionObj)) + throw new InvalidInformationFileException("Invalid syntax of kpm version: " + kpmVersionObj); + version = Version.of((String) kpmVersionObj); + } + else + throw new InvalidInformationFileException("kpm is not found."); + // endregion + + return new KPMInformationFile(version); + + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java index 50bc789c..578a90f7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java @@ -4,30 +4,14 @@ import lombok.AllArgsConstructor; import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; -import org.jetbrains.annotations.NotNull; -import org.yaml.snakeyaml.Yaml; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.Map; -import java.util.zip.ZipFile; /** * KPMの情報ファイルを表すクラスです。 */ @Value -@AllArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PACKAGE) public class KPMInformationFile { - private static final Yaml YAML_PARSER; - - static - { - YAML_PARSER = new Yaml(); - } /** * 対応するKPMのバージョンです。 @@ -36,56 +20,4 @@ public class KPMInformationFile */ Version kpmVersion; - @NotNull - public static KPMInformationFile load(InputStream stream) throws InvalidInformationFileException - { - return loadFromMap(YAML_PARSER.load(stream)); - } - - @NotNull - public static KPMInformationFile load(Path jarFile) throws InvalidInformationFileException, FileNotFoundException - { - File file = jarFile.toFile(); - if (!file.exists()) - throw new FileNotFoundException("File not found: " + file.getAbsolutePath()); - - try (ZipFile zip = new ZipFile(file)) - { - InputStream stream = zip.getInputStream(zip.getEntry("kpm.yml")); - if (stream == null) - throw new InvalidInformationFileException("kpm.yml not found in " + file.getAbsolutePath()); - - return load(stream); - } - catch (IOException e) - { - throw new InvalidInformationFileException("Failed to load kpm.yml from " + file.getAbsolutePath(), e); - } - } - - private static KPMInformationFile loadFromMap(Map map) throws InvalidInformationFileException - { - if (map == null) - throw new InvalidInformationFileException("Information file is empty."); - - Version version; - // region Parse kpm => kpmVersion [required] - if (map.containsKey("kpm")) - { - Object kpmVersionObj = map.get("kpm"); - if (!(kpmVersionObj instanceof String)) - throw new InvalidInformationFileException("kpmVersion is not a string."); - - if (Version.isValidVersionString((String) kpmVersionObj)) - throw new InvalidInformationFileException("Invalid syntax of kpm version: " + kpmVersionObj); - version = Version.of((String) kpmVersionObj); - } - else - throw new InvalidInformationFileException("kpm is not found."); - // endregion - - return new KPMInformationFile(version); - - } - } From 5cc2af9e445a7c4e4a083cb6e82490f3ab745675 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 22 Oct 2022 15:52:04 +0900 Subject: [PATCH 399/745] feat: Update query in kpm file --- .../impls/install/InstallErrorCause.java | 4 +- .../impls/install/PluginInstaller.java | 29 ++--------- .../impls/uninstall/PluginUninstaller.java | 3 +- .../tasks/dependencies/DependencyElement.java | 25 +++------ .../collector/DependsCollectTask.java | 52 +++++++++++-------- .../tasks/install/PluginsInstallArgument.java | 5 +- .../install/PluginsInstallErrorCause.java | 8 +++ .../tasks/install/PluginsInstallTask.java | 50 ++++++++++++++++-- .../PluginIncompatibleWithKPMSignal.java | 2 +- .../kpminfo/KPMInfoManager.java | 34 ++++++++++++ .../kpminfo/KPMInfoParser.java | 32 ++++++++---- .../kpminfo/KPMInformationFile.java | 12 ++++- .../resolver/QueryContext.java | 14 +++++ .../common/CheckEnvSignalHandler.java | 2 +- 14 files changed, 186 insertions(+), 86 deletions(-) rename KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/{impls => task/tasks}/install/signals/PluginIncompatibleWithKPMSignal.java (94%) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java index 4162900e..cd180e23 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java @@ -1,5 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; + /** * インストールのエラーを表す列挙型です。 */ @@ -22,7 +24,7 @@ public enum InstallErrorCause INCOMPATIBLE_API_VERSION, /** * プラグインのKPM指定バージョンと、このKPMのバージョンが互換性がなく、 - * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.PluginIncompatibleWithKPMSignal} でも強制インストールが選択されませんでした。 + * {@link PluginIncompatibleWithKPMSignal} でも強制インストールが選択されませんでした。 */ INCOMPATIBLE_KPM_VERSION, } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index e4c596b8..bf6bd2d3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -5,7 +5,6 @@ import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.PluginIncompatibleWithKPMSignal; import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; @@ -93,15 +92,13 @@ public InstallResult execute(@NotNull InstallArgument argument) th // Load kpmInfo KPMInformationFile kpmInfo = this.daemon.getKpmInfoManager().loadInfo(pluginFilePath, pluginDescription); - if (kpmInfo == null) - return null; // No kpmInfo file. boolean replacePlugin = false; // region Do assertions. this.progress.setCurrentTask(InstallTasks.CHECKING_ENVIRONMENT); - InstallErrorCause checkEnvErrorResult = this.checkEnvironment(pluginDescription, kpmInfo); + InstallErrorCause checkEnvErrorResult = this.checkEnvironment(pluginDescription); if (checkEnvErrorResult != null) return this.error(checkEnvErrorResult); @@ -146,7 +143,7 @@ public InstallResult execute(@NotNull InstallArgument argument) th new PluginsInstallTask(this) ) .bridgeArgument(result -> new PluginsInstallArgument( - pluginFilePath, pluginDescription, query, result.getOrder() + pluginFilePath, pluginDescription, kpmInfo, result.getOrder() )) .submitAll(new DependsCollectArgument(pluginDescription)); // endregion @@ -160,8 +157,7 @@ public InstallResult execute(@NotNull InstallArgument argument) th } @Nullable - @SuppressWarnings("deprecation") - private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescription, KPMInformationFile kpmInfo) + private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescription) { String pluginName = pluginDescription.getName(); @@ -177,25 +173,6 @@ private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescripti } // endregion - // region Check if the plugin is incompatible with the server. - if (pluginDescription.getAPIVersion() != null) - { - String apiVersion = pluginDescription.getAPIVersion(); - if (!Bukkit.getUnsafe().isSupportedApiVersion(apiVersion)) - return InstallErrorCause.INCOMPATIBLE_API_VERSION; - } - - if (kpmInfo.getKpmVersion().isOlderThan(this.daemon.getVersion())) - { - PluginIncompatibleWithKPMSignal incompatibleSignal = - new PluginIncompatibleWithKPMSignal(pluginDescription, kpmInfo, this.daemon.getVersion()); - this.postSignal(incompatibleSignal); - - if (!incompatibleSignal.isForceInstall()) - return InstallErrorCause.INCOMPATIBLE_KPM_VERSION; - } - // endregion - return null; // No error with environment. } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java index 0ad81132..6d8828f6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java @@ -123,7 +123,8 @@ public InstallResult execute(@NotNull UninstallArgument argument String name = descriptionFile.getName(); Path path = PluginUtil.getFile(pl).toPath(); - return new DependencyElement(name, path, descriptionFile, null); + // Dummy element + return new DependencyElement(name, path, descriptionFile, null, null); }) .collect(Collectors.toList()); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java index 2fafc363..ae4ce5f4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java @@ -2,7 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,28 +32,15 @@ public class DependencyElement */ @NotNull PluginDescriptionFile pluginDescription; + /** + * 依存関係のKPM情報ファイルです。 + */ + @Nullable + KPMInformationFile kpmInfoFile; /** * 依存関係の解決に使用したクエリです。 */ @Nullable String query; - - public DependencyElement(@NotNull String pluginName, @NotNull Path pluginPath, @NotNull String query) - { - this.pluginName = pluginName; - this.pluginPath = pluginPath; - this.query = query; - - try - { - this.pluginDescription = PluginUtil.loadDescription(pluginPath.toFile()); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 6ef33289..bd4b6b46 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -18,9 +18,9 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveResult; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.Pair; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.PluginDescriptionFile; @@ -32,7 +32,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; /** @@ -53,7 +52,6 @@ public class DependsCollectTask extends InstallTask { // TODO: きれいに private final KPMDaemon daemon; - private final SignalHandleManager signalHandler; private final DependsCollectStatus status; private DependsCollectState taskState; @@ -63,7 +61,6 @@ public DependsCollectTask(@NotNull AbstractInstaller installer) super(installer.getProgress(), installer.getProgress().getSignalHandler()); this.daemon = installer.getDaemon(); - this.signalHandler = installer.getProgress().getSignalHandler(); this.status = this.progress.getDependsCollectStatus(); this.taskState = DependsCollectState.INITIALIZED; @@ -107,16 +104,15 @@ public DependsCollectTask(@NotNull AbstractInstaller installer) // region Collect dependency's dependencies (Recursive via collectDependsDepends) this.taskState = DependsCollectState.COLLECTING_DEPENDS_DEPENDS; - HashMap dependsDescriptions = this.downloadResultsToPluginDescriptionFiles(downloadResults); + HashMap dependsDescriptions = this.downloadResultsToDependencyElement(downloadResults); // Remove failed dependencies from load description results dependsDescriptions.entrySet().removeIf(entry -> entry.getValue() == null); dependsDescriptions.entrySet().stream() - .filter(entry -> Objects.nonNull(entry.getValue())) .filter(entry -> downloadResults.containsKey(entry.getKey())) - .forEach(entry -> { - String exceptedName = entry.getValue().getName(); + .forEach((entry) -> { + String exceptedName = entry.getValue().getPluginName(); String actualName = entry.getKey(); if (!exceptedName.equals(actualName)) { @@ -124,13 +120,9 @@ public DependsCollectTask(@NotNull AbstractInstaller installer) return; } - Path pluginPath = downloadResults.get(actualName).getPath(); - this.status.onCollect( exceptedName, - new DependencyElement(exceptedName, pluginPath, - entry.getValue(), exceptedName - ) + entry.getValue() ); }); @@ -166,14 +158,15 @@ private DependsCollectResult passCollector(@NotNull PluginDescriptionFile plugin .runTask(arguments); } - private void collectDependsDepends(@NotNull HashMap dependsDescriptions, + private void collectDependsDepends(@NotNull HashMap dependencies, @NotNull List alreadyCollectedPlugins) { List alreadyCollected = new ArrayList<>(alreadyCollectedPlugins); - for (Map.Entry entry : dependsDescriptions.entrySet()) + for (Map.Entry entry : dependencies.entrySet()) { - DependsCollectResult dependsCollectResult = this.passCollector(entry.getValue(), alreadyCollected); + DependsCollectResult dependsCollectResult = + this.passCollector(entry.getValue().getPluginDescription(), alreadyCollected); if (!dependsCollectResult.isSuccess()) { @@ -202,22 +195,39 @@ private PluginDescriptionFile downloadResultToPluginDescriptionFile(@NotNull Dow } } - private HashMap downloadResultsToPluginDescriptionFiles( + private HashMap downloadResultsToDependencyElement( @NotNull Map downloadResults) { - HashMap pluginDescriptionFiles = new HashMap<>(); + HashMap dependencyElements = new HashMap<>(); for (Map.Entry entry : downloadResults.entrySet()) { PluginDescriptionFile pluginDescriptionFile = this.downloadResultToPluginDescriptionFile(entry.getValue()); - if (pluginDescriptionFile == null) + { this.postSignal(new DependencyLoadDescriptionFailedSignal(entry.getKey())); + continue; + } + + KPMInformationFile kpmInfoFile; + if (this.daemon.getKpmInfoManager().hasInfo(entry.getValue().getPath())) + kpmInfoFile = this.daemon.getKpmInfoManager().loadInfo(entry.getValue().getPath(), pluginDescriptionFile); + else + kpmInfoFile = null; + + String query; + if (kpmInfoFile != null && kpmInfoFile.getUpdateQuery() != null) + query = kpmInfoFile.getUpdateQuery().getQuery(); else - pluginDescriptionFiles.put(entry.getKey(), pluginDescriptionFile); + query = pluginDescriptionFile.getName(); + + dependencyElements.put(entry.getKey(), new DependencyElement( + pluginDescriptionFile.getName(), entry.getValue().getPath(), + pluginDescriptionFile, kpmInfoFile, query + )); } - return pluginDescriptionFiles; + return dependencyElements; } private DownloadResult passDownloader(@NotNull String url) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java index 8430ad57..a4a8ec95 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java @@ -4,6 +4,7 @@ import lombok.Value; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,10 +30,10 @@ public class PluginsInstallArgument extends TaskArgument @NotNull PluginDescriptionFile pluginDescription; /** - * プラグインの解決に使用したクエリです。 + * プラグインのKPM情報ファイルです。 */ @Nullable - String query; + KPMInformationFile kpmInformation; /** * 依存関係の要素です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java index 41047614..028890f4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java @@ -17,6 +17,14 @@ public enum PluginsInstallErrorCause * 無効なプラグイン情報ファイルが指定されました。 */ INVALID_PLUGIN_DESCRIPTION, + /** + * プラグインがこのサーバに互換性がありません。 + */ + INCOMPATIBLE_WITH_BUKKIT_VERSION, + /** + * プラグインがこのKPMに互換性がありません。 + */ + INCOMPATIBLE_WITH_KPM_VERSION, /** * {@link java.io.IOException} が発生しました。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java index b98ba1d3..c07c7ad3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java @@ -6,14 +6,17 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginInstallingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginLoadSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; import net.kunmc.lab.teamkunpluginmanager.loader.CommandsPatcher; import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; +import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.entity.Player; @@ -90,7 +93,7 @@ private static void patchPluginCommands(List targets) Path path = dependency.getPluginPath(); PluginsInstallResult result = - this.installOne(path, pluginDescription, dependency.getQuery(), + this.installOne(path, pluginDescription, dependency.getKpmInfoFile(), installedPlugins, true ); if (!result.isSuccess()) // installOne returns null if installation is failed @@ -104,7 +107,7 @@ private static void patchPluginCommands(List targets) PluginsInstallResult result = this.installOne(arguments.getPluginPath(), arguments.getPluginDescription(), - arguments.getQuery(), installedPlugins, false + arguments.getKpmInformation(), installedPlugins, false ); if (result.isSuccess() && result.getInstalledPlugin() != null) @@ -120,10 +123,14 @@ private static void patchPluginCommands(List targets) @NotNull private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription, - @Nullable String query, @NotNull List installedPlugins, boolean isDependency) + @Nullable KPMInformationFile kpmInformationFile, @NotNull List installedPlugins, boolean isDependency) { this.postSignal(new PluginInstallingSignal(path, pluginDescription)); + PluginsInstallErrorCause checkEnvError; + if ((checkEnvError = this.checkEnv(pluginDescription, kpmInformationFile)) != null) + return new PluginsInstallResult(false, this.state, checkEnvError); + this.state = PluginsInstallState.PLUGIN_RELOCATING; // Relocate plugin @@ -179,6 +186,12 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr installedPlugins.add(target); + String query; + if (kpmInformationFile != null && kpmInformationFile.getUpdateQuery() != null) + query = kpmInformationFile.getUpdateQuery().toString(); + else + query = null; + this.pluginMetaManager.onInstalled( target, isDependency ? InstallOperator.KPM_DEPENDENCY_RESOLVER: InstallOperator.SERVER_ADMIN, @@ -256,4 +269,35 @@ private PluginsInstallResult movePlugin(@NotNull Path source, @NotNull Path targ return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.RELOCATE_FAILED); } } + + @Nullable + @SuppressWarnings("deprecation") + private PluginsInstallErrorCause checkEnv(PluginDescriptionFile pluginDescription, @Nullable KPMInformationFile kpmInformation) + { + + if (pluginDescription.getAPIVersion() != null) + { + String apiVersion = pluginDescription.getAPIVersion(); + if (!Bukkit.getUnsafe().isSupportedApiVersion(apiVersion)) + return PluginsInstallErrorCause.INCOMPATIBLE_WITH_KPM_VERSION; + } + + if (kpmInformation == null) + return null; + + Version daemonVersion = this.progress.getInstaller().getDaemon().getVersion(); + + if (kpmInformation.getKpmVersion().isOlderThan(daemonVersion)) + { + PluginIncompatibleWithKPMSignal incompatibleSignal = + new PluginIncompatibleWithKPMSignal(pluginDescription, kpmInformation, daemonVersion); + this.postSignal(incompatibleSignal); + + if (!incompatibleSignal.isForceInstall()) + return PluginsInstallErrorCause.INCOMPATIBLE_WITH_KPM_VERSION; + + } + + return null; + } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/PluginIncompatibleWithKPMSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java similarity index 94% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/PluginIncompatibleWithKPMSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java index b2a167cf..517cd677 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/PluginIncompatibleWithKPMSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals; +package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals; import lombok.Data; import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java index 36381ef5..cb1c21ea 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java @@ -1,6 +1,7 @@ package net.kunmc.lab.teamkunpluginmanager.kpminfo; import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; +import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -9,6 +10,7 @@ import java.io.FileNotFoundException; import java.nio.file.Path; import java.util.HashMap; +import java.util.zip.ZipFile; /** * KPM情報ファイルを管理するクラスです。 @@ -78,6 +80,38 @@ public KPMInformationFile getInfo(@NotNull String pluginName) return this.lookupNames.get(pluginName); } + /** + * プラグインが KPM情報ファイルを持っているかどうかを取得します。 + * + * @param plugin プラグイン名 + * @return プラグインが KPM情報ファイルを持っているかどうか + */ + public boolean hasInfo(@NotNull Plugin plugin) + { + if (this.lookupNames.containsKey(plugin.getDescription().getName())) + return true; + + return this.hasInfo(PluginUtil.getFile(plugin).toPath()); + } + + /** + * プラグインが KPM情報ファイルを持っているかどうかを取得します。 + * + * @param pluginFile プラグインのファイル + * @return プラグインが KPM情報ファイルを持っているかどうか + */ + public boolean hasInfo(@NotNull Path pluginFile) + { + try (ZipFile zipFile = new ZipFile(pluginFile.toFile())) + { + return zipFile.getEntry("kpm.info") != null; + } + catch (Exception e) + { + return false; + } + } + /** * プラグインのKPM情報ファイルを削除します。 * diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java index bb88c364..85c6d12b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java @@ -1,7 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.kpminfo; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.yaml.snakeyaml.Yaml; import java.io.File; @@ -48,28 +50,40 @@ public static KPMInformationFile load(Path jarFile) throws InvalidInformationFil } } + @NotNull private static KPMInformationFile loadFromMap(Map map) throws InvalidInformationFileException { if (map == null) throw new InvalidInformationFileException("Information file is empty."); - Version version; - // region Parse kpm => kpmVersion [required] + Version version = parseVersion(map); // Parse kpm => kpmVersion [required] + QueryContext updateQuery = parseUpdateQuery(map); // Parse update => updateQuery [required] + + return new KPMInformationFile(version, updateQuery); + } + + @NotNull + private static Version parseVersion(Map map) throws InvalidInformationFileException + { if (map.containsKey("kpm")) { Object kpmVersionObj = map.get("kpm"); - if (!(kpmVersionObj instanceof String)) - throw new InvalidInformationFileException("kpmVersion is not a string."); - - if (Version.isValidVersionString((String) kpmVersionObj)) + if (Version.isValidVersionString(kpmVersionObj.toString())) throw new InvalidInformationFileException("Invalid syntax of kpm version: " + kpmVersionObj); - version = Version.of((String) kpmVersionObj); + return Version.of((String) kpmVersionObj); } else throw new InvalidInformationFileException("kpm is not found."); - // endregion - return new KPMInformationFile(version); + } + + @Nullable + private static QueryContext parseUpdateQuery(Map map) + { + if (!map.containsKey("update")) + return null; + Object updateQueryObj = map.get("update"); + return QueryContext.fromString(updateQueryObj.toString()); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java index 578a90f7..e516d075 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java @@ -3,7 +3,10 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Value; +import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * KPMの情報ファイルを表すクラスです。 @@ -12,12 +15,17 @@ @AllArgsConstructor(access = AccessLevel.PACKAGE) public class KPMInformationFile { - /** * 対応するKPMのバージョンです。 * このバージョンより古いKPMではこの情報ファイルを読み込むことができません。 * YAMLのキーは{@code kpm}です。 */ + @NotNull Version kpmVersion; - + /** + * アップデートで使用するクエリです。 + * YAMLのキーは{@code update}です。 + */ + @Nullable + QueryContext updateQuery; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java index 316bd4ea..abaec961 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java @@ -63,4 +63,18 @@ public static QueryContext fromString(@NotNull String query) return new QueryContext(resolverName, plainQuery, version); } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + + if (this.resolverName != null) + sb.append(this.resolverName).append(resolverNameQuerySeparator); + sb.append(this.query); + if (this.version != null) + sb.append(versionEqualQuerySeparator).append(this.version); + + return sb.toString(); + } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java index 5aced915..ab5a6633 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java @@ -2,8 +2,8 @@ import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.PluginIncompatibleWithKPMSignal; import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; From 87baeb6a3d53326f57cd43de3c5ef925034b1e4c Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 22 Oct 2022 21:44:38 +0900 Subject: [PATCH 400/745] refactor: Change error handling(install) --- .../installer/impls/install/InstallErrorCause.java | 10 ---------- .../intall/InstallFinishedSignalHandler.java | 12 ++++++------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java index cd180e23..f0a67542 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java @@ -1,6 +1,5 @@ package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; /** * インストールのエラーを表す列挙型です。 @@ -18,13 +17,4 @@ public enum InstallErrorCause * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 */ PLUGIN_ALREADY_INSTALLED, - /** - * プラグインのapi-versionが、このサーバーバージョンと互換性がありません。 - */ - INCOMPATIBLE_API_VERSION, - /** - * プラグインのKPM指定バージョンと、このKPMのバージョンが互換性がなく、 - * {@link PluginIncompatibleWithKPMSignal} でも強制インストールが選択されませんでした。 - */ - INCOMPATIBLE_KPM_VERSION, } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java index 745cae44..32c64cfc 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -41,12 +41,6 @@ private boolean handleGeneralErrors(@Nullable InstallErrorCause cause) case PLUGIN_ALREADY_INSTALLED: this.terminal.error("指定されたプラグインは既にインストールされています。"); return true; - case INCOMPATIBLE_API_VERSION: - this.terminal.error("指定されたプラグインは、このサーバーバージョンと互換性がありません(プラグインのapi-versionがより新しい可能性があります)。"); - return true; - case INCOMPATIBLE_KPM_VERSION: - this.terminal.error("指定されたプラグインは、このKPMのバージョンと互換性がありません。"); - return true; } return false; @@ -126,6 +120,12 @@ private void handleInstallError(PluginsInstallErrorCause cause) case INVALID_PLUGIN_DESCRIPTION: this.terminal.error("不正なプラグイン情報ファイルが含まれています。"); break; + case INCOMPATIBLE_WITH_BUKKIT_VERSION: + this.terminal.error("指定されたプラグインは、このサーバのバージョンと互換性がありません(プラグインのapi-versionがより新しい可能性があります)。"); + break; + case INCOMPATIBLE_WITH_KPM_VERSION: + this.terminal.error("指定されたプラグインは、この KPM のバージョンと互換性がありません。"); + break; case IO_EXCEPTION_OCCURRED: this.terminal.error("プラグインのインストール中に I/O エラーが発生しました。"); break; From 5aab4c28829956865f03b1a703c5746199d8dbc5 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 22 Oct 2022 22:57:04 +0900 Subject: [PATCH 401/745] feat: Unused plugin meta deleting --- .../lab/teamkunpluginmanager/KPMDaemon.java | 49 +++++++- .../meta/PluginMetaIterator.java | 115 ++++++++++++++++++ .../meta/PluginMetaManager.java | 42 +++---- .../meta/PluginMetaProvider.java | 26 +++- .../utils/db/Transaction.java | 46 ++++++- 5 files changed, 246 insertions(+), 32 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaIterator.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java index 1db70d99..8a0b319b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java @@ -7,6 +7,9 @@ import net.kunmc.lab.teamkunpluginmanager.installer.InstallManager; import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInfoManager; import net.kunmc.lab.teamkunpluginmanager.loader.PluginLoader; +import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMeta; +import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaIterator; import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; import net.kunmc.lab.teamkunpluginmanager.resolver.impl.BruteforceGitHubResolver; @@ -16,12 +19,16 @@ import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import java.io.IOException; import java.nio.file.Path; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; /** * KPMのデーモンです。 @@ -123,7 +130,47 @@ public void setupDaemon(@NotNull Path dataFolder, @NotNull List organiza private void setupDependencyTree() { this.logger.info("Loading plugin meta data ..."); - this.pluginMetaManager.crawlAll(); + + List plugins = Arrays.asList(Bukkit.getPluginManager().getPlugins()); + List pluginNames = plugins.stream().parallel() + .map(Plugin::getName) + .map(String::toLowerCase) + .collect(Collectors.toList()); + + + try (PluginMetaIterator iterator = this.pluginMetaManager.getProvider().getPluginMetaIterator()) + { + while (iterator.hasNext()) + { + PluginMeta meta = iterator.next(); + + if (pluginNames.contains(meta.getName().toLowerCase())) + continue; + + + this.logger.info("Plugin {} is not loaded by server. Removing from database ...", meta.getName()); + iterator.remove(); + } + } + + for (Plugin plugin : plugins) + { + if (this.pluginMetaManager.hasPluginMeta(plugin)) + continue; + + this.pluginMetaManager.getProvider().savePluginMeta( + plugin, + InstallOperator.UNKNOWN, + System.currentTimeMillis(), + null, + false + ); + + this.logger.info("Plugin {} is not managed by KPM. Adding to database ...", plugin.getName()); + + this.pluginMetaManager.getProvider().buildDependencyTree(plugin); + } + } private void setupPluginResolvers(List organizationNames) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaIterator.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaIterator.java new file mode 100644 index 00000000..8ea986fc --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaIterator.java @@ -0,0 +1,115 @@ +package net.kunmc.lab.teamkunpluginmanager.meta; + +import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; +import org.bukkit.plugin.PluginLoadOrder; +import org.jetbrains.annotations.NotNull; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class PluginMetaIterator implements Iterator, AutoCloseable +{ + private final Transaction transaction; + private final Transaction.QueryResult results; + private final List removeTargets; + + private boolean hasNextCalled; + private boolean lastHasNextResult; + + public PluginMetaIterator(@NotNull PluginMetaProvider metaProvider, @NotNull Transaction transaction) + { + this.transaction = transaction.renew("SELECT * FROM plugin_meta"); + this.results = this.transaction.executeQuery() + .setMapper(row -> { + String name = row.getString("name"); + String version = row.getString("version"); + PluginLoadOrder loadTiming = PluginLoadOrder.valueOf(row.getString("load_timing")); + long installedAt = row.getLong("installed_at"); + InstallOperator installedBy = InstallOperator.valueOf(row.getString("installed_by")); + String resolveQuery = row.getString("resolve_query"); + boolean isDependency = row.getInt("is_dependency") == 1; + + List authors = metaProvider.getAuthors(name); + + List dependedBy = metaProvider.getDependedBy(name); + List dependsOn = metaProvider.getDependOn(name); + + dependedBy.addAll(metaProvider.getSoftDependedBy(name)); + dependsOn.addAll(metaProvider.getSoftDependOn(name)); + + dependedBy.addAll(metaProvider.getLoadBeforeBy(name)); + dependsOn.addAll(metaProvider.getLoadBefore(name)); + + return new PluginMeta( + name, + version, + loadTiming, + installedBy, + isDependency, + resolveQuery, + installedAt, + authors, + dependedBy, + dependsOn + ); + }); + this.removeTargets = new ArrayList<>(); + + this.hasNextCalled = false; + } + + @Override + public boolean hasNext() + { + this.hasNextCalled = true; + return this.lastHasNextResult = this.results.next(); + } + + @Override + public PluginMeta next() + { + if (this.hasNextCalled) + { + this.hasNextCalled = false; + return this.lastHasNextResult ? this.results.get(): null; + } + + return this.results.next() ? this.results.get(): null; + } + + @Override + public void close() + { + try + { + this.results.close(); + + Transaction transaction = this.transaction.renew("DELETE FROM plugin_meta WHERE name = ?"); + for (String name : this.removeTargets) + { + transaction.set(1, name); + transaction.executeUpdate(false); + } + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + finally + { + this.transaction.finishManually(); + } + } + + @Override + public void remove() + { + PluginMeta meta = this.results.get(); + if (meta == null) + throw new IllegalStateException("next() has not been called yet"); + + this.removeTargets.add(meta.getName()); + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java index cf244c79..c325efac 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java @@ -132,37 +132,35 @@ public void onInstalled(@NotNull Plugin plugin, @NotNull InstallOperator operato } /** - * すべてのプラグインのデータをクロールします。 + * プラグインがアンインストールされたときに呼び出します。 + * + * @param pluginName アンインストールされたプラグインの名前 */ - public void crawlAll() + public void onUninstalled(@NotNull String pluginName) { - Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); + this.provider.removePluginMeta(pluginName); + } - for (Plugin plugin : plugins) - { - if (this.provider.isPluginMetaExists(plugin.getName())) - continue; - - this.provider.savePluginMeta( - plugin, - InstallOperator.UNKNOWN, - System.currentTimeMillis(), - null, - false - ); - - this.provider.buildDependencyTree(plugin); - } + /** + * プラグインのメタデータが存在するかどうかを返します。 + * + * @param pluginName プラグインの名前 + * @return プラグインのメタデータが存在するかどうか + */ + public boolean hasPluginMeta(@NotNull String pluginName) + { + return this.provider.isPluginMetaExists(pluginName); } /** - * プラグインがアンインストールされたときに呼び出します。 + * プラグインのメタデータが存在するかどうかを返します。 * - * @param pluginName アンインストールされたプラグインの名前 + * @param plugin プラグイン + * @return プラグインのメタデータが存在するかどうか */ - public void onUninstalled(@NotNull String pluginName) + public boolean hasPluginMeta(@NotNull Plugin plugin) { - this.provider.removePluginMeta(pluginName); + return this.hasPluginMeta(plugin.getName()); } private boolean checkNoAutoCreateMetadata(Plugin plugin) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java index a83dd1f1..eaf7630e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java @@ -2,6 +2,7 @@ import com.zaxxer.hikari.HikariDataSource; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; import org.bukkit.Bukkit; import org.bukkit.event.Listener; @@ -256,10 +257,18 @@ private void savePluginRelationalData(Connection connection, Plugin plugin) thro connection.prepareStatement("INSERT INTO plugin_author(name, author) VALUES(?, ?)"); statement.setString(1, name); - for (String author : authors) + try { - statement.setString(2, author); - statement.execute(); + for (String author : authors) + { + statement.setString(2, author); + statement.execute(); + } + } + catch (SQLException e) + { + KPMDaemon.getInstance().getLogger() + .warn("Failed to save plugin author data: " + name + " by " + authors); } statement = connection.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); @@ -562,6 +571,17 @@ public void deleteFromDependencyTree(@NotNull String pluginName) .executeUpdate(); } + /** + * PluginMeta のイテレータを取得します。 + * + * @return PluginMeta のイテレータ + */ + @NotNull + public PluginMetaIterator getPluginMetaIterator() + { + return new PluginMetaIterator(this, Transaction.create(this.db)); + } + /** * 使われていない依存関係のリストを取得します。 *

    diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java index a84c4f26..3fb5e804 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java @@ -2,8 +2,10 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.experimental.Accessors; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -725,10 +727,13 @@ public int characteristics() /** * クエリの実行結果を表すクラスです。 */ - @AllArgsConstructor + @RequiredArgsConstructor public class QueryResult { private final ResultSet result; + @Setter + @Accessors(chain = true) + private Function mapper; /** * ResultSetをそのまま取得します。 @@ -746,7 +751,6 @@ public ResultSet getResult() public void close() throws SQLException { this.result.close(); - Transaction.this.connection.close(); } /** @@ -756,14 +760,14 @@ public void close() throws SQLException * @param max 最大件数 * @return 変換されたList */ - public ArrayList mapToList(Function resultMapper, long max) + public ArrayList mapToList(Function resultMapper, long max) { ArrayList list = new ArrayList<>(); try { while (this.result.next() && !(max == -1 || list.size() >= max)) - list.add(resultMapper.apply(this.result)); + list.add(resultMapper.apply(new ResultRow(this.result, true))); } catch (SQLException e) { @@ -779,7 +783,7 @@ public ArrayList mapToList(Function resultMapper, long max) * @param resultMapper マッピング関数 * @return 変換されたList */ - public ArrayList mapToList(Function resultMapper) + public ArrayList mapToList(Function resultMapper) { return this.mapToList(resultMapper, -1); } @@ -806,6 +810,36 @@ public Stream stream() { return this.stream(true); } + + /** + * 次の行に移動します。 + * + * @return 次の行が存在するかどうか + */ + public boolean next() + { + try + { + return this.result.next(); + } + catch (SQLException e) + { + throw new IllegalStateException(e); + } + } + + /** + * 行の内容をマップして返します。 + * + * @return マップされた行の内容 + */ + public T get() + { + if (this.mapper == null) + throw new IllegalStateException("Mapper is not set."); + + return this.mapper.apply(new ResultRow(this.result, true)); + } } From 2cd342242f3f537e0bb7a3d46269f6414e4bb62e Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 22 Oct 2022 23:17:52 +0900 Subject: [PATCH 402/745] fix: KPM removes the plugin meta that was installed dynamically when the server is being stopped --- .../meta/PluginMetaManager.java | 3 +++ .../utils/PluginUtil.java | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java index c325efac..1fabbec1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java @@ -84,6 +84,9 @@ public void onPluginEnable(PluginEnableEvent event) @EventHandler public void onDisable(PluginDisableEvent event) { + if (!PluginUtil.isServerRunning()) + return; // The server is being stopped. + Plugin plugin = event.getPlugin(); if (plugin.getName().equalsIgnoreCase("TeamKUNPluginManager") || this.checkNoAutoCreateMetadata(plugin)) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java index 92054d00..9c8290bc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java @@ -26,6 +26,8 @@ public class PluginUtil { private static final Method pluginGetFile; + private static final Field fIsRunning; // Lnet/minecraft/server//MinecraftServer; -> isRunning:Z + private static final Object oMinecraftServer; // Lnet/minecraft/server//MinecraftServer; -> Lnet/minecraft/server//DedicatedServer; static { @@ -33,8 +35,13 @@ public class PluginUtil { pluginGetFile = ReflectionUtils.getAccessibleMethod(JavaPlugin.class, "getFile"); pluginGetFile.setAccessible(true); + + Class cMinecraftServer = ReflectionUtils.PackageType.MINECRAFT_SERVER.getClass("MinecraftServer"); + fIsRunning = ReflectionUtils.getAccessibleField(cMinecraftServer, true, "isRunning"); + + oMinecraftServer = ReflectionUtils.getValue(Bukkit.getServer(), true, "console"); } - catch (NoSuchMethodException e) + catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } @@ -157,4 +164,16 @@ public static PluginDescriptionFile loadDescription(File file) throws InvalidDes return desc; } + public static boolean isServerRunning() + { + try + { + return fIsRunning.getBoolean(oMinecraftServer); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + return false; + } + } } From 0ce11d6d64e75010a06b5911810d04bc056f369a Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 23 Oct 2022 19:25:15 +0900 Subject: [PATCH 403/745] fix: Version predicate --- .../kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java index 85c6d12b..7fc01ab5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java @@ -68,7 +68,7 @@ private static Version parseVersion(Map map) throws InvalidInformationFile if (map.containsKey("kpm")) { Object kpmVersionObj = map.get("kpm"); - if (Version.isValidVersionString(kpmVersionObj.toString())) + if (!Version.isValidVersionString(kpmVersionObj.toString())) throw new InvalidInformationFileException("Invalid syntax of kpm version: " + kpmVersionObj); return Version.of((String) kpmVersionObj); } From 0836048c325ae504469c3f0eb6a2376ddf09f8c0 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 23 Oct 2022 19:53:53 +0900 Subject: [PATCH 404/745] feat: New kpm info error handling --- .../impls/install/InstallErrorCause.java | 5 +++ .../impls/install/PluginInstaller.java | 22 +++++++++- .../signals/InvalidKPMInfoFileSignal.java | 40 +++++++++++++++++++ .../collector/DependsCollectTask.java | 22 ++++++++-- .../kpminfo/KPMInfoManager.java | 22 +++------- .../intall/InstallerSignalHandler.java | 13 ++++++ 6 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InvalidKPMInfoFileSignal.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java index f0a67542..b27a8565 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java @@ -17,4 +17,9 @@ public enum InstallErrorCause * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 */ PLUGIN_ALREADY_INSTALLED, + /** + * プラグインの持つKPM情報ファイルが不正であり、 + * {@link net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal} でも無視が選択されませんでした。 + */ + INVALID_KPM_INFO_FILE, } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java index bf6bd2d3..d255cf3c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java @@ -5,6 +5,7 @@ import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal; import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; @@ -21,6 +22,7 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.InvalidInformationFileException; import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; @@ -31,6 +33,7 @@ import org.jetbrains.annotations.Nullable; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Path; @@ -91,7 +94,21 @@ public InstallResult execute(@NotNull InstallArgument argument) th // endregion // Load kpmInfo - KPMInformationFile kpmInfo = this.daemon.getKpmInfoManager().loadInfo(pluginFilePath, pluginDescription); + KPMInformationFile kpmInfo = null; + try + { + kpmInfo = this.daemon.getKpmInfoManager().loadInfo(pluginFilePath, pluginDescription); + } + catch (InvalidInformationFileException e) + { + InvalidKPMInfoFileSignal signal = new InvalidKPMInfoFileSignal(pluginFilePath, pluginDescription); + this.postSignal(signal); + if (!signal.isIgnore()) + return this.error(InstallErrorCause.INVALID_KPM_INFO_FILE); + } + catch (FileNotFoundException ignored) + { + } // KPM info file is not required so we can ignore it. boolean replacePlugin = false; // region Do assertions. @@ -131,6 +148,7 @@ public InstallResult execute(@NotNull InstallArgument argument) th // region Do collect dependencies, compute dependencies load order and install them. + KPMInformationFile finalKpmInfo = kpmInfo; TaskResult installResult = this.submitter( InstallTasks.COLLECTING_DEPENDENCIES, @@ -143,7 +161,7 @@ public InstallResult execute(@NotNull InstallArgument argument) th new PluginsInstallTask(this) ) .bridgeArgument(result -> new PluginsInstallArgument( - pluginFilePath, pluginDescription, kpmInfo, result.getOrder() + pluginFilePath, pluginDescription, finalKpmInfo, result.getOrder() )) .submitAll(new DependsCollectArgument(pluginDescription)); // endregion diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InvalidKPMInfoFileSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InvalidKPMInfoFileSignal.java new file mode 100644 index 00000000..de2cff50 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InvalidKPMInfoFileSignal.java @@ -0,0 +1,40 @@ +package net.kunmc.lab.teamkunpluginmanager.installer.signals; + +import lombok.Data; +import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; + +/** + * プラグインのKPM情報ファイルが不正な場合に投げられるシグナルです。 + */ +@Data +public class InvalidKPMInfoFileSignal implements Signal +{ + /** + * プラグインの名前です。 + */ + @NotNull + private final Path plugin; + /** + * プラグインの {@link org.bukkit.plugin.PluginDescriptionFile} です。 + */ + @NotNull + private final PluginDescriptionFile descriptionFile; + + /** + * プラグインのKPM情報ファイルを無視するかどうかを示すフラグです。 + * {@code true} の場合、プラグインの持つKPM情報ファイルは無視されます。 + * {@code false} の場合、KPM情報ファイルが不正なため、プラグインのインストールが中断される可能性があります。 + */ + private boolean ignore; + + public InvalidKPMInfoFileSignal(@NotNull Path plugin, @NotNull PluginDescriptionFile descriptionFile) + { + this.plugin = plugin; + this.descriptionFile = descriptionFile; + this.ignore = false; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java index bd4b6b46..3117bdb9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -2,6 +2,7 @@ import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; @@ -18,6 +19,7 @@ import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveResult; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.teamkunpluginmanager.kpminfo.InvalidInformationFileException; import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; @@ -27,6 +29,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.FileNotFoundException; import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; @@ -209,11 +212,22 @@ private PluginDescriptionFile downloadResultToPluginDescriptionFile(@NotNull Dow continue; } - KPMInformationFile kpmInfoFile; - if (this.daemon.getKpmInfoManager().hasInfo(entry.getValue().getPath())) + KPMInformationFile kpmInfoFile = null; + try + { kpmInfoFile = this.daemon.getKpmInfoManager().loadInfo(entry.getValue().getPath(), pluginDescriptionFile); - else - kpmInfoFile = null; + } + catch (InvalidInformationFileException ex) + { + InvalidKPMInfoFileSignal signal = + new InvalidKPMInfoFileSignal(entry.getValue().getPath(), pluginDescriptionFile); + this.postSignal(signal); + if (!signal.isIgnore()) + continue; + } + catch (FileNotFoundException ignored) + { + } String query; if (kpmInfoFile != null && kpmInfoFile.getUpdateQuery() != null) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java index cb1c21ea..8acbaf8f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java @@ -32,25 +32,15 @@ public KPMInfoManager(KPMDaemon daemon) * @param path KPM情報ファイルのパス * @param descriptionFile プラグインの説明ファイル * @return 読み込みに成功した場合はKPM情報ファイル、失敗した場合はnull + * @throws InvalidInformationFileException KPM情報ファイルが不正な場合 + * @throws FileNotFoundException KPM情報ファイルが見つからない場合 */ @Nullable - public KPMInformationFile loadInfo(@NotNull Path path, @NotNull PluginDescriptionFile descriptionFile) + public KPMInformationFile loadInfo(@NotNull Path path, @NotNull PluginDescriptionFile descriptionFile) throws + FileNotFoundException, InvalidInformationFileException { - KPMInformationFile info = null; - try - { - info = KPMInfoParser.load(path); - this.lookupNames.put(descriptionFile.getName(), info); - } - catch (InvalidInformationFileException e) - { - this.daemon.getLogger().warn( - "The plugin " + descriptionFile.getName() + " has invalid KPM information file: " + e.getMessage()); - this.daemon.getLogger().warn("The plugin's KPM information will be ignored."); - } - catch (FileNotFoundException ignored) - { - } + KPMInformationFile info = KPMInfoParser.load(path); + this.lookupNames.put(descriptionFile.getName(), info); return info; } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java index 277230c9..de267aa0 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java @@ -1,11 +1,13 @@ package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginInstallingSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginLoadSignal; import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginRelocatingSignal; import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; +import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; @@ -50,4 +52,15 @@ public void onPluginLoading(PluginEnablingSignal.Pre signal) this.terminal.writeLine(ChatColor.GREEN + PluginUtil.getPluginString(signal.getPlugin()) + " のトリガを処理しています ..."); } + + @SignalHandler + public void onInvalidKPMInfoFile(InvalidKPMInfoFileSignal signal) + { + this.terminal.warn("プラグイン " + signal.getPlugin() + " はKPM情報ファイル (kpm.yml) を持っていますが、" + + "KPMが理解できる形式ではありません。"); + this.terminal.info(ChatColor.GRAY + "このファイルを無視して強制的にインストールできますが、" + + "強制的な操作は予期しない問題を引き起こす可能性があります。"); + + signal.setIgnore(SignalHandlingUtils.askContinue(this.terminal)); + } } From 0ba52dfaabcd3a7a23a1ed5253309001e909f7a9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 23 Oct 2022 20:13:34 +0900 Subject: [PATCH 405/745] fix: Old schema --- kpm-info.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kpm-info.json b/kpm-info.json index 97dff331..c421aeec 100644 --- a/kpm-info.json +++ b/kpm-info.json @@ -6,6 +6,10 @@ "version": { "type": "string", "pattern": "^v?(?[3-9]\\d*)\\.(?0|[1-9]\\d*)(\\.(?0|[1-9]\\d*))(-(?(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))(?:\\+(?[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" + }, + "query": { + "type": "string", + "pattern": "^(?[^>]+>)?(?[^=]+)(?:==(?.+))?$" } }, "properties": { @@ -16,6 +20,14 @@ "3.0.0", "v3.0-pre1" ] + }, + "update": { + "$ref": "#/definitions/query", + "description": "プラグインを自動更新する時に使用するクエリです。(この機能は将来的に実装される予定です。)", + "examples": [ + "TeamKUN/DaredemoOpPlugin", + "bukkit>daredemo-op-plugin" + ] } }, "required": [ From dea1daf4f0c62d3fd2304a38ba0de5b35381dce7 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 23 Oct 2022 20:39:13 +0900 Subject: [PATCH 406/745] refactor!: Change package from net.kunmc.lab.teamkunpluginmanager to net.kunmc.lab.kpm BREAKING-CHANGE: Change base package name: net.kunmc.lab.kpm --- KPMDaemon/pom.xml | 1 + .../KPMDaemon.java | 36 ++++++------- .../KPMEnvironment.java | 2 +- .../TokenStore.java | 2 +- .../alias/Alias.java | 2 +- .../alias/AliasPluginResolver.java | 20 +++---- .../alias/AliasProvider.java | 6 +-- .../alias/AliasSource.java | 2 +- .../alias/AliasUpdater.java | 4 +- .../installer/AbstractInstaller.java | 20 +++---- .../installer/AbstractInstallerArgument.java | 2 +- .../installer/InstallFailedInstallResult.java | 2 +- .../installer/InstallManager.java | 10 ++-- .../installer/InstallProgress.java | 12 ++--- .../installer/InstallResult.java | 2 +- .../exceptions/InstallerRunningException.java | 2 +- .../TokenNotAvailableException.java | 2 +- .../impls/autoremove/AutoRemoveArgument.java | 4 +- .../autoremove/AutoRemoveErrorCause.java | 2 +- .../autoremove/AutoRemoveSucceedResult.java | 8 +-- .../impls/autoremove/AutoRemoveTasks.java | 2 +- .../impls/autoremove/PluginAutoRemover.java | 28 +++++----- .../signals/PluginEnumeratedSignal.java | 4 +- .../signals/PluginUninstallFailedSignal.java | 8 +-- .../installer/impls/clean/CleanArgument.java | 4 +- .../impls/clean/CleanErrorCause.java | 2 +- .../installer/impls/clean/CleanTasks.java | 2 +- .../clean/GarbageCleanSucceedResult.java | 6 +-- .../installer/impls/clean/GarbageCleaner.java | 22 ++++---- .../impls/install/InstallArgument.java | 4 +- .../impls/install/InstallErrorCause.java | 8 +-- .../installer/impls/install/InstallTasks.java | 16 +++--- .../impls/install/PluginInstaller.java | 54 +++++++++---------- .../signals/AlreadyInstalledPluginSignal.java | 4 +- .../impls/register/RegisterArgument.java | 4 +- .../impls/register/RegisterErrorCause.java | 2 +- .../impls/register/RegisterTasks.java | 2 +- .../impls/register/TokenRegisterer.java | 42 +++++++-------- .../pojos/UserVerificationCodeResponse.java | 2 +- .../VerificationSubmitPollingResponse.java | 2 +- .../signals/TokenGenerateStartingSignal.java | 4 +- .../register/signals/TokenStoredSignal.java | 4 +- .../UserDoesntCompleteVerifySignal.java | 4 +- .../UserVerificationSuccessSignal.java | 4 +- .../signals/UserVerifyDeniedSignal.java | 4 +- .../VerificationCodeExpiredSignal.java | 4 +- .../VerificationCodeReceivedSignal.java | 6 +-- .../VerificationCodeRequestFailedSignal.java | 4 +- .../VerificationCodeRequestingSignal.java | 4 +- .../PluginUninstallSucceedResult.java | 8 +-- .../impls/uninstall/PluginUninstaller.java | 40 +++++++------- .../impls/uninstall/UnInstallErrorCause.java | 6 +-- .../impls/uninstall/UnInstallTasks.java | 2 +- .../impls/uninstall/UninstallArgument.java | 4 +- .../signals/PluginIsDependencySignal.java | 4 +- .../signals/SearchingPluginSignal.java | 4 +- .../signals/UninstallReadySignal.java | 4 +- .../installer/impls/update/AliasUpdater.java | 24 ++++----- .../impls/update/UpdateArgument.java | 4 +- .../impls/update/UpdateErrorCause.java | 2 +- .../installer/impls/update/UpdateTasks.java | 2 +- .../update/signals/UpdateFinishedSignal.java | 4 +- .../signals/InstallFinishedSignal.java | 6 +-- .../signals/InvalidKPMInfoFileSignal.java | 4 +- .../signals/PluginModifiedSignal.java | 4 +- .../assertion/IgnoredPluginSignal.java | 4 +- .../installer/task/InstallTask.java | 8 +-- .../installer/task/TaskArgument.java | 2 +- .../installer/task/TaskChain.java | 4 +- .../installer/task/TaskFailedException.java | 2 +- .../installer/task/TaskResult.java | 2 +- .../download/SourceDownloadArgument.java | 4 +- .../download/SourceDownloadErrorCause.java | 2 +- .../source/download/SourceDownloadResult.java | 6 +-- .../source/download/SourceDownloadState.java | 2 +- .../source/download/SourceDownloadTask.java | 24 ++++----- .../download/signals/InvalidRemoteSignal.java | 4 +- .../download/signals/MalformedURLSignal.java | 2 +- .../signals/SourceDownloadFailedSignal.java | 6 +-- .../signals/UnsupportedProtocolSignal.java | 2 +- .../alias/update/UpdateAliasesArgument.java | 6 +-- .../alias/update/UpdateAliasesErrorCause.java | 2 +- .../alias/update/UpdateAliasesResult.java | 4 +- .../alias/update/UpdateAliasesState.java | 2 +- .../tasks/alias/update/UpdateAliasesTask.java | 18 +++---- .../update/signals/AliasUpdateSignal.java | 4 +- .../update/signals/InvalidSourceSignal.java | 2 +- .../update/signals/SourcePreparedSignal.java | 2 +- .../alias/update/signals/SourceSignal.java | 4 +- .../tasks/dependencies/DependencyElement.java | 4 +- .../collector/DependsCollectArgument.java | 4 +- .../collector/DependsCollectErrorCause.java | 2 +- .../collector/DependsCollectResult.java | 6 +-- .../collector/DependsCollectState.java | 2 +- .../collector/DependsCollectStatus.java | 6 +-- .../collector/DependsCollectTask.java | 54 +++++++++---------- ...CollectDependencysDependsFailedSignal.java | 4 +- .../DependencyCollectFailedSignalBase.java | 4 +- .../DependencyDownloadFailedSignal.java | 2 +- ...DependencyLoadDescriptionFailedSignal.java | 2 +- .../signals/DependencyNameMismatchSignal.java | 2 +- .../DependencyResolveFailedSignal.java | 2 +- .../signals/DependsCollectFailedSignal.java | 4 +- .../DependsDownloadFinishedSignal.java | 6 +-- .../signals/DependsEnumeratedSignal.java | 4 +- .../computer/DependsComputeOrderArgument.java | 6 +-- .../DependsComputeOrderErrorCause.java | 2 +- .../computer/DependsComputeOrderResult.java | 6 +-- .../computer/DependsComputeOrderState.java | 2 +- .../computer/DependsComputeOrderTask.java | 10 ++-- .../DependsLoadOrderComputingSignal.java | 6 +-- .../description/DescriptionLoadArgument.java | 4 +- .../DescriptionLoadErrorCause.java | 2 +- .../description/DescriptionLoadResult.java | 4 +- .../description/DescriptionLoadState.java | 2 +- .../description/DescriptionLoadTask.java | 10 ++-- .../signals/LoadPluginDescriptionSignal.java | 4 +- .../task/tasks/download/DownloadArgument.java | 4 +- .../tasks/download/DownloadErrorCause.java | 2 +- .../task/tasks/download/DownloadResult.java | 4 +- .../task/tasks/download/DownloadState.java | 2 +- .../task/tasks/download/DownloadTask.java | 22 ++++---- .../download/signals/DownloadErrorSignal.java | 4 +- .../signals/DownloadProgressSignal.java | 2 +- .../download/signals/DownloadSignal.java | 4 +- .../signals/DownloadStartingSignal.java | 2 +- .../signals/DownloadSucceedSignal.java | 2 +- .../garbage/clean/GarbageCleanArgument.java | 4 +- .../garbage/clean/GarbageCleanErrorCause.java | 2 +- .../garbage/clean/GarbageCleanResult.java | 4 +- .../garbage/clean/GarbageCleanState.java | 2 +- .../tasks/garbage/clean/GarbageCleanTask.java | 16 +++--- .../signal/GarbageDeleteSkippedSignal.java | 4 +- .../clean/signal/GarbageDeletingSignal.java | 4 +- .../clean/signal/GarbageEnumeratedSignal.java | 4 +- .../clean/signal/InvalidIntegritySignal.java | 4 +- .../garbage/search/GarbageSearchArgument.java | 4 +- .../search/GarbageSearchErrorCause.java | 2 +- .../garbage/search/GarbageSearchResult.java | 4 +- .../garbage/search/GarbageSearchState.java | 2 +- .../garbage/search/GarbageSearchTask.java | 8 +-- .../signals/GarbageSearchingSignal.java | 4 +- .../tasks/install/PluginsInstallArgument.java | 8 +-- .../install/PluginsInstallErrorCause.java | 2 +- .../tasks/install/PluginsInstallResult.java | 4 +- .../tasks/install/PluginsInstallState.java | 2 +- .../tasks/install/PluginsInstallTask.java | 36 ++++++------- .../install/signals/PluginEnablingSignal.java | 4 +- .../PluginIncompatibleWithKPMSignal.java | 8 +-- .../signals/PluginInstallingSignal.java | 4 +- .../install/signals/PluginLoadSignal.java | 4 +- .../signals/PluginOnLoadRunningSignal.java | 4 +- .../signals/PluginRelocatingSignal.java | 4 +- .../tasks/resolve/PluginResolveArgument.java | 4 +- .../resolve/PluginResolveErrorCause.java | 4 +- .../tasks/resolve/PluginResolveResult.java | 6 +-- .../tasks/resolve/PluginResolveState.java | 2 +- .../task/tasks/resolve/PluginResolveTask.java | 24 ++++----- .../signals/MultiplePluginResolvedSignal.java | 10 ++-- .../signals/PluginResolveErrorSignal.java | 6 +-- .../PluginResolvedSuccessfulSignal.java | 6 +-- .../signals/PluginResolvingSignal.java | 6 +-- .../tasks/uninstall/UnInstallArgument.java | 4 +- .../tasks/uninstall/UnInstallErrorCause.java | 2 +- .../task/tasks/uninstall/UnInstallResult.java | 4 +- .../task/tasks/uninstall/UnInstallState.java | 2 +- .../task/tasks/uninstall/UnInstallTask.java | 26 ++++----- .../signals/PluginDisablingSignal.java | 4 +- .../signals/PluginRegisteredRecipeSignal.java | 4 +- .../signals/PluginUninstallErrorSignal.java | 6 +-- .../signals/PluginUninstallingSignal.java | 4 +- .../signals/PluginUnloadingSignal.java | 4 +- .../uninstall/signals/StartingGCSignal.java | 10 ++++ .../InvalidInformationFileException.java | 2 +- .../kpminfo/KPMInfoManager.java | 6 +-- .../kpminfo/KPMInfoParser.java | 6 +-- .../kpminfo/KPMInformationFile.java | 6 +-- .../loader/CommandsPatcher.java | 4 +- .../loader/PluginLoadResult.java | 2 +- .../loader/PluginLoader.java | 6 +-- .../meta/DependType.java | 2 +- .../meta/DependencyNode.java | 2 +- .../meta/InstallOperator.java | 2 +- .../meta/MetaSQLUtil.java | 2 +- .../meta/PluginMeta.java | 2 +- .../meta/PluginMetaIterator.java | 4 +- .../meta/PluginMetaManager.java | 4 +- .../meta/PluginMetaProvider.java | 6 +-- .../resolver/PluginResolver.java | 12 ++--- .../resolver/QueryContext.java | 2 +- .../impl/BruteforceGitHubResolver.java | 12 ++--- .../resolver/impl/CurseBukkitResolver.java | 18 +++---- .../impl/CurseBukkitSuccessResult.java | 12 ++--- .../resolver/impl/GitHubSuccessResult.java | 8 +-- .../resolver/impl/GitHubURLResolver.java | 20 +++---- .../resolver/impl/OmittedGitHubResolver.java | 12 ++--- .../resolver/impl/SpigotMCResolver.java | 18 +++---- .../resolver/impl/SpigotMCSuccessResult.java | 10 ++-- .../resolver/interfaces/BaseResolver.java | 10 ++-- .../resolver/interfaces/URLResolver.java | 10 ++-- .../resolver/result/ErrorResult.java | 4 +- .../resolver/result/MarketplaceResult.java | 2 +- .../resolver/result/MultiResult.java | 4 +- .../resolver/result/PipeResult.java | 8 +-- .../resolver/result/ResolveResult.java | 4 +- .../resolver/result/SuccessResult.java | 4 +- .../resolver/result/VersionedResult.java | 2 +- .../signal/Signal.java | 2 +- .../signal/SignalHandleManager.java | 4 +- .../signal/SignalHandler.java | 2 +- .../signal/SignalHandlerList.java | 4 +- .../utils/Pair.java | 2 +- .../utils/PluginUtil.java | 2 +- .../utils/ReflectionUtils.java | 2 +- .../utils/ReversedCollector.java | 2 +- .../utils/db/ResultRow.java | 2 +- .../utils/db/Transaction.java | 2 +- .../utils/http/DownloadProgress.java | 2 +- .../utils/http/HTTPResponse.java | 2 +- .../utils/http/RequestContext.java | 2 +- .../utils/http/RequestMethod.java | 2 +- .../utils/http/Requests.java | 4 +- .../InvalidVersionSyntaxException.java | 2 +- .../utils/versioning/Version.java | 2 +- .../utils/versioning/VersionComparator.java | 2 +- .../utils/versioning/VersionElement.java | 2 +- .../uninstall/signals/StartingGCSignal.java | 10 ---- .../utils/versioning/VersionTest.java | 2 +- KPMPlugin/pom.xml | 1 + .../HeadInstallers.java | 38 ++++++------- .../TeamKunPluginManager.java | 24 ++++----- .../{teamkunpluginmanager => kpm}/Utils.java | 4 +- .../commands/CommandAutoRemove.java | 6 +-- .../commands/CommandClean.java | 6 +-- .../commands/CommandDebug.java | 10 ++-- .../commands/CommandInfo.java | 18 +++---- .../commands/CommandInstall.java | 6 +-- .../commands/CommandRegister.java | 8 +-- .../commands/CommandReload.java | 4 +- .../commands/CommandResolve.java | 20 +++---- .../commands/CommandStatus.java | 4 +- .../commands/CommandUninstall.java | 6 +-- .../commands/CommandUpdate.java | 8 +-- .../commands/debug/CommandDepTreeDebug.java | 10 ++-- .../commands/debug/CommandInstallDebug.java | 16 +++--- .../commands/debug/CommandUninstallDebug.java | 16 +++--- .../commands/debug/DebugSignalHandler.java | 16 +++--- .../deptree/CommandMarkAsDependency.java | 4 +- .../commands/debug/deptree/CommandPurge.java | 4 +- .../debug/deptree/CommandRelation.java | 10 ++-- .../signal/HeadSignalHandlers.java | 38 ++++++------- .../signal/SignalHandlingUtils.java | 2 +- .../AutoRemoveFinishedSignalHandler.java | 10 ++-- .../AutoRemoveReadySignalHandler.java | 10 ++-- .../GarbageCleanFinishedSignalHandler.java | 10 ++-- .../clean/GarbageCleanSignalHandler.java | 10 ++-- .../common/CheckEnvSignalHandler.java | 14 ++--- .../common/DownloadingSignalHandler.java | 12 ++--- .../common/InstallFinishedSignalBase.java | 12 ++--- .../handlers/common/ModifySignalHandler.java | 8 +-- .../intall/DependenciesSignalHandler.java | 16 +++--- .../intall/InstallFinishedSignalHandler.java | 20 +++---- .../intall/InstallerSignalHandler.java | 18 +++---- .../intall/ResolverSignalHandler.java | 14 ++--- .../register/TokenGenerateSignalHandler.java | 24 ++++----- .../register/TokenRegisterSignalHandler.java | 6 +-- .../PluginIsDependencySignalHandler.java | 8 +-- .../UninstallFinishedSignalHandler.java | 16 +++--- .../UninstallReadySignalHandler.java | 10 ++-- .../uninstall/UninstallerSignalHandler.java | 16 +++--- .../update/UpdateAliasesSignalHandler.java | 12 ++--- KPMPlugin/src/main/resources/plugin.yml | 2 +- 272 files changed, 975 insertions(+), 973 deletions(-) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/KPMDaemon.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/KPMEnvironment.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/TokenStore.java (99%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/alias/Alias.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/alias/AliasPluginResolver.java (72%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/alias/AliasProvider.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/alias/AliasSource.java (94%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/alias/AliasUpdater.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/AbstractInstaller.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/AbstractInstallerArgument.java (68%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/InstallFailedInstallResult.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/InstallManager.java (85%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/InstallProgress.java (96%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/InstallResult.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/exceptions/InstallerRunningException.java (87%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/exceptions/TokenNotAvailableException.java (87%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/autoremove/AutoRemoveArgument.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/autoremove/AutoRemoveErrorCause.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/autoremove/AutoRemoveSucceedResult.java (58%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/autoremove/AutoRemoveTasks.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/autoremove/PluginAutoRemover.java (76%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/autoremove/signals/PluginEnumeratedSignal.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java (52%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/clean/CleanArgument.java (87%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/clean/CleanErrorCause.java (61%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/clean/CleanTasks.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/clean/GarbageCleanSucceedResult.java (82%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/clean/GarbageCleaner.java (73%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/install/InstallArgument.java (73%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/install/InstallErrorCause.java (50%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/install/InstallTasks.java (64%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/install/PluginInstaller.java (76%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/install/signals/AlreadyInstalledPluginSignal.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/RegisterArgument.java (75%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/RegisterErrorCause.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/RegisterTasks.java (87%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/TokenRegisterer.java (85%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/pojos/UserVerificationCodeResponse.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/pojos/VerificationSubmitPollingResponse.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/TokenGenerateStartingSignal.java (74%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/TokenStoredSignal.java (68%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java (81%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/UserVerificationSuccessSignal.java (79%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/UserVerifyDeniedSignal.java (65%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/VerificationCodeExpiredSignal.java (72%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/VerificationCodeReceivedSignal.java (81%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java (76%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/register/signals/VerificationCodeRequestingSignal.java (54%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/PluginUninstallSucceedResult.java (59%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/PluginUninstaller.java (81%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/UnInstallErrorCause.java (53%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/UnInstallTasks.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/UninstallArgument.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/signals/PluginIsDependencySignal.java (89%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/signals/SearchingPluginSignal.java (64%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/uninstall/signals/UninstallReadySignal.java (82%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/update/AliasUpdater.java (64%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/update/UpdateArgument.java (74%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/update/UpdateErrorCause.java (64%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/update/UpdateTasks.java (82%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/impls/update/signals/UpdateFinishedSignal.java (75%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/signals/InstallFinishedSignal.java (56%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/signals/InvalidKPMInfoFileSignal.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/signals/PluginModifiedSignal.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/signals/assertion/IgnoredPluginSignal.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/InstallTask.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/TaskArgument.java (62%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/TaskChain.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/TaskFailedException.java (92%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/TaskResult.java (92%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/SourceDownloadArgument.java (74%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java (73%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/SourceDownloadResult.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/SourceDownloadState.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/SourceDownloadTask.java (78%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java (73%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java (51%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java (84%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/UpdateAliasesArgument.java (73%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java (74%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/UpdateAliasesResult.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/UpdateAliasesState.java (81%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/UpdateAliasesTask.java (85%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java (84%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/alias/update/signals/SourceSignal.java (78%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/DependencyElement.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/DependsCollectArgument.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java (72%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/DependsCollectResult.java (85%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/DependsCollectState.java (87%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/DependsCollectStatus.java (93%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/DependsCollectTask.java (82%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java (77%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java (76%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java (84%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java (78%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java (89%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java (74%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java (76%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java (61%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java (77%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java (62%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java (64%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java (77%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java (85%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java (93%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/description/DescriptionLoadArgument.java (79%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/description/DescriptionLoadErrorCause.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/description/DescriptionLoadResult.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/description/DescriptionLoadState.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/description/DescriptionLoadTask.java (84%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java (78%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/DownloadArgument.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/DownloadErrorCause.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/DownloadResult.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/DownloadState.java (84%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/DownloadTask.java (81%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/signals/DownloadErrorSignal.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/signals/DownloadProgressSignal.java (93%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/signals/DownloadSignal.java (72%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/signals/DownloadStartingSignal.java (89%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/download/signals/DownloadSucceedSignal.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/GarbageCleanArgument.java (75%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/GarbageCleanResult.java (84%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/GarbageCleanState.java (79%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/GarbageCleanTask.java (82%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java (72%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java (87%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java (75%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java (60%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/search/GarbageSearchArgument.java (82%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java (71%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/search/GarbageSearchResult.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/search/GarbageSearchState.java (79%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/search/GarbageSearchTask.java (86%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java (67%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/PluginsInstallArgument.java (74%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/PluginsInstallErrorCause.java (92%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/PluginsInstallResult.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/PluginsInstallState.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/PluginsInstallTask.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/signals/PluginEnablingSignal.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/signals/PluginInstallingSignal.java (79%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/signals/PluginLoadSignal.java (92%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java (87%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/install/signals/PluginRelocatingSignal.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/PluginResolveArgument.java (76%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/PluginResolveErrorCause.java (77%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/PluginResolveResult.java (81%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/PluginResolveState.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/PluginResolveTask.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java (73%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java (60%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java (67%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/resolve/signals/PluginResolvingSignal.java (68%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/UnInstallArgument.java (73%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/UnInstallErrorCause.java (89%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/UnInstallResult.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/UnInstallState.java (92%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/UnInstallTask.java (89%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java (85%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java (94%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java (67%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java (68%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java (88%) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/kpminfo/InvalidInformationFileException.java (84%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/kpminfo/KPMInfoManager.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/kpminfo/KPMInfoParser.java (93%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/kpminfo/KPMInformationFile.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/loader/CommandsPatcher.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/loader/PluginLoadResult.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/loader/PluginLoader.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/DependType.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/DependencyNode.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/InstallOperator.java (94%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/MetaSQLUtil.java (97%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/PluginMeta.java (96%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/PluginMetaIterator.java (97%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/PluginMetaManager.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/meta/PluginMetaProvider.java (99%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/PluginResolver.java (92%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/QueryContext.java (97%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/BruteforceGitHubResolver.java (77%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/CurseBukkitResolver.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/CurseBukkitSuccessResult.java (83%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/GitHubSuccessResult.java (85%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/GitHubURLResolver.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/OmittedGitHubResolver.java (65%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/SpigotMCResolver.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/impl/SpigotMCSuccessResult.java (74%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/interfaces/BaseResolver.java (80%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/interfaces/URLResolver.java (92%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/result/ErrorResult.java (94%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/result/MarketplaceResult.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/result/MultiResult.java (71%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/result/PipeResult.java (69%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/result/ResolveResult.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/result/SuccessResult.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/resolver/result/VersionedResult.java (82%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/Signal.java (91%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/SignalHandleManager.java (96%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/SignalHandler.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/SignalHandlerList.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/Pair.java (62%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/PluginUtil.java (99%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/ReflectionUtils.java (99%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/ReversedCollector.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/db/ResultRow.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/db/Transaction.java (99%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/http/DownloadProgress.java (88%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/http/HTTPResponse.java (99%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/http/RequestContext.java (95%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/http/RequestMethod.java (90%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/http/Requests.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/versioning/InvalidVersionSyntaxException.java (81%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/versioning/Version.java (98%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/versioning/VersionComparator.java (76%) rename KPMDaemon/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/versioning/VersionElement.java (95%) delete mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/StartingGCSignal.java rename KPMDaemon/src/test/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/utils/versioning/VersionTest.java (98%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/HeadInstallers.java (80%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/TeamKunPluginManager.java (80%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/Utils.java (92%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandAutoRemove.java (86%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandClean.java (87%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandDebug.java (78%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandInfo.java (94%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandInstall.java (88%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandRegister.java (87%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandReload.java (95%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandResolve.java (88%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandStatus.java (95%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandUninstall.java (89%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/CommandUpdate.java (84%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/debug/CommandDepTreeDebug.java (77%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/debug/CommandInstallDebug.java (83%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/debug/CommandUninstallDebug.java (83%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/debug/DebugSignalHandler.java (93%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/debug/deptree/CommandMarkAsDependency.java (94%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/debug/deptree/CommandPurge.java (94%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/commands/debug/deptree/CommandRelation.java (93%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/HeadSignalHandlers.java (68%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/SignalHandlingUtils.java (93%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java (79%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java (78%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java (79%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/clean/GarbageCleanSignalHandler.java (72%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/common/CheckEnvSignalHandler.java (82%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/common/DownloadingSignalHandler.java (84%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/common/InstallFinishedSignalBase.java (80%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/common/ModifySignalHandler.java (80%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/intall/DependenciesSignalHandler.java (70%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/intall/InstallFinishedSignalHandler.java (87%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/intall/InstallerSignalHandler.java (73%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/intall/ResolverSignalHandler.java (86%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/register/TokenGenerateSignalHandler.java (77%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/register/TokenRegisterSignalHandler.java (64%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/uninstall/PluginIsDependencySignalHandler.java (87%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/uninstall/UninstallFinishedSignalHandler.java (70%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/uninstall/UninstallReadySignalHandler.java (75%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/uninstall/UninstallerSignalHandler.java (73%) rename KPMPlugin/src/main/java/net/kunmc/lab/{teamkunpluginmanager => kpm}/signal/handlers/update/UpdateAliasesSignalHandler.java (76%) diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index ead1c96e..2a5684e5 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -10,6 +10,7 @@ 4.0.0 + net.kunmc.lab.kpm KPMDaemon diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 8a0b319b..d12b2798 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -1,24 +1,24 @@ -package net.kunmc.lab.teamkunpluginmanager; +package net.kunmc.lab.kpm; import lombok.AccessLevel; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.alias.AliasPluginResolver; -import net.kunmc.lab.teamkunpluginmanager.alias.AliasProvider; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallManager; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInfoManager; -import net.kunmc.lab.teamkunpluginmanager.loader.PluginLoader; -import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMeta; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaIterator; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.BruteforceGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubURLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.OmittedGitHubResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCResolver; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; -import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import net.kunmc.lab.kpm.alias.AliasPluginResolver; +import net.kunmc.lab.kpm.alias.AliasProvider; +import net.kunmc.lab.kpm.installer.InstallManager; +import net.kunmc.lab.kpm.kpminfo.KPMInfoManager; +import net.kunmc.lab.kpm.loader.PluginLoader; +import net.kunmc.lab.kpm.meta.InstallOperator; +import net.kunmc.lab.kpm.meta.PluginMeta; +import net.kunmc.lab.kpm.meta.PluginMetaIterator; +import net.kunmc.lab.kpm.meta.PluginMetaManager; +import net.kunmc.lab.kpm.resolver.PluginResolver; +import net.kunmc.lab.kpm.resolver.impl.BruteforceGitHubResolver; +import net.kunmc.lab.kpm.resolver.impl.CurseBukkitResolver; +import net.kunmc.lab.kpm.resolver.impl.GitHubURLResolver; +import net.kunmc.lab.kpm.resolver.impl.OmittedGitHubResolver; +import net.kunmc.lab.kpm.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.kpm.utils.http.Requests; +import net.kunmc.lab.kpm.utils.versioning.Version; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMEnvironment.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMEnvironment.java index dd1dc8cb..66ad0e92 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/KPMEnvironment.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMEnvironment.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager; +package net.kunmc.lab.kpm; import lombok.Builder; import lombok.Getter; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/TokenStore.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/TokenStore.java index d3638365..f102ab40 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/TokenStore.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/TokenStore.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager; +package net.kunmc.lab.kpm; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/Alias.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/Alias.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java index 31fb7edb..42f1265b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/Alias.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.alias; +package net.kunmc.lab.kpm.alias; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java similarity index 72% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java index e2380085..cd8b2d6c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasPluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.alias; - -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +package net.kunmc.lab.kpm.alias; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.resolver.PluginResolver; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasProvider.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasProvider.java index 512029d3..936ddde0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasProvider.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.alias; +package net.kunmc.lab.kpm.alias; import com.zaxxer.hikari.HikariDataSource; import lombok.AccessLevel; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.utils.db.ResultRow; -import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; +import net.kunmc.lab.kpm.utils.db.ResultRow; +import net.kunmc.lab.kpm.utils.db.Transaction; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasSource.java similarity index 94% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasSource.java index ba47836d..a9ac3799 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasSource.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasSource.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.alias; +package net.kunmc.lab.kpm.alias; import lombok.Value; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasUpdater.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasUpdater.java index c810df71..faf14753 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/alias/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasUpdater.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.alias; +package net.kunmc.lab.kpm.alias; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; +import net.kunmc.lab.kpm.utils.db.Transaction; /** * エイリアスを更新するトランザクションを補助するクラスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java index 3a9393d6..8ae48290 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.installer; +package net.kunmc.lab.kpm.installer; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskChain; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskChain; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.installer.task.TaskResult; +import net.kunmc.lab.kpm.signal.Signal; +import net.kunmc.lab.kpm.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstallerArgument.java similarity index 68% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstallerArgument.java index 15b5d09a..9d8821ce 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/AbstractInstallerArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstallerArgument.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer; +package net.kunmc.lab.kpm.installer; /** * インストーラの引数の基底クラスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallFailedInstallResult.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallFailedInstallResult.java index b06a5520..f6f1e315 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallFailedInstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallFailedInstallResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer; +package net.kunmc.lab.kpm.installer; import lombok.Getter; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallManager.java similarity index 85% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallManager.java index f6786064..016be2da 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallManager.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.installer; +package net.kunmc.lab.kpm.installer; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.TokenStore; +import net.kunmc.lab.kpm.installer.exceptions.InstallerRunningException; +import net.kunmc.lab.kpm.installer.exceptions.TokenNotAvailableException; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.TokenStore; -import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.InstallerRunningException; -import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.TokenNotAvailableException; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallProgress.java similarity index 96% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallProgress.java index 73f3e065..7278c477 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallProgress.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallProgress.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.installer; +package net.kunmc.lab.kpm.installer; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.PluginModifiedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectStatus; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.signals.PluginModifiedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.DependsCollectStatus; +import net.kunmc.lab.kpm.signal.Signal; +import net.kunmc.lab.kpm.signal.SignalHandleManager; import org.apache.commons.io.FileUtils; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallResult.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallResult.java index 68044a3e..0dd70c33 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/InstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer; +package net.kunmc.lab.kpm.installer; import lombok.Getter; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/InstallerRunningException.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/exceptions/InstallerRunningException.java similarity index 87% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/InstallerRunningException.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/exceptions/InstallerRunningException.java index c26fc88d..d41e5c09 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/InstallerRunningException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/exceptions/InstallerRunningException.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.exceptions; +package net.kunmc.lab.kpm.installer.exceptions; /** * インストーラが既に実行中であることを表す例外です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/TokenNotAvailableException.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/exceptions/TokenNotAvailableException.java similarity index 87% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/TokenNotAvailableException.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/exceptions/TokenNotAvailableException.java index bb2a91f9..9e600819 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/exceptions/TokenNotAvailableException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/exceptions/TokenNotAvailableException.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.exceptions; +package net.kunmc.lab.kpm.installer.exceptions; /** * トークンが設定されていないことを表す例外です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveArgument.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveArgument.java index 79957978..cc277fd9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; +package net.kunmc.lab.kpm.installer.impls.autoremove; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveErrorCause.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveErrorCause.java index 75bbf124..12f78852 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; +package net.kunmc.lab.kpm.installer.impls.autoremove; /** * 自動削除のエラーを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveSucceedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveSucceedResult.java similarity index 58% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveSucceedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveSucceedResult.java index 4a423456..9bb528ea 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveSucceedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveSucceedResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; +package net.kunmc.lab.kpm.installer.impls.autoremove; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.kpm.installer.InstallProgress; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallResult; /** * プラグインのアンインストールの結果を表すクラスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveTasks.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveTasks.java index 2f905873..261a36c7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/AutoRemoveTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; +package net.kunmc.lab.kpm.installer.impls.autoremove; /** * 自動削除のタスクを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java similarity index 76% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java index 04c9b256..5aa35b2f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/PluginAutoRemover.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java @@ -1,17 +1,17 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove; - -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginUninstallFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstallSucceedResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallTasks; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +package net.kunmc.lab.kpm.installer.impls.autoremove; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.autoremove.signals.PluginEnumeratedSignal; +import net.kunmc.lab.kpm.installer.impls.autoremove.signals.PluginUninstallFailedSignal; +import net.kunmc.lab.kpm.installer.impls.uninstall.PluginUninstallSucceedResult; +import net.kunmc.lab.kpm.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.kpm.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.kpm.signal.SignalHandleManager; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginEnumeratedSignal.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginEnumeratedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginEnumeratedSignal.java index ebf7cf66..9fe8ba70 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginEnumeratedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals; +package net.kunmc.lab.kpm.installer.impls.autoremove.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java similarity index 52% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java index 94e4a682..f2a07c0f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals; +package net.kunmc.lab.kpm.installer.impls.autoremove.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallTasks; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.kpm.signal.Signal; /** * アンインストールに失敗したときに送信されるシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanArgument.java similarity index 87% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanArgument.java index c0b961db..0be2e863 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; +package net.kunmc.lab.kpm.installer.impls.clean; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanErrorCause.java similarity index 61% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanErrorCause.java index f975e42e..8a9c6774 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; +package net.kunmc.lab.kpm.installer.impls.clean; /** * 不要データ削除のエラーを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanTasks.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanTasks.java index 9e44dba2..112a6ffa 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/CleanTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; +package net.kunmc.lab.kpm.installer.impls.clean; /** * 不要データ削除のタスクを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleanSucceedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleanSucceedResult.java similarity index 82% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleanSucceedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleanSucceedResult.java index 6dceb7ac..ae51ba03 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleanSucceedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleanSucceedResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; +package net.kunmc.lab.kpm.installer.impls.clean; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; +import net.kunmc.lab.kpm.installer.InstallProgress; +import net.kunmc.lab.kpm.installer.InstallResult; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleaner.java similarity index 73% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleaner.java index 37a811e2..be86c3bb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/clean/GarbageCleaner.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleaner.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.clean; +package net.kunmc.lab.kpm.installer.impls.clean; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.GarbageSearchArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.GarbageSearchTask; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.GarbageCleanArgument; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.GarbageCleanResult; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.GarbageCleanTask; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.search.GarbageSearchArgument; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.search.GarbageSearchTask; +import net.kunmc.lab.kpm.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallArgument.java similarity index 73% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallArgument.java index 5f990a37..33a17d9a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; +package net.kunmc.lab.kpm.installer.impls.install; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallErrorCause.java similarity index 50% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallErrorCause.java index b27a8565..7f9541d1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; +package net.kunmc.lab.kpm.installer.impls.install; /** @@ -9,17 +9,17 @@ public enum InstallErrorCause // Environment errors /** * 変更しようとしているプラグインが、無視リストに登録されており、 - * {@link net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal} でも強制インストールが選択されませんでした。 + * {@link net.kunmc.lab.kpm.installer.signals.assertion.IgnoredPluginSignal} でも強制インストールが選択されませんでした。 */ PLUGIN_IGNORED, /** * インストールしようとしているプラグインが、既にインストールされており、 - * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 + * {@link net.kunmc.lab.kpm.installer.impls.install.signals.AlreadyInstalledPluginSignal} でも置換が選択されませんでした。 */ PLUGIN_ALREADY_INSTALLED, /** * プラグインの持つKPM情報ファイルが不正であり、 - * {@link net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal} でも無視が選択されませんでした。 + * {@link net.kunmc.lab.kpm.installer.signals.InvalidKPMInfoFileSignal} でも無視が選択されませんでした。 */ INVALID_KPM_INFO_FILE, } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallTasks.java similarity index 64% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallTasks.java index da381f1b..409cd45a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/InstallTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; +package net.kunmc.lab.kpm.installer.impls.install; /** * インストールに必要なタスクをまとめた列挙型です。 @@ -18,20 +18,20 @@ public enum InstallTasks /** * プラグイン・クエリの解決中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask + * @see net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveTask */ RESOLVING_QUERY, /** * プラグインのダウンロード中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask + * @see net.kunmc.lab.kpm.installer.task.tasks.download.DownloadTask */ DOWNLOADING, /** * プラグイン情報の読み込み中であることを示します。 * * @see org.bukkit.plugin.PluginDescriptionFile - * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadTask + * @see net.kunmc.lab.kpm.installer.task.tasks.description.DescriptionLoadTask */ LOADING_PLUGIN_DESCRIPTION, /** @@ -42,25 +42,25 @@ public enum InstallTasks CHECKING_ENVIRONMENT, /** * 古いプラグインの削除中であることを示します。 - * このタスクは必ずしも実行されるわけではなく、{@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal} で {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal#setReplacePlugin(boolean)} に {@code true} が設定されてた場合にのみ実行されます。 + * このタスクは必ずしも実行されるわけではなく、{@link net.kunmc.lab.kpm.installer.impls.install.signals.AlreadyInstalledPluginSignal} で {@link net.kunmc.lab.kpm.installer.impls.install.signals.AlreadyInstalledPluginSignal#setReplacePlugin(boolean)} に {@code true} が設定されてた場合にのみ実行されます。 */ REMOVING_OLD_PLUGIN, /** * 依存関係のインストール中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectTask + * @see net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.DependsCollectTask */ COLLECTING_DEPENDENCIES, /** * プラグインの読み込み順序を計算中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal + * @see net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal */ COMPUTING_LOAD_ORDER, /** * プラグインのインストール中であることを示します。 * - * @see net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask + * @see net.kunmc.lab.kpm.installer.task.InstallTask */ INSTALLING_PLUGINS, } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java similarity index 76% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java index d255cf3c..faf26824 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java @@ -1,31 +1,31 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.install; - +package net.kunmc.lab.kpm.installer.impls.install; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.kpm.installer.signals.InvalidKPMInfoFileSignal; +import net.kunmc.lab.kpm.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.DependsCollectArgument; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.DependsCollectTask; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; +import net.kunmc.lab.kpm.installer.task.tasks.description.DescriptionLoadArgument; +import net.kunmc.lab.kpm.installer.task.tasks.description.DescriptionLoadResult; +import net.kunmc.lab.kpm.installer.task.tasks.description.DescriptionLoadTask; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.kpm.installer.task.tasks.install.PluginsInstallArgument; +import net.kunmc.lab.kpm.installer.task.tasks.install.PluginsInstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveArgument; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.kpm.kpminfo.InvalidInformationFileException; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; +import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.InvalidInformationFileException; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/AlreadyInstalledPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/signals/AlreadyInstalledPluginSignal.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/AlreadyInstalledPluginSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/signals/AlreadyInstalledPluginSignal.java index 845c50b8..21a29209 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/install/signals/AlreadyInstalledPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/signals/AlreadyInstalledPluginSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals; +package net.kunmc.lab.kpm.installer.impls.install.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterArgument.java similarity index 75% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterArgument.java index cf35e69b..971e3252 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; +package net.kunmc.lab.kpm.installer.impls.register; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; import org.jetbrains.annotations.Nullable; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterErrorCause.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterErrorCause.java index 3a6a555a..77e40110 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; +package net.kunmc.lab.kpm.installer.impls.register; /** * トークン登録のエラーを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterTasks.java similarity index 87% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterTasks.java index c45a0390..591be713 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/RegisterTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/RegisterTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; +package net.kunmc.lab.kpm.installer.impls.register; /** * トークン登録のタスクを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java similarity index 85% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java index a19b4146..31214800 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/TokenRegisterer.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java @@ -1,26 +1,26 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register; +package net.kunmc.lab.kpm.installer.impls.register; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos.UserVerificationCodeResponse; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos.VerificationSubmitPollingResponse; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenGenerateStartingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenStoredSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserDoesntCompleteVerifySignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerificationSuccessSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerifyDeniedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeExpiredSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeReceivedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.register.pojos.UserVerificationCodeResponse; +import net.kunmc.lab.kpm.installer.impls.register.pojos.VerificationSubmitPollingResponse; +import net.kunmc.lab.kpm.installer.impls.register.signals.TokenGenerateStartingSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.TokenStoredSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.UserDoesntCompleteVerifySignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.UserVerificationSuccessSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.UserVerifyDeniedSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeExpiredSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeReceivedSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeRequestFailedSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeRequestingSignal; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.kpm.utils.http.HTTPResponse; +import net.kunmc.lab.kpm.utils.http.RequestContext; +import net.kunmc.lab.kpm.utils.http.RequestMethod; +import net.kunmc.lab.kpm.utils.http.Requests; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/UserVerificationCodeResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/pojos/UserVerificationCodeResponse.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/UserVerificationCodeResponse.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/pojos/UserVerificationCodeResponse.java index e2700b9d..62c08655 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/UserVerificationCodeResponse.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/pojos/UserVerificationCodeResponse.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos; +package net.kunmc.lab.kpm.installer.impls.register.pojos; import com.google.gson.annotations.SerializedName; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/VerificationSubmitPollingResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/pojos/VerificationSubmitPollingResponse.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/VerificationSubmitPollingResponse.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/pojos/VerificationSubmitPollingResponse.java index aa617ab7..b8732f11 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/pojos/VerificationSubmitPollingResponse.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/pojos/VerificationSubmitPollingResponse.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos; +package net.kunmc.lab.kpm.installer.impls.register.pojos; import com.google.gson.annotations.SerializedName; import lombok.EqualsAndHashCode; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenGenerateStartingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenGenerateStartingSignal.java similarity index 74% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenGenerateStartingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenGenerateStartingSignal.java index 7aafa017..ed7c794f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenGenerateStartingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenGenerateStartingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; /** * トークンの生成の開始中であることを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenStoredSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenStoredSignal.java similarity index 68% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenStoredSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenStoredSignal.java index 7823e142..6fc42aca 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/TokenStoredSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenStoredSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java similarity index 81% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java index 9a73c184..1d07ffb6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerificationSuccessSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerificationSuccessSignal.java similarity index 79% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerificationSuccessSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerificationSuccessSignal.java index 82d9c7bb..b2382d44 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerificationSuccessSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerificationSuccessSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerifyDeniedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerifyDeniedSignal.java similarity index 65% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerifyDeniedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerifyDeniedSignal.java index 869d1d52..69a5ea9b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/UserVerifyDeniedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerifyDeniedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeExpiredSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeExpiredSignal.java similarity index 72% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeExpiredSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeExpiredSignal.java index 98c8006f..65fa939c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeExpiredSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeExpiredSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeReceivedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeReceivedSignal.java similarity index 81% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeReceivedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeReceivedSignal.java index b740ffc0..a01b8ed1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeReceivedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeReceivedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.pojos.UserVerificationCodeResponse; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.installer.impls.register.pojos.UserVerificationCodeResponse; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java similarity index 76% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java index 2295855d..84e51bb6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestingSignal.java similarity index 54% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestingSignal.java index bff543a6..997cf103 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/register/signals/VerificationCodeRequestingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestingSignal.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals; +package net.kunmc.lab.kpm.installer.impls.register.signals; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; /** * ユーザ検証コードの要求中であることを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstallSucceedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstallSucceedResult.java similarity index 59% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstallSucceedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstallSucceedResult.java index d1e1c7fe..d5e570c5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstallSucceedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstallSucceedResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; +package net.kunmc.lab.kpm.installer.impls.uninstall; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.kpm.installer.InstallProgress; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallResult; /** * プラグインのアンインストールの結果を表すクラスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java similarity index 81% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index 6d8828f6..f0297af7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -1,23 +1,23 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; - -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.PluginIsDependencySignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.SearchingPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.UninstallReadySignal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallTask; -import net.kunmc.lab.teamkunpluginmanager.meta.DependencyNode; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; -import net.kunmc.lab.teamkunpluginmanager.utils.ReversedCollector; +package net.kunmc.lab.kpm.installer.impls.uninstall; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.uninstall.signals.PluginIsDependencySignal; +import net.kunmc.lab.kpm.installer.impls.uninstall.signals.SearchingPluginSignal; +import net.kunmc.lab.kpm.installer.impls.uninstall.signals.UninstallReadySignal; +import net.kunmc.lab.kpm.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.DependsComputeOrderArgument; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.DependsComputeOrderTask; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallArgument; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallResult; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallTask; +import net.kunmc.lab.kpm.meta.DependencyNode; +import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.kpm.utils.PluginUtil; +import net.kunmc.lab.kpm.utils.ReversedCollector; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallErrorCause.java similarity index 53% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallErrorCause.java index 6f844a38..834e93e2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; +package net.kunmc.lab.kpm.installer.impls.uninstall; /** * アンインストールのエラーを表す列挙型です。 @@ -11,12 +11,12 @@ public enum UnInstallErrorCause PLUGIN_NOT_FOUND, /** * 指定されたプラグインが無視リストに登録されており、 - * {@link net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal} でも強制アンインストールが選択されませんでした。 + * {@link net.kunmc.lab.kpm.installer.signals.assertion.IgnoredPluginSignal} でも強制アンインストールが選択されませんでした。 */ PLUGIN_IGNORED, /** * 指定されたプラグインが他のプラグインの依存関係に含まれており、 - * {@link net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.PluginIsDependencySignal} でも強制アンインストールが選択されませんでした。 + * {@link net.kunmc.lab.kpm.installer.impls.uninstall.signals.PluginIsDependencySignal} でも強制アンインストールが選択されませんでした。 */ PLUGIN_IS_DEPENDENCY, } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallTasks.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallTasks.java index 1384c29a..f0491edc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UnInstallTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; +package net.kunmc.lab.kpm.installer.impls.uninstall; /** * アンインストールのタスクを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UninstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UninstallArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java index 316960d0..ac60e316 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/UninstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall; +package net.kunmc.lab.kpm.installer.impls.uninstall; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/PluginIsDependencySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/PluginIsDependencySignal.java similarity index 89% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/PluginIsDependencySignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/PluginIsDependencySignal.java index ee0c86f1..936929f0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/PluginIsDependencySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/PluginIsDependencySignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals; +package net.kunmc.lab.kpm.installer.impls.uninstall.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/SearchingPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/SearchingPluginSignal.java similarity index 64% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/SearchingPluginSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/SearchingPluginSignal.java index 6bb9c716..7fbe22dc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/SearchingPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/SearchingPluginSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals; +package net.kunmc.lab.kpm.installer.impls.uninstall.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/UninstallReadySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/UninstallReadySignal.java similarity index 82% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/UninstallReadySignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/UninstallReadySignal.java index 3fde6ffe..a2a8401a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/uninstall/signals/UninstallReadySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/UninstallReadySignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals; +package net.kunmc.lab.kpm.installer.impls.uninstall.signals; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/AliasUpdater.java similarity index 64% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/AliasUpdater.java index b561e673..7f620b3f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/AliasUpdater.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; +package net.kunmc.lab.kpm.installer.impls.update; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.signals.UpdateFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskFailedException; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.SourceDownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.SourceDownloadTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.UpdateAliasesArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.UpdateAliasesResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.UpdateAliasesTask; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.update.signals.UpdateFinishedSignal; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.SourceDownloadArgument; +import net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.SourceDownloadTask; +import net.kunmc.lab.kpm.installer.task.tasks.alias.update.UpdateAliasesArgument; +import net.kunmc.lab.kpm.installer.task.tasks.alias.update.UpdateAliasesResult; +import net.kunmc.lab.kpm.installer.task.tasks.alias.update.UpdateAliasesTask; +import net.kunmc.lab.kpm.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateArgument.java similarity index 74% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateArgument.java index ea838ccf..66c286be 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; +package net.kunmc.lab.kpm.installer.impls.update; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; import java.util.Map; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateErrorCause.java similarity index 64% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateErrorCause.java index 9e68b3bf..3ccd67ec 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; +package net.kunmc.lab.kpm.installer.impls.update; /** * エイリアスのアップデートのエラーを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateTasks.java similarity index 82% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateTasks.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateTasks.java index c1ad77a6..8c803251 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/UpdateTasks.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/UpdateTasks.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.update; +package net.kunmc.lab.kpm.installer.impls.update; /** * エイリアスのアップデートのタスクを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/signals/UpdateFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/signals/UpdateFinishedSignal.java similarity index 75% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/signals/UpdateFinishedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/signals/UpdateFinishedSignal.java index b7efcc9e..04d1d37c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/impls/update/signals/UpdateFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/signals/UpdateFinishedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.impls.update.signals; +package net.kunmc.lab.kpm.installer.impls.update.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import java.util.HashMap; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InstallFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InstallFinishedSignal.java similarity index 56% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InstallFinishedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InstallFinishedSignal.java index 29dcc052..ed17f296 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InstallFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InstallFinishedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.signals; +package net.kunmc.lab.kpm.installer.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.signal.Signal; /** * インストールが完了したことを表すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InvalidKPMInfoFileSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InvalidKPMInfoFileSignal.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InvalidKPMInfoFileSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InvalidKPMInfoFileSignal.java index de2cff50..02bffe8b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/InvalidKPMInfoFileSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InvalidKPMInfoFileSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.signals; +package net.kunmc.lab.kpm.installer.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/PluginModifiedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/PluginModifiedSignal.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/PluginModifiedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/PluginModifiedSignal.java index 4f1b4377..ab627ee3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/PluginModifiedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/PluginModifiedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.signals; +package net.kunmc.lab.kpm.installer.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/assertion/IgnoredPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/assertion/IgnoredPluginSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java index 1f84cbe7..c9ea8a4e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/signals/assertion/IgnoredPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion; +package net.kunmc.lab.kpm.installer.signals.assertion; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/InstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/InstallTask.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/InstallTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/InstallTask.java index 6886ece1..7f1a3b21 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/InstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/InstallTask.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task; +package net.kunmc.lab.kpm.installer.task; import lombok.AllArgsConstructor; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; +import net.kunmc.lab.kpm.installer.InstallProgress; +import net.kunmc.lab.kpm.signal.Signal; +import net.kunmc.lab.kpm.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskArgument.java similarity index 62% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskArgument.java index 0b0f4af1..656a89ec 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskArgument.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task; +package net.kunmc.lab.kpm.installer.task; /** * タスクの引数の基底クラスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskChain.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskChain.java index bcee021e..7ccf0def 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskChain.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskChain.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task; +package net.kunmc.lab.kpm.installer.task; import lombok.AccessLevel; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.AbstractInstaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskFailedException.java similarity index 92% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskFailedException.java index c7fb7190..6f0de874 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskFailedException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskFailedException.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task; +package net.kunmc.lab.kpm.installer.task; import lombok.Getter; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskResult.java similarity index 92% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskResult.java index b86a4ebb..45ae0252 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/TaskResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task; +package net.kunmc.lab.kpm.installer.task; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadArgument.java similarity index 74% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadArgument.java index 16f136dc..f843a460 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import java.util.Map; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java similarity index 73% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java index 5da17781..dd6a9433 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download; /** * ソースファイルのダウンロードに失敗した理由を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadResult.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadResult.java index 9c4346d7..7b70c000 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.kpm.installer.task.TaskResult; +import net.kunmc.lab.kpm.utils.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadState.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadState.java index 32b1233f..85aa0627 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download; /** * ソースファイルのダウンロードの状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadTask.java similarity index 78% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadTask.java index 0543f38f..22d8b219 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/SourceDownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadTask.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download; - -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.SourceDownloadFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.UnsupportedProtocolSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download; + +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; +import net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals.SourceDownloadFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals.UnsupportedProtocolSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.kpm.utils.Pair; import org.jetbrains.annotations.NotNull; import java.net.MalformedURLException; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java index f11f69f7..efc49a21 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java similarity index 73% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java index 3826a8af..8e84da5c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/MalformedURLSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals; /** * 不正なURLが指定された場合に送信されるシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java similarity index 51% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java index 3b737da6..620c2de9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.kpm.signal.Signal; /** * ソースファイルのダウンロードに失敗したことを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java similarity index 84% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java index 98fdec4c..0af5f592 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/UnsupportedProtocolSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals; import lombok.Getter; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesArgument.java similarity index 73% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesArgument.java index e8f6a8cd..852a947d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.kpm.installer.task.TaskArgument; +import net.kunmc.lab.kpm.utils.Pair; import java.net.URL; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java similarity index 74% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java index e3b84f4c..93e10930 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update; /** * エイリアスのアップデートに失敗した理由を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesResult.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesResult.java index 63eaed22..3ac20ffc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesState.java similarity index 81% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesState.java index 45c92098..a8a50f7e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update; /** * エイリアスのアップデートの状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesTask.java similarity index 85% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesTask.java index 42101f0c..052de20d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/UpdateAliasesTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesTask.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update; import com.google.gson.JsonSyntaxException; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.alias.AliasUpdater; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.AliasUpdateSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.InvalidSourceSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.SourcePreparedSignal; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.alias.AliasUpdater; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals.AliasUpdateSignal; +import net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals.InvalidSourceSignal; +import net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals.SourcePreparedSignal; +import net.kunmc.lab.kpm.utils.Pair; import org.jetbrains.annotations.NotNull; import java.io.BufferedReader; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java similarity index 84% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java index 34673a2b..3af2f784 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.net.URL; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java index 727ec8eb..5c515d47 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/InvalidSourceSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java index e452b436..f797fa08 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourcePreparedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals; import lombok.Getter; import lombok.Setter; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourceSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourceSignal.java similarity index 78% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourceSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourceSignal.java index ab32ba62..640ba35c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/alias/update/signals/SourceSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourceSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals; +package net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/DependencyElement.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/DependencyElement.java index ae4ce5f4..918b2ede 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/DependencyElement.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/DependencyElement.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies; import lombok.AllArgsConstructor; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectArgument.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectArgument.java index 70efa177..d92d1725 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java similarity index 72% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java index e8abbae4..fa68ac8c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector; /** * 依存関係の取得に失敗した理由を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectResult.java similarity index 85% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectResult.java index bbe6adc4..da115d5f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectState.java similarity index 87% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectState.java index cf7755d9..7cf5370c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector; /** * 依存関係取得の状態を表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectStatus.java similarity index 93% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectStatus.java index 1bae3739..952af262 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectStatus.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectStatus.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.InstallProgress; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectTask.java similarity index 82% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectTask.java index 3117bdb9..ba235569 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -1,30 +1,30 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector; - -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyDownloadFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependsCollectFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependsDownloadFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependsEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveTask; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.InvalidInformationFileException; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.signals.InvalidKPMInfoFileSignal; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyDownloadFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependsCollectFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependsDownloadFinishedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependsEnumeratedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadArgument; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadTask; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveArgument; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveResult; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.kpm.kpminfo.InvalidInformationFileException; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.utils.Pair; +import net.kunmc.lab.kpm.utils.PluginUtil; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java similarity index 77% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java index cfbcfb30..d12a2bef 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java similarity index 76% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java index 0968045a..893036b0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; /** * 依存関係の取得に失敗したことを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java similarity index 84% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java index 9913b889..c7433511 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyDownloadFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.Getter; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java similarity index 78% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java index db752016..664de3f0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyLoadDescriptionFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; /** * 依存関係のプラグイン情報ファイルの読み込みに失敗したことを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java similarity index 89% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java index dac4daaf..711a7ae0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyNameMismatchSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.Getter; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java similarity index 74% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java index cd16081f..1ae4394e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyResolveFailedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; /** * 依存関係の解決に失敗したことを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java similarity index 76% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java index 7a4936f0..467f0489 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java similarity index 61% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java index ee23147e..b8b22df6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadResult; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadResult; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java similarity index 77% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java index d54073e0..2446eecc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.AllArgsConstructor; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java similarity index 62% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java index 57e790ff..25f53eac 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer; import lombok.AllArgsConstructor; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java similarity index 64% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java index e53d4e97..6188323f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer; /** * 依存関係の読み込み順序を計算する際に発生したエラーの原因を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java similarity index 77% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java index a708b3ea..14e3c497 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java similarity index 85% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java index 75acfdc0..017f19d1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer; /** * 依存関係の読み込み順序計算の状態を表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java similarity index 93% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index ca17a809..a1a05962 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java index 7dc9ed7c..d51e5d55 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals; +package net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.util.Collections; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadArgument.java similarity index 79% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadArgument.java index dbd2e538..212b8b4f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; +package net.kunmc.lab.kpm.installer.task.tasks.description; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadErrorCause.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadErrorCause.java index 9585178f..4a9ccf76 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; +package net.kunmc.lab.kpm.installer.task.tasks.description; /** * プラグイン情報ファイルの読み込みに失敗した際のエラーの原因を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadResult.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadResult.java index e0ff74f7..9f9f7e1c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; +package net.kunmc.lab.kpm.installer.task.tasks.description; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadState.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadState.java index 37877114..4ab1bc74 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; +package net.kunmc.lab.kpm.installer.task.tasks.description; /** * プラグイン情報ファイルの読み込みの状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadTask.java similarity index 84% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadTask.java index c0e106c4..27ca65ff 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/DescriptionLoadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/DescriptionLoadTask.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description; +package net.kunmc.lab.kpm.installer.task.tasks.description; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; +import net.kunmc.lab.kpm.utils.PluginUtil; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java similarity index 78% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java index b7973b37..6612ce22 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.signals; +package net.kunmc.lab.kpm.installer.task.tasks.description.signals; import lombok.AllArgsConstructor; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadArgument.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadArgument.java index 8aa28071..c202f09c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; +package net.kunmc.lab.kpm.installer.task.tasks.download; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadErrorCause.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadErrorCause.java index 9abf1e63..2f76af5e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; +package net.kunmc.lab.kpm.installer.task.tasks.download; /** * ダウンロードに失敗した際のエラーの原因を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadResult.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadResult.java index 53605a29..32900cd8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; +package net.kunmc.lab.kpm.installer.task.tasks.download; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadState.java similarity index 84% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadState.java index 1241c8b1..50a17832 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; +package net.kunmc.lab.kpm.installer.task.tasks.download; /** * ダウンロードの状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadTask.java similarity index 81% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadTask.java index 2b117de2..b63a15b9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/DownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/DownloadTask.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download; - -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadStartingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; -import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +package net.kunmc.lab.kpm.installer.task.tasks.download; + +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadErrorSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadStartingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadSucceedSignal; +import net.kunmc.lab.kpm.utils.http.DownloadProgress; +import net.kunmc.lab.kpm.utils.http.RequestMethod; +import net.kunmc.lab.kpm.utils.http.Requests; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadErrorSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadErrorSignal.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadErrorSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadErrorSignal.java index 4a04a4a8..73e55c67 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadErrorSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadErrorSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.download.signals; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadErrorCause; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadErrorCause; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadProgressSignal.java similarity index 93% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadProgressSignal.java index a2d1ea7c..730d17a0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadProgressSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadProgressSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.download.signals; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSignal.java similarity index 72% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSignal.java index d912d3ab..89983f84 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.download.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadStartingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadStartingSignal.java similarity index 89% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadStartingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadStartingSignal.java index 18d43f69..88369e18 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadStartingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadStartingSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.download.signals; import lombok.Getter; import lombok.Setter; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSucceedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSucceedSignal.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSucceedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSucceedSignal.java index 4f5e1bdf..8d58ec32 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/download/signals/DownloadSucceedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSucceedSignal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals; +package net.kunmc.lab.kpm.installer.task.tasks.download.signals; import lombok.EqualsAndHashCode; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanArgument.java similarity index 75% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanArgument.java index b1c51383..da1a91ed 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java index 6b6d9629..a1aa61a1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean; /** * 不要データ削除のエラーを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanResult.java similarity index 84% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanResult.java index 290fed89..43201c49 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanState.java similarity index 79% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanState.java index 12f2f7ac..d659c39b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean; /** * 不要データ削除の状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanTask.java similarity index 82% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanTask.java index 60a13d09..529bc477 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/GarbageCleanTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/GarbageCleanTask.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean; - -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageDeleteSkippedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageDeletingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.InvalidIntegritySignal; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean; + +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal.GarbageDeleteSkippedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal.GarbageDeletingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal.InvalidIntegritySignal; import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java similarity index 72% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java index 3bdf6f24..1e47d7d7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java similarity index 87% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java index 5a043e3c..aabbe476 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal; import lombok.Data; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java similarity index 75% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java index 4725a1ed..c6da8f70 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import java.nio.file.Path; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java similarity index 60% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java index b1cf7fe4..47566554 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; /** * 整合性がとれなく、システムが保護されたことを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchArgument.java similarity index 82% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchArgument.java index 459e4b92..8b288a4f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchArgument.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.search; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java similarity index 71% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java index d9d1733b..ab573cf8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.search; /** * 不要データ検索のエラーを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchResult.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchResult.java index af23df95..1710b104 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.search; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchState.java similarity index 79% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchState.java index e8fa0920..0214b3bb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.search; /** * 不要データ検索の状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchTask.java similarity index 86% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchTask.java index b3f2974b..87827c0f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/GarbageSearchTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/GarbageSearchTask.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.search; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java similarity index 67% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java index 5d09ae96..00383ee1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals; +package net.kunmc.lab.kpm.installer.task.tasks.garbage.search.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallArgument.java similarity index 74% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallArgument.java index a4a8ec95..b54fe6f0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallArgument.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; +package net.kunmc.lab.kpm.installer.task.tasks.install; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; +import net.kunmc.lab.kpm.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallErrorCause.java similarity index 92% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallErrorCause.java index 028890f4..c5fa0b13 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; +package net.kunmc.lab.kpm.installer.task.tasks.install; /** * プラグインのインストール時に発生したエラーの原因を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallResult.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallResult.java index 930c1649..a4a6cf96 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; +package net.kunmc.lab.kpm.installer.task.tasks.install; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallState.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallState.java index 78fdf952..e532751a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; +package net.kunmc.lab.kpm.installer.task.tasks.install; /** * プラグインのインストールの状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java index c07c7ad3..321d8ae5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java @@ -1,22 +1,22 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install; - +package net.kunmc.lab.kpm.installer.task.tasks.install; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginEnablingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginInstallingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginLoadSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; +import net.kunmc.lab.kpm.loader.CommandsPatcher; +import net.kunmc.lab.kpm.meta.InstallOperator; +import net.kunmc.lab.kpm.meta.PluginMetaManager; +import net.kunmc.lab.kpm.meta.PluginMetaProvider; +import net.kunmc.lab.kpm.utils.versioning.Version; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.DependencyElement; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginInstallingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginLoadSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginRelocatingSignal; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; -import net.kunmc.lab.teamkunpluginmanager.loader.CommandsPatcher; -import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; -import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.entity.Player; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginEnablingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginEnablingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java index 15fcf14d..afbe2885 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginEnablingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals; +package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java index 517cd677..517d1cf2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals; +package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.kpminfo.KPMInformationFile; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; +import net.kunmc.lab.kpm.signal.Signal; +import net.kunmc.lab.kpm.utils.versioning.Version; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginInstallingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginInstallingSignal.java similarity index 79% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginInstallingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginInstallingSignal.java index acda5174..54d8c89d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginInstallingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginInstallingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals; +package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginLoadSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginLoadSignal.java similarity index 92% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginLoadSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginLoadSignal.java index 84222948..59de718e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginLoadSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginLoadSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals; +package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java similarity index 87% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java index 55f8f69c..682a264c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals; +package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginRelocatingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginRelocatingSignal.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginRelocatingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginRelocatingSignal.java index acdc9aa0..f7248161 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/install/signals/PluginRelocatingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginRelocatingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals; +package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveArgument.java similarity index 76% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveArgument.java index 3337b930..b8b69d73 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve; +package net.kunmc.lab.kpm.installer.task.tasks.resolve; import lombok.Data; import lombok.EqualsAndHashCode; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveErrorCause.java similarity index 77% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveErrorCause.java index ab1fe76a..4958b034 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveErrorCause.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve; +package net.kunmc.lab.kpm.installer.task.tasks.resolve; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; /** * プラグインの解決に失敗した理由を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveResult.java similarity index 81% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveResult.java index 143aee69..89c04094 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve; +package net.kunmc.lab.kpm.installer.task.tasks.resolve; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveState.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveState.java index f6061f22..7f691776 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve; +package net.kunmc.lab.kpm.installer.task.tasks.resolve; /** * プラグインの解決の状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java index 91ffd0c1..fa178508 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/PluginResolveTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve; - -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolvingSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +package net.kunmc.lab.kpm.installer.task.tasks.resolve; + +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.signals.PluginResolvingSignal; +import net.kunmc.lab.kpm.resolver.PluginResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java similarity index 73% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java index bebc35e0..db72187a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals; +package net.kunmc.lab.kpm.installer.task.tasks.resolve.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java similarity index 60% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java index c1abc86a..1e93f41f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals; +package net.kunmc.lab.kpm.installer.task.tasks.resolve.signals; import lombok.Data; import lombok.NonNull; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.signal.Signal; /** * プラグインの解決に失敗したことを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java similarity index 67% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java index 0a0997f0..199f2d13 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals; +package net.kunmc.lab.kpm.installer.task.tasks.resolve.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolvingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvingSignal.java similarity index 68% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolvingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvingSignal.java index b7243d8b..3570090b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/resolve/signals/PluginResolvingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvingSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals; +package net.kunmc.lab.kpm.installer.task.tasks.resolve.signals; import lombok.AllArgsConstructor; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.resolver.PluginResolver; +import net.kunmc.lab.kpm.signal.Signal; /** * プラグインの解決中であることを示すシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallArgument.java similarity index 73% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallArgument.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallArgument.java index f5607929..d6ef68ab 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallArgument.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskArgument; +import net.kunmc.lab.kpm.installer.task.TaskArgument; import org.bukkit.plugin.Plugin; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallErrorCause.java similarity index 89% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallErrorCause.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallErrorCause.java index fd3a5021..2b983045 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallErrorCause.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall; /** * アンインストールに失敗した理由を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallResult.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallResult.java index 2bbb44a8..0f003153 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.installer.task.TaskResult; +import net.kunmc.lab.kpm.installer.task.TaskResult; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallState.java similarity index 92% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallState.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallState.java index be3845a2..536b2061 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallState.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallState.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall; /** * アンインストールの状態を表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java similarity index 89% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java index c71b1b7c..9737abca 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/UnInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java @@ -1,17 +1,17 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall; - +package net.kunmc.lab.kpm.installer.task.tasks.uninstall; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginDisablingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.StartingGCSignal; +import net.kunmc.lab.kpm.loader.CommandsPatcher; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.task.InstallTask; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginDisablingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.StartingGCSignal; -import net.kunmc.lab.teamkunpluginmanager.loader.CommandsPatcher; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java similarity index 85% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java index 191425d8..2b148e19 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java similarity index 94% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java index 5fd2ba6e..1dee0056 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; import lombok.Data; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.inventory.Recipe; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java similarity index 67% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java index 563da8b7..61d4a33d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallErrorCause; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java similarity index 68% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java index bc9db1ee..6aa28e58 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java index a11c10c2..7fad4af1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals; +package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; import lombok.EqualsAndHashCode; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; +import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java new file mode 100644 index 00000000..2ac57a4e --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; + +import net.kunmc.lab.kpm.signal.Signal; + +/** + * VMのGCを実行することを通知するシグナルです。 + */ +public class StartingGCSignal implements Signal +{ +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/InvalidInformationFileException.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/InvalidInformationFileException.java similarity index 84% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/InvalidInformationFileException.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/InvalidInformationFileException.java index 33a56607..75b2b075 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/InvalidInformationFileException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/InvalidInformationFileException.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.kpminfo; +package net.kunmc.lab.kpm.kpminfo; public class InvalidInformationFileException extends Exception { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java index 8acbaf8f..c5caf693 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.kpminfo; +package net.kunmc.lab.kpm.kpminfo; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.utils.PluginUtil; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java similarity index 93% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java index 7fc01ab5..8159c040 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInfoParser.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.kpminfo; +package net.kunmc.lab.kpm.kpminfo; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.utils.versioning.Version; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.yaml.snakeyaml.Yaml; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java index e516d075..25415fe6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.kpminfo; +package net.kunmc.lab.kpm.kpminfo; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.utils.versioning.Version; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.utils.versioning.Version; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/CommandsPatcher.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/CommandsPatcher.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/CommandsPatcher.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/CommandsPatcher.java index 1eac570b..f9d5d1a0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/CommandsPatcher.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/CommandsPatcher.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.loader; +package net.kunmc.lab.kpm.loader; import com.mojang.brigadier.CommandDispatcher; -import net.kunmc.lab.teamkunpluginmanager.utils.ReflectionUtils; +import net.kunmc.lab.kpm.utils.ReflectionUtils; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoadResult.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoadResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoadResult.java index 3693e670..e521335e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoadResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.loader; +package net.kunmc.lab.kpm.loader; import lombok.Getter; import org.bukkit.plugin.Plugin; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoader.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoader.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoader.java index 53b9572d..da490fc1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/loader/PluginLoader.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoader.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.loader; +package net.kunmc.lab.kpm.loader; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.command.Command; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/DependType.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/DependType.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/DependType.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/DependType.java index 4eca5dca..63f749b5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/DependType.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/DependType.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; /** * 依存の種類です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/DependencyNode.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/DependencyNode.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/DependencyNode.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/DependencyNode.java index 2fb476bf..2c565919 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/DependencyNode.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/DependencyNode.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/InstallOperator.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/InstallOperator.java similarity index 94% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/InstallOperator.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/InstallOperator.java index 8be3828b..4de08e09 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/InstallOperator.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/InstallOperator.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; /** * プラグインが誰によってインストールされたかを表します。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/MetaSQLUtil.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/MetaSQLUtil.java similarity index 97% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/MetaSQLUtil.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/MetaSQLUtil.java index c916e1ec..d814cada 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/MetaSQLUtil.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/MetaSQLUtil.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; import com.zaxxer.hikari.HikariDataSource; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMeta.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java similarity index 96% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMeta.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java index 1b29e5f4..6935a6df 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMeta.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; import lombok.Value; import org.bukkit.plugin.PluginLoadOrder; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaIterator.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java similarity index 97% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaIterator.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java index 8ea986fc..54c4210a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaIterator.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; -import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; +import net.kunmc.lab.kpm.utils.db.Transaction; import org.bukkit.plugin.PluginLoadOrder; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java index 1fabbec1..1bac8cf4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; import lombok.Getter; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java index eaf7630e..b84fec45 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.meta; +package net.kunmc.lab.kpm.meta; import com.zaxxer.hikari.HikariDataSource; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.utils.db.Transaction; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.utils.db.Transaction; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java similarity index 92% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java index 03ec3812..57a9e3be 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/PluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver; +package net.kunmc.lab.kpm.resolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.PipeResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.interfaces.URLResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.PipeResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; import java.net.MalformedURLException; import java.net.URL; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/QueryContext.java similarity index 97% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/QueryContext.java index abaec961..0789b5ec 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/QueryContext.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/QueryContext.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver; +package net.kunmc.lab.kpm.resolver; import lombok.Builder; import lombok.Data; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java similarity index 77% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java index 6949de9c..d9189186 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/BruteforceGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; import lombok.AllArgsConstructor; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/CurseBukkitResolver.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/CurseBukkitResolver.java index f29699c8..2b46376b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/CurseBukkitResolver.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.URLResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.utils.http.HTTPResponse; +import net.kunmc.lab.kpm.utils.http.RequestContext; +import net.kunmc.lab.kpm.utils.http.Requests; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/CurseBukkitSuccessResult.java similarity index 83% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/CurseBukkitSuccessResult.java index f76d4dcc..d152d733 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/CurseBukkitSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/CurseBukkitSuccessResult.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.kpm.resolver.result.MarketplaceResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.utils.http.HTTPResponse; +import net.kunmc.lab.kpm.utils.http.RequestContext; +import net.kunmc.lab.kpm.utils.http.Requests; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java similarity index 85% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java index a6b6fa2f..ced70e1d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.result.MarketplaceResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java index 81bf9e46..0675106b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java @@ -1,17 +1,17 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.URLResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.utils.http.HTTPResponse; +import net.kunmc.lab.kpm.utils.http.RequestContext; +import net.kunmc.lab.kpm.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/OmittedGitHubResolver.java similarity index 65% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/OmittedGitHubResolver.java index b884553f..9320bd43 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/OmittedGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/OmittedGitHubResolver.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.PipeResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.PipeResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; import org.apache.commons.lang.StringUtils; public class OmittedGitHubResolver implements BaseResolver diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/SpigotMCResolver.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/SpigotMCResolver.java index 85f240a7..2512f7e4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/SpigotMCResolver.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.URLResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; -import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestContext; -import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.URLResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.utils.http.HTTPResponse; +import net.kunmc.lab.kpm.utils.http.RequestContext; +import net.kunmc.lab.kpm.utils.http.Requests; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/SpigotMCSuccessResult.java similarity index 74% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/SpigotMCSuccessResult.java index fa3125a8..25f36fdd 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/impl/SpigotMCSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/SpigotMCSuccessResult.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.impl; +package net.kunmc.lab.kpm.resolver.impl; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.VersionedResult; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.result.MarketplaceResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.resolver.result.VersionedResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java similarity index 80% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java index d4bfd6d8..801e5b89 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/BaseResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +package net.kunmc.lab.kpm.resolver.interfaces; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; /** * プラグインの解決を行うクラスのインターフェースです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java similarity index 92% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java index d1594a69..d41ce771 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/interfaces/URLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.interfaces; +package net.kunmc.lab.kpm.resolver.interfaces; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.utils.http.HTTPResponse; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.utils.http.HTTPResponse; import java.net.MalformedURLException; import java.net.URL; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/ErrorResult.java similarity index 94% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/ErrorResult.java index 3af97005..80942984 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ErrorResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/ErrorResult.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.kpm.resolver.result; import lombok.EqualsAndHashCode; import lombok.Getter; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/MarketplaceResult.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/MarketplaceResult.java index e0fe5aa2..1c97a6ad 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MarketplaceResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/MarketplaceResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.kpm.resolver.result; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/MultiResult.java similarity index 71% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/MultiResult.java index 51fb8629..63bfe451 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/MultiResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/MultiResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.kpm.resolver.result; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; /** * 解決結果が複数ある場合に返されるクラスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/PipeResult.java similarity index 69% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/PipeResult.java index cf719c56..69b32521 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/PipeResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/PipeResult.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.kpm.resolver.result; import lombok.Value; -import net.kunmc.lab.teamkunpluginmanager.resolver.PluginResolver; -import net.kunmc.lab.teamkunpluginmanager.resolver.QueryContext; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.PluginResolver; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/ResolveResult.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/ResolveResult.java index 5166f575..b973aa67 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/ResolveResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/ResolveResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.kpm.resolver.result; import lombok.AllArgsConstructor; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; /** * プラグイン解決結果のインタフェースです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/SuccessResult.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/SuccessResult.java index 057a17ca..57d0b894 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/SuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/SuccessResult.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.kpm.resolver.result; import lombok.Data; -import net.kunmc.lab.teamkunpluginmanager.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/VersionedResult.java similarity index 82% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/VersionedResult.java index 6c9372d2..840f523d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/resolver/result/VersionedResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/result/VersionedResult.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.resolver.result; +package net.kunmc.lab.kpm.resolver.result; import java.util.List; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/Signal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/Signal.java similarity index 91% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/Signal.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/Signal.java index 768b92a8..d66b9daa 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/Signal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/Signal.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.signal; +package net.kunmc.lab.kpm.signal; /** * インストーラやタスクなどからスローされるシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandleManager.java similarity index 96% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandleManager.java index e8b3ced4..3e5af5c4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandleManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandleManager.java @@ -1,6 +1,6 @@ -package net.kunmc.lab.teamkunpluginmanager.signal; +package net.kunmc.lab.kpm.signal; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; +import net.kunmc.lab.kpm.installer.InstallProgress; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandler.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandler.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandler.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandler.java index beef22a6..eddce450 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandler.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandler.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.signal; +package net.kunmc.lab.kpm.signal; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java index 01f713c4..1f143ab5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlerList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager.signal; +package net.kunmc.lab.kpm.signal; +import net.kunmc.lab.kpm.installer.InstallProgress; import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/Pair.java similarity index 62% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/Pair.java index 7256382c..58b1fb00 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/Pair.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/Pair.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.kpm.utils; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/PluginUtil.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/PluginUtil.java index 9c8290bc..22562e4d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/PluginUtil.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/PluginUtil.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.kpm.utils; import org.bukkit.Bukkit; import org.bukkit.configuration.MemorySection; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReflectionUtils.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReflectionUtils.java index 5dac71ba..4b952e60 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReflectionUtils.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReflectionUtils.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.kpm.utils; import org.bukkit.Bukkit; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReversedCollector.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReversedCollector.java index f6000790..85f56e96 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/ReversedCollector.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReversedCollector.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils; +package net.kunmc.lab.kpm.utils; import java.util.ArrayList; import java.util.EnumSet; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/ResultRow.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/ResultRow.java index cceac57a..1faf6d3d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/ResultRow.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/ResultRow.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.db; +package net.kunmc.lab.kpm.utils.db; import lombok.AllArgsConstructor; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/Transaction.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/Transaction.java index 3fb5e804..1420c17f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/db/Transaction.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/Transaction.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.db; +package net.kunmc.lab.kpm.utils.db; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/DownloadProgress.java similarity index 88% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/DownloadProgress.java index 9669b864..9056f899 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/DownloadProgress.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/DownloadProgress.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.kpm.utils.http; import lombok.Value; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/HTTPResponse.java similarity index 99% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/HTTPResponse.java index 106a4114..7a7c5074 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/HTTPResponse.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/HTTPResponse.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.kpm.utils.http; import com.google.gson.Gson; import com.google.gson.JsonElement; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/RequestContext.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/RequestContext.java index 0e9af511..931f21db 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestContext.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/RequestContext.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.kpm.utils.http; import lombok.Builder; import lombok.Singular; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/RequestMethod.java similarity index 90% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/RequestMethod.java index 91d90e04..011997c7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/RequestMethod.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/RequestMethod.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.kpm.utils.http; /** * HTTPリクエストのメソッドを表す列挙型です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/Requests.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/Requests.java index 07adb923..cd7537c0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/http/Requests.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/http/Requests.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.http; +package net.kunmc.lab.kpm.utils.http; import lombok.Getter; import lombok.Setter; -import net.kunmc.lab.teamkunpluginmanager.TokenStore; +import net.kunmc.lab.kpm.TokenStore; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/InvalidVersionSyntaxException.java similarity index 81% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/InvalidVersionSyntaxException.java index 8a8391fb..f2005343 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/InvalidVersionSyntaxException.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/InvalidVersionSyntaxException.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.versioning; +package net.kunmc.lab.kpm.utils.versioning; /** * バージョンの構文が不正な場合に投げられる例外です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/Version.java similarity index 98% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/Version.java index c73214d9..fb565325 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/Version.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/Version.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.versioning; +package net.kunmc.lab.kpm.utils.versioning; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionComparator.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/VersionComparator.java similarity index 76% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionComparator.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/VersionComparator.java index cc720408..56095590 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionComparator.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/VersionComparator.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.versioning; +package net.kunmc.lab.kpm.utils.versioning; import java.util.Comparator; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/VersionElement.java similarity index 95% rename from KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/VersionElement.java index b1830fb9..7a486a2c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionElement.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/versioning/VersionElement.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.versioning; +package net.kunmc.lab.kpm.utils.versioning; import lombok.Getter; import org.jetbrains.annotations.NotNull; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/StartingGCSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/StartingGCSignal.java deleted file mode 100644 index ca6158ea..00000000 --- a/KPMDaemon/src/main/java/net/kunmc/lab/teamkunpluginmanager/installer/task/tasks/uninstall/signals/StartingGCSignal.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals; - -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; - -/** - * VMのGCを実行することを通知するシグナルです。 - */ -public class StartingGCSignal implements Signal -{ -} diff --git a/KPMDaemon/src/test/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionTest.java b/KPMDaemon/src/test/java/net/kunmc/lab/kpm/utils/versioning/VersionTest.java similarity index 98% rename from KPMDaemon/src/test/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionTest.java rename to KPMDaemon/src/test/java/net/kunmc/lab/kpm/utils/versioning/VersionTest.java index a531c31d..2fddbaa9 100644 --- a/KPMDaemon/src/test/java/net/kunmc/lab/teamkunpluginmanager/utils/versioning/VersionTest.java +++ b/KPMDaemon/src/test/java/net/kunmc/lab/kpm/utils/versioning/VersionTest.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.utils.versioning; +package net.kunmc.lab.kpm.utils.versioning; import org.junit.jupiter.api.Test; diff --git a/KPMPlugin/pom.xml b/KPMPlugin/pom.xml index b39954f6..b542f389 100644 --- a/KPMPlugin/pom.xml +++ b/KPMPlugin/pom.xml @@ -10,6 +10,7 @@ 4.0.0 + net.kunmc.lab.kpm KPMPlugin diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java similarity index 80% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java index 0fed0c4f..44febc3d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/HeadInstallers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java @@ -1,25 +1,25 @@ -package net.kunmc.lab.teamkunpluginmanager; +package net.kunmc.lab.kpm; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.installer.exceptions.InstallerRunningException; +import net.kunmc.lab.kpm.installer.exceptions.TokenNotAvailableException; +import net.kunmc.lab.kpm.installer.impls.autoremove.AutoRemoveArgument; +import net.kunmc.lab.kpm.installer.impls.autoremove.PluginAutoRemover; +import net.kunmc.lab.kpm.installer.impls.clean.CleanArgument; +import net.kunmc.lab.kpm.installer.impls.clean.GarbageCleaner; +import net.kunmc.lab.kpm.installer.impls.install.InstallArgument; +import net.kunmc.lab.kpm.installer.impls.install.PluginInstaller; +import net.kunmc.lab.kpm.installer.impls.register.RegisterArgument; +import net.kunmc.lab.kpm.installer.impls.register.TokenRegisterer; +import net.kunmc.lab.kpm.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.kpm.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.kpm.installer.impls.update.AliasUpdater; +import net.kunmc.lab.kpm.installer.impls.update.UpdateArgument; +import net.kunmc.lab.kpm.signal.HeadSignalHandlers; +import net.kunmc.lab.kpm.signal.SignalHandleManager; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.AbstractInstallerArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.InstallerRunningException; -import net.kunmc.lab.teamkunpluginmanager.installer.exceptions.TokenNotAvailableException; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.PluginAutoRemover; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.CleanArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.GarbageCleaner; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.PluginInstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.RegisterArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.TokenRegisterer; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.AliasUpdater; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; -import net.kunmc.lab.teamkunpluginmanager.signal.HeadSignalHandlers; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java similarity index 80% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java index 251308d1..6a71acef 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java @@ -1,19 +1,19 @@ -package net.kunmc.lab.teamkunpluginmanager; +package net.kunmc.lab.kpm; import lombok.Getter; +import net.kunmc.lab.kpm.commands.CommandAutoRemove; +import net.kunmc.lab.kpm.commands.CommandClean; +import net.kunmc.lab.kpm.commands.CommandDebug; +import net.kunmc.lab.kpm.commands.CommandInfo; +import net.kunmc.lab.kpm.commands.CommandInstall; +import net.kunmc.lab.kpm.commands.CommandRegister; +import net.kunmc.lab.kpm.commands.CommandReload; +import net.kunmc.lab.kpm.commands.CommandResolve; +import net.kunmc.lab.kpm.commands.CommandStatus; +import net.kunmc.lab.kpm.commands.CommandUninstall; +import net.kunmc.lab.kpm.commands.CommandUpdate; import net.kunmc.lab.peyangpaperutils.lib.command.CommandManager; import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandAutoRemove; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandClean; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandDebug; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandInfo; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandInstall; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandRegister; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandReload; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandResolve; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandStatus; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandUninstall; -import net.kunmc.lab.teamkunpluginmanager.commands.CommandUpdate; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/Utils.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/Utils.java similarity index 92% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/Utils.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/Utils.java index cd674586..a8e3f389 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/Utils.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/Utils.java @@ -1,7 +1,7 @@ -package net.kunmc.lab.teamkunpluginmanager; +package net.kunmc.lab.kpm; +import net.kunmc.lab.kpm.installer.InstallResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; import org.bukkit.ChatColor; public class Utils diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandAutoRemove.java similarity index 86% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandAutoRemove.java index fae0f972..b48e3398 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandAutoRemove.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandAutoRemove.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.installer.impls.autoremove.AutoRemoveArgument; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandClean.java similarity index 87% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandClean.java index 6e2064df..0fe89eae 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandClean.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandClean.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.installer.impls.clean.CleanArgument; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.clean.CleanArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandDebug.java similarity index 78% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandDebug.java index 4bff33b6..d67ae7fe 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandDebug.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.commands.debug.CommandDepTreeDebug; +import net.kunmc.lab.kpm.commands.debug.CommandInstallDebug; +import net.kunmc.lab.kpm.commands.debug.CommandUninstallDebug; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandDepTreeDebug; -import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandInstallDebug; -import net.kunmc.lab.teamkunpluginmanager.commands.debug.CommandUninstallDebug; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInfo.java similarity index 94% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInfo.java index 9b1b1bf9..2f074c9a 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInfo.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInfo.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.Utils; +import net.kunmc.lab.kpm.meta.DependType; +import net.kunmc.lab.kpm.meta.InstallOperator; +import net.kunmc.lab.kpm.meta.PluginMeta; +import net.kunmc.lab.kpm.meta.PluginMetaProvider; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.Utils; -import net.kunmc.lab.teamkunpluginmanager.meta.DependType; -import net.kunmc.lab.teamkunpluginmanager.meta.InstallOperator; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMeta; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInstall.java similarity index 88% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInstall.java index fe8f0709..b937148e 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandInstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInstall.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.installer.impls.install.InstallArgument; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandRegister.java similarity index 87% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandRegister.java index 395a336d..4d383b26 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandRegister.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandRegister.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.installer.impls.register.RegisterArgument; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.RegisterArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandReload.java similarity index 95% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandReload.java index e75853e0..db3f0002 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandReload.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandReload.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandResolve.java similarity index 88% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandResolve.java index a606a109..eb9eb79b 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandResolve.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandResolve.java @@ -1,17 +1,17 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.resolver.impl.CurseBukkitSuccessResult; +import net.kunmc.lab.kpm.resolver.impl.GitHubSuccessResult; +import net.kunmc.lab.kpm.resolver.impl.SpigotMCSuccessResult; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MarketplaceResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.CurseBukkitSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.GitHubSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.impl.SpigotMCSuccessResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MarketplaceResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.MultiResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ResolveResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; import net.kyori.adventure.text.TextComponent; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandStatus.java similarity index 95% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandStatus.java index c47ba2b4..7c7b266b 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandStatus.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandStatus.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUninstall.java similarity index 89% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUninstall.java index 3cc5ce36..b0f098e3 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUninstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUninstall.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUpdate.java similarity index 84% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUpdate.java index 88ce62c8..87ba4cd8 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/CommandUpdate.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUpdate.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.commands; +package net.kunmc.lab.kpm.commands; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.installer.impls.update.UpdateArgument; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.UpdateArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandDepTreeDebug.java similarity index 77% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandDepTreeDebug.java index b3d51030..11511341 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandDepTreeDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandDepTreeDebug.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.debug; +package net.kunmc.lab.kpm.commands.debug; +import net.kunmc.lab.kpm.commands.debug.deptree.CommandMarkAsDependency; +import net.kunmc.lab.kpm.commands.debug.deptree.CommandPurge; +import net.kunmc.lab.kpm.commands.debug.deptree.CommandRelation; +import net.kunmc.lab.kpm.meta.PluginMetaManager; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.command.SubCommandWith; -import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandMarkAsDependency; -import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandPurge; -import net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree.CommandRelation; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaManager; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandInstallDebug.java similarity index 83% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandInstallDebug.java index c33b9002..c2058073 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandInstallDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandInstallDebug.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.debug; +package net.kunmc.lab.kpm.commands.debug; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.install.InstallArgument; +import net.kunmc.lab.kpm.installer.impls.install.InstallErrorCause; +import net.kunmc.lab.kpm.installer.impls.install.InstallTasks; +import net.kunmc.lab.kpm.installer.impls.install.PluginInstaller; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallArgument; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallTasks; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.PluginInstaller; import net.kyori.adventure.text.TextComponent; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandUninstallDebug.java similarity index 83% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandUninstallDebug.java index eb8b12f5..4de21f7d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/CommandUninstallDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandUninstallDebug.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.debug; +package net.kunmc.lab.kpm.commands.debug; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallErrorCause; +import net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.kpm.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import net.kunmc.lab.teamkunpluginmanager.KPMDaemon; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.PluginUninstaller; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallTasks; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UninstallArgument; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/DebugSignalHandler.java similarity index 93% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/DebugSignalHandler.java index 6a1fabc7..5a802cc6 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/DebugSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/DebugSignalHandler.java @@ -1,16 +1,16 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.debug; +package net.kunmc.lab.kpm.commands.debug; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.installer.InstallProgress; +import net.kunmc.lab.kpm.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.kpm.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.kpm.signal.Signal; +import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Question; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.Signal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandleManager; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandMarkAsDependency.java similarity index 94% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandMarkAsDependency.java index 811b89d5..19d0daae 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandMarkAsDependency.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandMarkAsDependency.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree; +package net.kunmc.lab.kpm.commands.debug.deptree; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.meta.PluginMetaProvider; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandPurge.java similarity index 94% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandPurge.java index 7701f522..f2654cdb 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandPurge.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandPurge.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree; +package net.kunmc.lab.kpm.commands.debug.deptree; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.meta.PluginMetaProvider; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandRelation.java similarity index 93% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandRelation.java index 2dc3e147..42b40fd5 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/commands/debug/deptree/CommandRelation.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/deptree/CommandRelation.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.commands.debug.deptree; +package net.kunmc.lab.kpm.commands.debug.deptree; import com.google.common.base.Enums; import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.meta.DependType; +import net.kunmc.lab.kpm.meta.DependencyNode; +import net.kunmc.lab.kpm.meta.PluginMeta; +import net.kunmc.lab.kpm.meta.PluginMetaProvider; import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.meta.DependType; -import net.kunmc.lab.teamkunpluginmanager.meta.DependencyNode; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMeta; -import net.kunmc.lab.teamkunpluginmanager.meta.PluginMetaProvider; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java similarity index 68% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java index f2061041..ff2bad72 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java @@ -1,24 +1,24 @@ -package net.kunmc.lab.teamkunpluginmanager.signal; +package net.kunmc.lab.kpm.signal; +import net.kunmc.lab.kpm.signal.handlers.autoremove.AutoRemoveFinishedSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.autoremove.AutoRemoveReadySignalHandler; +import net.kunmc.lab.kpm.signal.handlers.clean.GarbageCleanFinishedSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.clean.GarbageCleanSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.common.CheckEnvSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.common.DownloadingSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.common.ModifySignalHandler; +import net.kunmc.lab.kpm.signal.handlers.intall.DependenciesSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.intall.InstallFinishedSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.intall.InstallerSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.intall.ResolverSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.register.TokenGenerateSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.register.TokenRegisterSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.uninstall.PluginIsDependencySignalHandler; +import net.kunmc.lab.kpm.signal.handlers.uninstall.UninstallFinishedSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.uninstall.UninstallReadySignalHandler; +import net.kunmc.lab.kpm.signal.handlers.uninstall.UninstallerSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.update.UpdateAliasesSignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove.AutoRemoveFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove.AutoRemoveReadySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean.GarbageCleanFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean.GarbageCleanSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.CheckEnvSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.DownloadingSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.ModifySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.DependenciesSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.InstallFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.InstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall.ResolverSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.register.TokenGenerateSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.register.TokenRegisterSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.PluginIsDependencySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallFinishedSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallReadySignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall.UninstallerSignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.update.UpdateAliasesSignalHandler; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlingUtils.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlingUtils.java similarity index 93% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlingUtils.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlingUtils.java index b73905b2..89a491e6 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/SignalHandlingUtils.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlingUtils.java @@ -1,4 +1,4 @@ -package net.kunmc.lab.teamkunpluginmanager.signal; +package net.kunmc.lab.kpm.signal; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java similarity index 79% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java index 1f5d331c..d70dd197 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove; +package net.kunmc.lab.kpm.signal.handlers.autoremove; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.autoremove.AutoRemoveErrorCause; +import net.kunmc.lab.kpm.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.AutoRemoveErrorCause; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; public class AutoRemoveFinishedSignalHandler extends InstallFinishedSignalBase { diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java similarity index 78% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java index 89f0b7b2..534cf98d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveReadySignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.autoremove; +package net.kunmc.lab.kpm.signal.handlers.autoremove; +import net.kunmc.lab.kpm.Utils; +import net.kunmc.lab.kpm.installer.impls.autoremove.signals.PluginEnumeratedSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.signal.SignalHandlingUtils; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.Utils; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.autoremove.signals.PluginEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import org.bukkit.ChatColor; import java.util.List; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java similarity index 79% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java index 05cb6b76..f640b770 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean; +package net.kunmc.lab.kpm.signal.handlers.clean; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.GarbageCleanErrorCause; +import net.kunmc.lab.kpm.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.GarbageCleanErrorCause; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; public class GarbageCleanFinishedSignalHandler extends InstallFinishedSignalBase { diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanSignalHandler.java similarity index 72% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanSignalHandler.java index ea471409..cdb98136 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/clean/GarbageCleanSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.clean; +package net.kunmc.lab.kpm.signal.handlers.clean; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.signal.SignalHandlingUtils; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.clean.signal.GarbageEnumeratedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.garbage.search.signals.GarbageSearchingSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import org.bukkit.ChatColor; import java.util.stream.Collectors; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/CheckEnvSignalHandler.java similarity index 82% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/CheckEnvSignalHandler.java index ab5a6633..15d7aaaa 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/CheckEnvSignalHandler.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; +package net.kunmc.lab.kpm.signal.handlers.common; +import net.kunmc.lab.kpm.installer.impls.install.signals.AlreadyInstalledPluginSignal; +import net.kunmc.lab.kpm.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.signal.SignalHandlingUtils; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.signals.AlreadyInstalledPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.assertion.IgnoredPluginSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginIncompatibleWithKPMSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/DownloadingSignalHandler.java similarity index 84% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/DownloadingSignalHandler.java index 649d8e88..844ff3ca 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/DownloadingSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/DownloadingSignalHandler.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; +package net.kunmc.lab.kpm.signal.handlers.common; +import net.kunmc.lab.kpm.Utils; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadErrorSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadProgressSignal; +import net.kunmc.lab.kpm.installer.task.tasks.download.signals.DownloadSucceedSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.Utils; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadProgressSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.signals.DownloadSucceedSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.bukkit.ChatColor; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/InstallFinishedSignalBase.java similarity index 80% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/InstallFinishedSignalBase.java index ccd67dcd..ee364616 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/InstallFinishedSignalBase.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/InstallFinishedSignalBase.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; +package net.kunmc.lab.kpm.signal.handlers.common; import lombok.AccessLevel; import lombok.Setter; +import net.kunmc.lab.kpm.Utils; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.Utils; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; /** * インストールが完了したときのシグナルを処理するハンドラーの基底クラスです。 diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/ModifySignalHandler.java similarity index 80% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/ModifySignalHandler.java index 57e22922..b3232e12 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/common/ModifySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/ModifySignalHandler.java @@ -1,9 +1,9 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.common; +package net.kunmc.lab.kpm.signal.handlers.common; +import net.kunmc.lab.kpm.installer.signals.PluginModifiedSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.PluginModifiedSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/DependenciesSignalHandler.java similarity index 70% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/DependenciesSignalHandler.java index db72fb7f..da79d5f2 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/DependenciesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/DependenciesSignalHandler.java @@ -1,12 +1,12 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; - +package net.kunmc.lab.kpm.signal.handlers.intall; + +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyCollectDependencysDependsFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyLoadDescriptionFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyNameMismatchSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.signals.DependencyResolveFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.bukkit.ChatColor; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallFinishedSignalHandler.java similarity index 87% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallFinishedSignalHandler.java index 32c64cfc..795f1b3a 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; +package net.kunmc.lab.kpm.signal.handlers.intall; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.install.InstallErrorCause; +import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.DependsCollectErrorCause; +import net.kunmc.lab.kpm.installer.task.tasks.description.DescriptionLoadErrorCause; +import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadErrorCause; +import net.kunmc.lab.kpm.installer.task.tasks.install.PluginsInstallErrorCause; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveErrorCause; +import net.kunmc.lab.kpm.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.install.InstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.dependencies.collector.DependsCollectErrorCause; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.description.DescriptionLoadErrorCause; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.download.DownloadErrorCause; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.PluginsInstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.PluginResolveErrorCause; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; import org.jetbrains.annotations.Nullable; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallerSignalHandler.java similarity index 73% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallerSignalHandler.java index de267aa0..1985b1b1 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/InstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallerSignalHandler.java @@ -1,14 +1,14 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; +package net.kunmc.lab.kpm.signal.handlers.intall; +import net.kunmc.lab.kpm.installer.signals.InvalidKPMInfoFileSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginEnablingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginInstallingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginLoadSignal; +import net.kunmc.lab.kpm.installer.task.tasks.install.signals.PluginRelocatingSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.signal.SignalHandlingUtils; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.InvalidKPMInfoFileSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginEnablingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginInstallingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginLoadSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.install.signals.PluginRelocatingSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; /** diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java similarity index 86% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java index b267d193..8c91831d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/intall/ResolverSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java @@ -1,15 +1,15 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.intall; +package net.kunmc.lab.kpm.signal.handlers.intall; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.signals.PluginResolvingSignal; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import net.kunmc.lab.peyangpaperutils.lib.terminal.attributes.AttributeChoice; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.resolve.signals.PluginResolvingSignal; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.ErrorResult; -import net.kunmc.lab.teamkunpluginmanager.resolver.result.SuccessResult; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; import org.bukkit.ChatColor; import java.util.AbstractMap; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenGenerateSignalHandler.java similarity index 77% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenGenerateSignalHandler.java index 06879350..fcc3c065 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenGenerateSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenGenerateSignalHandler.java @@ -1,17 +1,17 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.register; - +package net.kunmc.lab.kpm.signal.handlers.register; + +import net.kunmc.lab.kpm.installer.impls.register.signals.TokenGenerateStartingSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.UserDoesntCompleteVerifySignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.UserVerificationSuccessSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.UserVerifyDeniedSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeExpiredSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeReceivedSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeRequestFailedSignal; +import net.kunmc.lab.kpm.installer.impls.register.signals.VerificationCodeRequestingSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.signal.SignalHandlingUtils; import net.kunmc.lab.peyangpaperutils.lib.terminal.Progressbar; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenGenerateStartingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserDoesntCompleteVerifySignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerificationSuccessSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.UserVerifyDeniedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeExpiredSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeReceivedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestFailedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.VerificationCodeRequestingSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import org.bukkit.ChatColor; public class TokenGenerateSignalHandler diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenRegisterSignalHandler.java similarity index 64% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenRegisterSignalHandler.java index 7a384fdd..9f37f83b 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/register/TokenRegisterSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenRegisterSignalHandler.java @@ -1,8 +1,8 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.register; +package net.kunmc.lab.kpm.signal.handlers.register; +import net.kunmc.lab.kpm.installer.impls.register.signals.TokenStoredSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.register.signals.TokenStoredSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; public class TokenRegisterSignalHandler { diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/PluginIsDependencySignalHandler.java similarity index 87% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/PluginIsDependencySignalHandler.java index a2ebfbe9..0309cae2 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/PluginIsDependencySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/PluginIsDependencySignalHandler.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; +package net.kunmc.lab.kpm.signal.handlers.uninstall; +import net.kunmc.lab.kpm.installer.impls.uninstall.signals.PluginIsDependencySignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionAttribute; import net.kunmc.lab.peyangpaperutils.lib.terminal.QuestionResult; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.PluginIsDependencySignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.Plugin; import java.util.List; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java similarity index 70% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallFinishedSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java index 8a7b7fb5..3a2e9b4a 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; +package net.kunmc.lab.kpm.signal.handlers.uninstall; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallErrorCause; +import net.kunmc.lab.kpm.signal.handlers.common.InstallFinishedSignalBase; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallFailedInstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.UnInstallErrorCause; -import net.kunmc.lab.teamkunpluginmanager.signal.handlers.common.InstallFinishedSignalBase; import org.jetbrains.annotations.Nullable; /** @@ -23,7 +23,7 @@ protected void onSuccess(InstallResult result) this.terminal.success("アンインストールが正常に完了しました。"); } - private boolean handleGeneralErrors(@Nullable net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause cause) + private boolean handleGeneralErrors(@Nullable net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallErrorCause cause) { if (cause == null) return false; @@ -47,8 +47,8 @@ private boolean handleGeneralErrors(@Nullable net.kunmc.lab.teamkunpluginmanager @Override protected void onFail(InstallFailedInstallResult result) { - if (result.getReason() instanceof net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause && - this.handleGeneralErrors((net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.UnInstallErrorCause) result.getReason())) + if (result.getReason() instanceof net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallErrorCause && + this.handleGeneralErrors((net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallErrorCause) result.getReason())) return; if (result.getReason() instanceof UnInstallErrorCause) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallReadySignalHandler.java similarity index 75% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallReadySignalHandler.java index 1b1da4cd..02cb31c5 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallReadySignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallReadySignalHandler.java @@ -1,10 +1,10 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; +package net.kunmc.lab.kpm.signal.handlers.uninstall; +import net.kunmc.lab.kpm.Utils; +import net.kunmc.lab.kpm.installer.impls.uninstall.signals.UninstallReadySignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.signal.SignalHandlingUtils; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.Utils; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.uninstall.signals.UninstallReadySignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandlingUtils; import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallerSignalHandler.java similarity index 73% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallerSignalHandler.java index 2eecd21e..49f4a092 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/uninstall/UninstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallerSignalHandler.java @@ -1,13 +1,13 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.uninstall; +package net.kunmc.lab.kpm.signal.handlers.uninstall; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginDisablingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; +import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginDisablingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUninstallErrorSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; -import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.ChatColor; public class UninstallerSignalHandler diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/update/UpdateAliasesSignalHandler.java similarity index 76% rename from KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java rename to KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/update/UpdateAliasesSignalHandler.java index 18eefc61..23e91cdf 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/teamkunpluginmanager/signal/handlers/update/UpdateAliasesSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/update/UpdateAliasesSignalHandler.java @@ -1,11 +1,11 @@ -package net.kunmc.lab.teamkunpluginmanager.signal.handlers.update; +package net.kunmc.lab.kpm.signal.handlers.update; +import net.kunmc.lab.kpm.installer.impls.update.signals.UpdateFinishedSignal; +import net.kunmc.lab.kpm.installer.signals.InstallFinishedSignal; +import net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; +import net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals.InvalidSourceSignal; +import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; -import net.kunmc.lab.teamkunpluginmanager.installer.impls.update.signals.UpdateFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.signals.InstallFinishedSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.source.download.signals.MalformedURLSignal; -import net.kunmc.lab.teamkunpluginmanager.installer.task.tasks.alias.update.signals.InvalidSourceSignal; -import net.kunmc.lab.teamkunpluginmanager.signal.SignalHandler; public class UpdateAliasesSignalHandler { diff --git a/KPMPlugin/src/main/resources/plugin.yml b/KPMPlugin/src/main/resources/plugin.yml index 371020f5..c878b1e8 100644 --- a/KPMPlugin/src/main/resources/plugin.yml +++ b/KPMPlugin/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: TeamKunPluginManager version: ${project.version} -main: net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager +main: net.kunmc.lab.kpm.TeamKunPluginManager authors: [Peyang] api-version: 1.16 description: Manage your plugin! From 041976b3f96733cef2f7be2788f8111d60f8c832 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 23 Oct 2022 21:11:37 +0900 Subject: [PATCH 407/745] feat: Hook base --- KPMHook/pom.xml | 21 +++++++++++++++++++ .../net/kunmc/lab/kpm/hook/HookListener.java | 16 ++++++++++++++ .../java/net/kunmc/lab/kpm/hook/KPMHook.java | 9 ++++++++ .../kunmc/lab/kpm/hook/KPMHookRecipient.java | 10 +++++++++ pom.xml | 1 + 5 files changed, 57 insertions(+) create mode 100644 KPMHook/pom.xml create mode 100644 KPMHook/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java create mode 100644 KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java create mode 100644 KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java diff --git a/KPMHook/pom.xml b/KPMHook/pom.xml new file mode 100644 index 00000000..dab7d49e --- /dev/null +++ b/KPMHook/pom.xml @@ -0,0 +1,21 @@ + + + + TeamKunPluginManager + net.kunmc.lab + 3.0.0-pre5 + + 4.0.0 + + net.kunmc.lab.kpm + KPMHook + + + 8 + 8 + UTF-8 + + + diff --git a/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java b/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java new file mode 100644 index 00000000..70fb3c6b --- /dev/null +++ b/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java @@ -0,0 +1,16 @@ +package net.kunmc.lab.kpm.hook; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * KPMフックを受け取るメソッドを宣言するためのアノテーションです。 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface HookListener +{ + +} diff --git a/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java b/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java new file mode 100644 index 00000000..4195ba31 --- /dev/null +++ b/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java @@ -0,0 +1,9 @@ +package net.kunmc.lab.kpm.hook; + +/** + * KPMフックのインタフェースです。 + */ +public interface KPMHook +{ + +} diff --git a/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java b/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java new file mode 100644 index 00000000..84238e4a --- /dev/null +++ b/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java @@ -0,0 +1,10 @@ +package net.kunmc.lab.kpm.hook; + +/** + * KPMフックを受け取るためのインターフェースです。 + * このクラスを継承し、KPMフックを受け取るクラスであることを宣言します。 + */ +public interface KPMHookRecipient +{ + +} diff --git a/pom.xml b/pom.xml index 32b132a2..53b5db99 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,7 @@ KPMDaemon KPMPlugin + KPMHook pom From 4dda61eb04fa87e947ab720f3f59c4f83cfd28b4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 24 Oct 2022 17:49:46 +0900 Subject: [PATCH 408/745] feat: KPM Hook --- .../java/net/kunmc/lab/kpm/KPMDaemon.java | 8 +- .../net/kunmc/lab/kpm/hook/HookExecutor.java | 56 +++++++++++++ .../net/kunmc/lab/kpm/hook/HookListener.java | 0 .../kunmc/lab/kpm/hook/HookRecipientList.java | 31 ++++++++ .../java/net/kunmc/lab/kpm/hook/KPMHook.java | 0 .../kunmc/lab/kpm/hook/KPMHookRecipient.java | 60 ++++++++++++++ .../lab/kpm/hook/hooks/PluginInstallHook.java | 67 ++++++++++++++++ .../tasks/install/PluginsInstallTask.java | 35 ++++++-- .../kunmc/lab/kpm/kpminfo/KPMInfoManager.java | 2 +- .../kunmc/lab/kpm/kpminfo/KPMInfoParser.java | 79 ++++++++++++++++--- .../lab/kpm/kpminfo/KPMInformationFile.java | 12 +++ KPMHook/pom.xml | 21 ----- .../kunmc/lab/kpm/hook/KPMHookRecipient.java | 10 --- 13 files changed, 332 insertions(+), 49 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookExecutor.java rename {KPMHook => KPMDaemon}/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java (100%) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java rename {KPMHook => KPMDaemon}/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java (100%) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java delete mode 100644 KPMHook/pom.xml delete mode 100644 KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index d12b2798..09cdfc15 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -4,6 +4,7 @@ import lombok.Getter; import net.kunmc.lab.kpm.alias.AliasPluginResolver; import net.kunmc.lab.kpm.alias.AliasProvider; +import net.kunmc.lab.kpm.hook.HookExecutor; import net.kunmc.lab.kpm.installer.InstallManager; import net.kunmc.lab.kpm.kpminfo.KPMInfoManager; import net.kunmc.lab.kpm.loader.PluginLoader; @@ -82,12 +83,16 @@ public class KPMDaemon */ @NotNull private final AliasProvider aliasProvider; - /** * プラグインをロード/アンロードするためのクラスです。 */ @NotNull private final PluginLoader pluginLoader; + /** + * フックを実行するクラスです。 + */ + @NotNull + private final HookExecutor hookExecutor; { INSTANCE = this; @@ -104,6 +109,7 @@ public KPMDaemon(@NotNull KPMEnvironment env) this.aliasProvider = new AliasProvider(env.getAliasesDBPath()); this.pluginLoader = new PluginLoader(this); this.installManager = new InstallManager(this); + this.hookExecutor = new HookExecutor(this); this.setupDaemon(env.getDataDirPath(), env.getOrganizations()); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookExecutor.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookExecutor.java new file mode 100644 index 00000000..3f83acee --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookExecutor.java @@ -0,0 +1,56 @@ +package net.kunmc.lab.kpm.hook; + +import lombok.Getter; +import net.kunmc.lab.kpm.KPMDaemon; + +import java.lang.reflect.Method; +import java.util.List; + +/** + * KPMフックを実行するクラスです。 + */ +public class HookExecutor +{ + @Getter + private final KPMDaemon daemon; + + public HookExecutor(KPMDaemon daemon) + { + this.daemon = daemon; + } + + /** + * フックを実行します。 + * + * @param recipient フックを受け取るクラス + * @param hook フック + */ + public void runHook(KPMHookRecipient recipient, KPMHook hook) + { + Method hookMethod = recipient.getHookListener(hook.getClass()); + + if (hookMethod == null) + throw new IllegalStateException("Hook method not found: " + hook.getClass().getName()); + + try + { + hookMethod.invoke(recipient, hook); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * フックを実行します。 + * + * @param recipients フックを受け取るクラスのリスト + * @param hook フック + */ + public void runHook(List recipients, KPMHook hook) + { + for (KPMHookRecipient recipient : recipients) + this.runHook(recipient, hook); + } +} diff --git a/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java similarity index 100% rename from KPMHook/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookListener.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java new file mode 100644 index 00000000..36ffeb98 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java @@ -0,0 +1,31 @@ +package net.kunmc.lab.kpm.hook; + +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; + +/** + * KPMフックの受け取りを行うクラスを管理するクラスです。 + */ +public class HookRecipientList extends ArrayList +{ + @Getter + private final HookExecutor executor; + + public HookRecipientList(@NotNull HookExecutor executor) + { + this.executor = executor; + } + + /** + * フックを実行します。 + * + * @param hook フック + */ + public void runHook(KPMHook hook) + { + for (KPMHookRecipient recipient : this) + this.executor.runHook(recipient, hook); + } +} diff --git a/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java similarity index 100% rename from KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java rename to KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHook.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java new file mode 100644 index 00000000..a88d662d --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java @@ -0,0 +1,60 @@ +package net.kunmc.lab.kpm.hook; + +import lombok.AccessLevel; +import lombok.Getter; +import net.kunmc.lab.kpm.KPMDaemon; + +import java.lang.invoke.WrongMethodTypeException; +import java.lang.reflect.Method; +import java.util.HashMap; + +/** + * KPMフックを受け取るためのインターフェースです。 + * このクラスを継承し、KPMフックを受け取るクラスであることを宣言します。 + */ +public abstract class KPMHookRecipient +{ + /** + * KPMデーモンのインスタンスです。 + */ + @Getter(AccessLevel.PROTECTED) + private final KPMDaemon daemon; + + private final HashMap> hooks; + + protected KPMHookRecipient(KPMDaemon daemon) + { + this.daemon = daemon; + this.hooks = new HashMap<>(); + + this.bakeAll(); + } + + @SuppressWarnings("unchecked") + private void bakeAll() + { + for (Method method : this.getClass().getDeclaredMethods()) + { + if (method.isAnnotationPresent(HookListener.class)) + { + if (!(method.getParameterCount() == 1 && KPMHook.class.isAssignableFrom(method.getParameterTypes()[0]))) + throw new WrongMethodTypeException("Invalid method signature for hook listener: " + + method.getName() + " in " + this.getClass().getName()); + + this.hooks.put(method, (Class) method.getParameterTypes()[0]); + } + } + } + + public Method getHookListener(Class hook) + { + for (Method method : this.hooks.keySet()) + { + Class hookClass = this.hooks.get(method); + if (hookClass.isAssignableFrom(hook)) + return method; + } + + return null; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java new file mode 100644 index 00000000..dee8538c --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java @@ -0,0 +1,67 @@ +package net.kunmc.lab.kpm.hook.hooks; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.kunmc.lab.kpm.hook.KPMHook; +import net.kunmc.lab.kpm.meta.InstallOperator; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * プラグインがインストールされたときに呼び出されるフックです。 + */ +@Data +@AllArgsConstructor +public class PluginInstallHook implements KPMHook +{ + /** + * プラグインのインストール者です。 + */ + @NotNull + private final InstallOperator operator; + /** + * プラグインが依存関係であるかどうかを表します。 + */ + boolean isDependency; + /** + * プラグインのインストールに使用した解決クエリです。 + */ + @Nullable + String resolveQuery; + + public static class Pre extends PluginInstallHook + { + public Pre(@NotNull InstallOperator operator, boolean isDependency, @Nullable String resolveQuery) + { + super(operator, isDependency, resolveQuery); + } + + public Pre(@NotNull InstallOperator operator, boolean isDependency) + { + super(operator, isDependency, null); + } + + public Pre(@NotNull InstallOperator operator) + { + super(operator, false, null); + } + } + + public static class Post extends PluginInstallHook + { + public Post(@NotNull InstallOperator operator, boolean isDependency, @Nullable String resolveQuery) + { + super(operator, isDependency, resolveQuery); + } + + public Post(@NotNull InstallOperator operator, boolean isDependency) + { + super(operator, isDependency, null); + } + + public Post(@NotNull InstallOperator operator) + { + super(operator, false, null); + } + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java index 321d8ae5..b03a6161 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java @@ -1,6 +1,8 @@ package net.kunmc.lab.kpm.installer.task.tasks.install; import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.hook.HookExecutor; +import net.kunmc.lab.kpm.hook.hooks.PluginInstallHook; import net.kunmc.lab.kpm.installer.AbstractInstaller; import net.kunmc.lab.kpm.installer.task.InstallTask; import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; @@ -56,6 +58,7 @@ public class PluginsInstallTask extends InstallTask installer) @@ -65,6 +68,7 @@ public PluginsInstallTask(@NotNull AbstractInstaller installer) PluginMetaManager pluginMetaManager = installer.getDaemon().getPluginMetaManager(); this.pluginMetaManager = pluginMetaManager; this.pluginMetaProvider = pluginMetaManager.getProvider(); + this.hookExecutor = installer.getDaemon().getHookExecutor(); this.state = PluginsInstallState.INITIALIZED; } @@ -125,8 +129,24 @@ private static void patchPluginCommands(List targets) private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescriptionFile pluginDescription, @Nullable KPMInformationFile kpmInformationFile, @NotNull List installedPlugins, boolean isDependency) { + // Define variables + InstallOperator operator = isDependency ? InstallOperator.KPM_DEPENDENCY_RESOLVER: InstallOperator.SERVER_ADMIN; + String query; + if (kpmInformationFile != null && kpmInformationFile.getUpdateQuery() != null) + query = kpmInformationFile.getUpdateQuery().toString(); + else + query = null; + + // Start install this.postSignal(new PluginInstallingSignal(path, pluginDescription)); + if (kpmInformationFile != null) + kpmInformationFile.getHooks().runHook(new PluginInstallHook.Pre( + operator, + isDependency, + query + )); + PluginsInstallErrorCause checkEnvError; if ((checkEnvError = this.checkEnv(pluginDescription, kpmInformationFile)) != null) return new PluginsInstallResult(false, this.state, checkEnvError); @@ -186,19 +206,20 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr installedPlugins.add(target); - String query; - if (kpmInformationFile != null && kpmInformationFile.getUpdateQuery() != null) - query = kpmInformationFile.getUpdateQuery().toString(); - else - query = null; - this.pluginMetaManager.onInstalled( target, - isDependency ? InstallOperator.KPM_DEPENDENCY_RESOLVER: InstallOperator.SERVER_ADMIN, + operator, query, isDependency ); + if (kpmInformationFile != null) + kpmInformationFile.getHooks().runHook(new PluginInstallHook.Post( + operator, + isDependency, + query + )); + return new PluginsInstallResult(true, this.state, null, null, target, installedPlugins); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java index c5caf693..d275ae03 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java @@ -39,7 +39,7 @@ public KPMInfoManager(KPMDaemon daemon) public KPMInformationFile loadInfo(@NotNull Path path, @NotNull PluginDescriptionFile descriptionFile) throws FileNotFoundException, InvalidInformationFileException { - KPMInformationFile info = KPMInfoParser.load(path); + KPMInformationFile info = KPMInfoParser.load(this.daemon, path); this.lookupNames.put(descriptionFile.getName(), info); return info; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java index 8159c040..a2970aac 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java @@ -1,5 +1,8 @@ package net.kunmc.lab.kpm.kpminfo; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.hook.HookRecipientList; +import net.kunmc.lab.kpm.hook.KPMHookRecipient; import net.kunmc.lab.kpm.resolver.QueryContext; import net.kunmc.lab.kpm.utils.versioning.Version; import org.jetbrains.annotations.NotNull; @@ -10,7 +13,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.nio.file.Path; +import java.util.List; import java.util.Map; import java.util.zip.ZipFile; @@ -24,13 +30,13 @@ public class KPMInfoParser } @NotNull - public static KPMInformationFile load(InputStream stream) throws InvalidInformationFileException + public static KPMInformationFile load(@NotNull KPMDaemon daemon, @NotNull InputStream stream) throws InvalidInformationFileException { - return loadFromMap(YAML_PARSER.load(stream)); + return loadFromMap(daemon, YAML_PARSER.load(stream)); } @NotNull - public static KPMInformationFile load(Path jarFile) throws InvalidInformationFileException, FileNotFoundException + public static KPMInformationFile load(@NotNull KPMDaemon daemon, @NotNull Path jarFile) throws InvalidInformationFileException, FileNotFoundException { File file = jarFile.toFile(); if (!file.exists()) @@ -42,7 +48,7 @@ public static KPMInformationFile load(Path jarFile) throws InvalidInformationFil if (stream == null) throw new InvalidInformationFileException("kpm.yml not found in " + file.getAbsolutePath()); - return load(stream); + return load(daemon, stream); } catch (IOException e) { @@ -51,15 +57,16 @@ public static KPMInformationFile load(Path jarFile) throws InvalidInformationFil } @NotNull - private static KPMInformationFile loadFromMap(Map map) throws InvalidInformationFileException + private static KPMInformationFile loadFromMap(@NotNull KPMDaemon daemon, Map map) throws InvalidInformationFileException { if (map == null) throw new InvalidInformationFileException("Information file is empty."); Version version = parseVersion(map); // Parse kpm => kpmVersion [required] QueryContext updateQuery = parseUpdateQuery(map); // Parse update => updateQuery [required] + HookRecipientList hooks = parseHooks(daemon, map); // Parse hooks [optional] - return new KPMInformationFile(version, updateQuery); + return new KPMInformationFile(version, updateQuery, hooks); } @NotNull @@ -78,12 +85,66 @@ private static Version parseVersion(Map map) throws InvalidInformationFile } @Nullable - private static QueryContext parseUpdateQuery(Map map) + private static QueryContext parseUpdateQuery(Map map) throws InvalidInformationFileException { if (!map.containsKey("update")) return null; - Object updateQueryObj = map.get("update"); - return QueryContext.fromString(updateQueryObj.toString()); + String updateQuery = map.get("update").toString(); + if (updateQuery.isEmpty()) + throw new InvalidInformationFileException("Update query is empty."); + + return QueryContext.fromString(updateQuery); + } + + @NotNull + private static HookRecipientList parseHooks(KPMDaemon daemon, Map map) throws InvalidInformationFileException + { + HookRecipientList result = new HookRecipientList(daemon.getHookExecutor()); + + if (!map.containsKey("hooks")) + return result; + + Object hooksObj = map.get("hooks"); + if (!(hooksObj instanceof List)) + throw new InvalidInformationFileException("hooks must be a list of full-qualified class names."); + + List hooks = (List) hooksObj; + + for (Object hook : hooks) + { + if (!(hook instanceof String)) + throw new InvalidInformationFileException("hooks must be a list of full-qualified class names."); + + String hookClassName = (String) hook; + try + { + Class hookClass = Class.forName(hookClassName); + if (!KPMHookRecipient.class.isAssignableFrom(hookClass)) + throw new InvalidInformationFileException("Class " + hookClassName + " is not a KPMHookRecipient."); + + Constructor constructor = + hookClass.asSubclass(KPMHookRecipient.class).getConstructor(KPMDaemon.class); + + result.add(constructor.newInstance(daemon)); + } + catch (ClassNotFoundException e) + { + throw new InvalidInformationFileException("Hook recipient class was not found: " + hookClassName, e); + } + catch (InstantiationException | IllegalAccessException | InvocationTargetException e) + { + throw new InvalidInformationFileException("Failed to create an instance of hook recipient class: " + + hookClassName, e); + } + catch (NoSuchMethodException e) + { + throw new InvalidInformationFileException("Hook recipient class must have a constructor with" + + " a single parameter of type KPMDaemon: " + hookClassName, e); + } + } + + return result; } + } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java index 25415fe6..d1448988 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java @@ -3,6 +3,8 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Value; +import net.kunmc.lab.kpm.hook.HookRecipientList; +import net.kunmc.lab.kpm.hook.KPMHookRecipient; import net.kunmc.lab.kpm.resolver.QueryContext; import net.kunmc.lab.kpm.utils.versioning.Version; import org.jetbrains.annotations.NotNull; @@ -28,4 +30,14 @@ public class KPMInformationFile */ @Nullable QueryContext updateQuery; + /** + * KPMフックを受け取る {@link KPMHookRecipient} のクラス名です。 + * KPMフックは、KPMがプラグインを読み込む際や、プラグインをアンロードする際に呼び出されるフックです。 + * + * @see net.kunmc.lab.kpm.hook.KPMHook + * @see KPMHookRecipient + * @see net.kunmc.lab.kpm.hook.HookListener + */ + @NotNull + HookRecipientList hooks; } diff --git a/KPMHook/pom.xml b/KPMHook/pom.xml deleted file mode 100644 index dab7d49e..00000000 --- a/KPMHook/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - TeamKunPluginManager - net.kunmc.lab - 3.0.0-pre5 - - 4.0.0 - - net.kunmc.lab.kpm - KPMHook - - - 8 - 8 - UTF-8 - - - diff --git a/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java b/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java deleted file mode 100644 index 84238e4a..00000000 --- a/KPMHook/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.kunmc.lab.kpm.hook; - -/** - * KPMフックを受け取るためのインターフェースです。 - * このクラスを継承し、KPMフックを受け取るクラスであることを宣言します。 - */ -public interface KPMHookRecipient -{ - -} From 76c7d9737acde49883faa8776ce507e45fb9263a Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 24 Oct 2022 18:00:37 +0900 Subject: [PATCH 409/745] feat: Old schema --- kpm-info.json | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kpm-info.json b/kpm-info.json index c421aeec..561d4178 100644 --- a/kpm-info.json +++ b/kpm-info.json @@ -28,10 +28,23 @@ "TeamKUN/DaredemoOpPlugin", "bukkit>daredemo-op-plugin" ] + }, + "hooks": { + "type": "array", + "description": "KPMフックを受け取るクラスの一覧です。KPMフックを受け取るには, このフィールドに KPMHookRecipient を実装したクラスのフルパスを指定します。また, KPMフックを受け取るクラスは, 1つのKPMDaemonのみを引数にとるコンストラクタを持つ必要があります。", + "items": { + "type": "string", + "examples": [ + "net.kunmc.lab.exampleplugin.kpmhooks.ExampleKPMHookRecipient" + ], + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$" + }, + "minItems": 1, + "uniqueItems": true } }, "required": [ "kpm" ], - "additionalProperties": false + "additionalProperties": true } From f115ac039829e208499dddb2074cec3cc00eed98 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 24 Oct 2022 18:19:13 +0900 Subject: [PATCH 410/745] fix: Remove old module --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53b5db99..32b132a2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,6 @@ KPMDaemon KPMPlugin - KPMHook pom From 692a8068218f3a08d3895c5842b05f1e6bc1badf Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 24 Oct 2022 19:57:40 +0900 Subject: [PATCH 411/745] feat: Uninstall cancel --- .../lab/kpm/installer/impls/uninstall/PluginUninstaller.java | 3 +++ .../kpm/installer/impls/uninstall/UnInstallErrorCause.java | 4 ++++ .../handlers/uninstall/UninstallFinishedSignalHandler.java | 3 +++ 3 files changed, 10 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index f0297af7..fd09cfa7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -111,6 +111,9 @@ public InstallResult execute(@NotNull UninstallArgument argument UninstallReadySignal uninstallReadySignal = new UninstallReadySignal(plugins); this.postSignal(uninstallReadySignal); + if (!uninstallReadySignal.isContinueUninstall()) + return this.error(UnInstallErrorCause.CANCELLED); + plugins = uninstallReadySignal.getPlugins(); // region Uninstall plugin diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallErrorCause.java index 834e93e2..aec77418 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UnInstallErrorCause.java @@ -19,4 +19,8 @@ public enum UnInstallErrorCause * {@link net.kunmc.lab.kpm.installer.impls.uninstall.signals.PluginIsDependencySignal} でも強制アンインストールが選択されませんでした。 */ PLUGIN_IS_DEPENDENCY, + /** + * アンインストールがユーザまたはシグナルによってキャンセルされました。 + */ + CANCELLED, } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java index 3a2e9b4a..f55d15ae 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -39,6 +39,9 @@ private boolean handleGeneralErrors(@Nullable net.kunmc.lab.kpm.installer.impls. case PLUGIN_IS_DEPENDENCY: this.terminal.error("指定されたプラグインが他のプラグインの依存関係に含まれています。"); return true; + case CANCELLED: + this.terminal.error("アンインストールがキャンセルされました。"); + return true; } return false; From 9c9a2f93a8d63a3276165320f4b3c98fa8c5134d Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 24 Oct 2022 21:00:47 +0900 Subject: [PATCH 412/745] refactor: fix pom --- KPMPlugin/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KPMPlugin/pom.xml b/KPMPlugin/pom.xml index b542f389..57c688d3 100644 --- a/KPMPlugin/pom.xml +++ b/KPMPlugin/pom.xml @@ -86,9 +86,9 @@ - net.kunmc.lab + net.kunmc.lab.kpm KPMDaemon - ${project.version} + 3.0.0-pre5 compile From 5e72c9668a61460d33778671f1e0725d0a4b53cc Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 24 Oct 2022 21:13:08 +0900 Subject: [PATCH 413/745] fix: Fix japanese --- .../lab/kpm/signal/handlers/intall/InstallerSignalHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallerSignalHandler.java index 1985b1b1..b74a6dd5 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallerSignalHandler.java @@ -56,7 +56,7 @@ public void onPluginLoading(PluginEnablingSignal.Pre signal) @SignalHandler public void onInvalidKPMInfoFile(InvalidKPMInfoFileSignal signal) { - this.terminal.warn("プラグイン " + signal.getPlugin() + " はKPM情報ファイル (kpm.yml) を持っていますが、" + + this.terminal.warn("プラグイン " + signal.getDescriptionFile().getName() + " はKPM情報ファイル (kpm.yml) を持っていますが、" + "KPMが理解できる形式ではありません。"); this.terminal.info(ChatColor.GRAY + "このファイルを無視して強制的にインストールできますが、" + "強制的な操作は予期しない問題を引き起こす可能性があります。"); From ff4896a05ba5fbacb94171cb1db17a1d086f0251 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 24 Oct 2022 21:28:42 +0900 Subject: [PATCH 414/745] feat: PluginInstalledHook --- .../lab/kpm/hook/hooks/PluginInstallHook.java | 67 ------------------- .../kpm/hook/hooks/PluginInstalledHook.java | 31 +++++++++ .../tasks/install/PluginsInstallTask.java | 11 +-- 3 files changed, 33 insertions(+), 76 deletions(-) delete mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstalledHook.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java deleted file mode 100644 index dee8538c..00000000 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstallHook.java +++ /dev/null @@ -1,67 +0,0 @@ -package net.kunmc.lab.kpm.hook.hooks; - -import lombok.AllArgsConstructor; -import lombok.Data; -import net.kunmc.lab.kpm.hook.KPMHook; -import net.kunmc.lab.kpm.meta.InstallOperator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * プラグインがインストールされたときに呼び出されるフックです。 - */ -@Data -@AllArgsConstructor -public class PluginInstallHook implements KPMHook -{ - /** - * プラグインのインストール者です。 - */ - @NotNull - private final InstallOperator operator; - /** - * プラグインが依存関係であるかどうかを表します。 - */ - boolean isDependency; - /** - * プラグインのインストールに使用した解決クエリです。 - */ - @Nullable - String resolveQuery; - - public static class Pre extends PluginInstallHook - { - public Pre(@NotNull InstallOperator operator, boolean isDependency, @Nullable String resolveQuery) - { - super(operator, isDependency, resolveQuery); - } - - public Pre(@NotNull InstallOperator operator, boolean isDependency) - { - super(operator, isDependency, null); - } - - public Pre(@NotNull InstallOperator operator) - { - super(operator, false, null); - } - } - - public static class Post extends PluginInstallHook - { - public Post(@NotNull InstallOperator operator, boolean isDependency, @Nullable String resolveQuery) - { - super(operator, isDependency, resolveQuery); - } - - public Post(@NotNull InstallOperator operator, boolean isDependency) - { - super(operator, isDependency, null); - } - - public Post(@NotNull InstallOperator operator) - { - super(operator, false, null); - } - } -} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstalledHook.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstalledHook.java new file mode 100644 index 00000000..15b6fea1 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginInstalledHook.java @@ -0,0 +1,31 @@ +package net.kunmc.lab.kpm.hook.hooks; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.kunmc.lab.kpm.hook.KPMHook; +import net.kunmc.lab.kpm.meta.InstallOperator; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * プラグインがインストールされたときに呼び出されるフックです。 + */ +@Data +@AllArgsConstructor +public class PluginInstalledHook implements KPMHook +{ + /** + * プラグインのインストール者です。 + */ + @NotNull + private final InstallOperator operator; + /** + * プラグインが依存関係であるかどうかを表します。 + */ + boolean isDependency; + /** + * プラグインのインストールに使用した解決クエリです。 + */ + @Nullable + String resolveQuery; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java index b03a6161..420743e7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java @@ -2,7 +2,7 @@ import net.kunmc.lab.kpm.KPMDaemon; import net.kunmc.lab.kpm.hook.HookExecutor; -import net.kunmc.lab.kpm.hook.hooks.PluginInstallHook; +import net.kunmc.lab.kpm.hook.hooks.PluginInstalledHook; import net.kunmc.lab.kpm.installer.AbstractInstaller; import net.kunmc.lab.kpm.installer.task.InstallTask; import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; @@ -140,13 +140,6 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr // Start install this.postSignal(new PluginInstallingSignal(path, pluginDescription)); - if (kpmInformationFile != null) - kpmInformationFile.getHooks().runHook(new PluginInstallHook.Pre( - operator, - isDependency, - query - )); - PluginsInstallErrorCause checkEnvError; if ((checkEnvError = this.checkEnv(pluginDescription, kpmInformationFile)) != null) return new PluginsInstallResult(false, this.state, checkEnvError); @@ -214,7 +207,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr ); if (kpmInformationFile != null) - kpmInformationFile.getHooks().runHook(new PluginInstallHook.Post( + kpmInformationFile.getHooks().runHook(new PluginInstalledHook( operator, isDependency, query From ce8c553ffe359087c12c8422629d0707232588b1 Mon Sep 17 00:00:00 2001 From: Peyang Date: Tue, 25 Oct 2022 23:26:22 +0900 Subject: [PATCH 415/745] feat: Uninstall hook --- .../kpm/hook/hooks/PluginUninstallHook.java | 67 +++++++++++++++++++ .../task/tasks/uninstall/UnInstallTask.java | 11 +++ .../kunmc/lab/kpm/kpminfo/KPMInfoManager.java | 24 +++++++ 3 files changed, 102 insertions(+) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginUninstallHook.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginUninstallHook.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginUninstallHook.java new file mode 100644 index 00000000..644f0da1 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/PluginUninstallHook.java @@ -0,0 +1,67 @@ +package net.kunmc.lab.kpm.hook.hooks; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.kunmc.lab.kpm.hook.KPMHook; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * プラグインがアンインストールされるときに呼び出されるフックです。 + */ +@Getter +@AllArgsConstructor +public class PluginUninstallHook implements KPMHook +{ + /** + * プラグイン情報ファイルです。 + */ + @NotNull + private final PluginDescriptionFile pluginDescription; + + /** + * KPM情報ファイルです。 + */ + @Nullable + private final KPMInformationFile kpmInfo; + + public PluginUninstallHook(@NotNull PluginDescriptionFile pluginDescription) + { + this(pluginDescription, null); + } + + @Getter + public static class Pre extends PluginUninstallHook + { + @NotNull + private final Plugin plugin; + + public Pre(@NotNull PluginDescriptionFile pluginDescription, @Nullable KPMInformationFile kpmInfo, @NotNull Plugin plugin) + { + super(pluginDescription, kpmInfo); + this.plugin = plugin; + } + + public Pre(@NotNull PluginDescriptionFile pluginDescription, @NotNull Plugin plugin) + { + super(pluginDescription); + this.plugin = plugin; + } + } + + public static class Post extends PluginUninstallHook + { + public Post(@NotNull PluginDescriptionFile pluginDescription, @Nullable KPMInformationFile kpmInfo) + { + super(pluginDescription, kpmInfo); + } + + public Post(@NotNull PluginDescriptionFile pluginDescription) + { + super(pluginDescription); + } + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java index 9737abca..9fbf7ba1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.uninstall; import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.hook.hooks.PluginUninstallHook; import net.kunmc.lab.kpm.installer.AbstractInstaller; import net.kunmc.lab.kpm.installer.task.InstallTask; import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginDisablingSignal; @@ -9,6 +10,7 @@ import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUninstallingSignal; import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.StartingGCSignal; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; import net.kunmc.lab.kpm.loader.CommandsPatcher; import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; @@ -144,6 +146,12 @@ public UnInstallTask(@NotNull AbstractInstaller installer) private UnInstallErrorCause uninstallOnePlugin(@NotNull Plugin plugin) { this.postSignal(new PluginUninstallingSignal(plugin)); + KPMInformationFile kpmInfo = null; + if (this.daemon.getKpmInfoManager().hasInfo(plugin)) + kpmInfo = this.daemon.getKpmInfoManager().getOrLoadInfo(plugin); + + if (kpmInfo != null) + kpmInfo.getHooks().runHook(new PluginUninstallHook.Pre(plugin.getDescription(), kpmInfo, plugin)); this.taskState = UnInstallState.RECIPES_UNREGISTERING; this.unregisterRecipes(plugin); @@ -179,6 +187,9 @@ private UnInstallErrorCause uninstallOnePlugin(@NotNull Plugin plugin) this.postSignal(new PluginUnloadingSignal.Post(pluginName)); + if (kpmInfo != null) + kpmInfo.getHooks().runHook(new PluginUninstallHook.Post(plugin.getDescription(), kpmInfo)); + return UnInstallErrorCause.INTERNAL_UNINSTALL_OK; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java index d275ae03..a63e6232 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java @@ -70,6 +70,30 @@ public KPMInformationFile getInfo(@NotNull String pluginName) return this.lookupNames.get(pluginName); } + /** + * プラグインのKPM情報ファイルを取得するか読み込みます。 + * + * @param plugin プラグイン + * @return プラグインのKPM情報ファイル + */ + @Nullable + public KPMInformationFile getOrLoadInfo(@NotNull Plugin plugin) + { + KPMInformationFile info = this.getInfo(plugin); + if (info != null) + return info; + + try + { + return this.loadInfo(PluginUtil.getFile(plugin).toPath(), plugin.getDescription()); + } + catch (FileNotFoundException | InvalidInformationFileException e) + { + e.printStackTrace(); + return null; + } + } + /** * プラグインが KPM情報ファイルを持っているかどうかを取得します。 * From 24a56ed5c074827c4b530f6f302f19b0e72e0fcb Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 27 Oct 2022 00:13:27 +0900 Subject: [PATCH 416/745] fix: Reversed KPM version comparing predicate --- .../kpm/installer/task/tasks/install/PluginsInstallTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java index 420743e7..2d858427 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java @@ -301,7 +301,7 @@ private PluginsInstallErrorCause checkEnv(PluginDescriptionFile pluginDescriptio Version daemonVersion = this.progress.getInstaller().getDaemon().getVersion(); - if (kpmInformation.getKpmVersion().isOlderThan(daemonVersion)) + if (kpmInformation.getKpmVersion().isNewerThan(daemonVersion)) { PluginIncompatibleWithKPMSignal incompatibleSignal = new PluginIncompatibleWithKPMSignal(pluginDescription, kpmInformation, daemonVersion); From 0e12224dcca33a07131b7c1c257b8cdc7da097e6 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 27 Oct 2022 00:14:26 +0900 Subject: [PATCH 417/745] fix: NoClassFoundException always occurs when hooks are defined in kpm.yml --- .../kunmc/lab/kpm/hook/HookRecipientList.java | 69 ++++++++++++++++++- .../kunmc/lab/kpm/kpminfo/KPMInfoManager.java | 3 + .../kunmc/lab/kpm/kpminfo/KPMInfoParser.java | 32 +-------- 3 files changed, 73 insertions(+), 31 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java index 36ffeb98..c52ffad0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java @@ -1,21 +1,33 @@ package net.kunmc.lab.kpm.hook; import lombok.Getter; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.kpminfo.InvalidInformationFileException; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.List; /** * KPMフックの受け取りを行うクラスを管理するクラスです。 */ public class HookRecipientList extends ArrayList { + @Getter + private final KPMDaemon daemon; @Getter private final HookExecutor executor; - public HookRecipientList(@NotNull HookExecutor executor) + @Getter + private final List reservedHookClasses; + + public HookRecipientList(@NotNull KPMDaemon daemon, @NotNull HookExecutor executor) { + this.daemon = daemon; this.executor = executor; + this.reservedHookClasses = new ArrayList<>(); } /** @@ -25,7 +37,62 @@ public HookRecipientList(@NotNull HookExecutor executor) */ public void runHook(KPMHook hook) { + if (!this.reservedHookClasses.isEmpty()) + { + try + { + this.bakeHooks(this.daemon); + } + catch (InvalidInformationFileException e) + { + throw new IllegalStateException("Failed to bake hook listeners: " + e.getMessage(), e); + } + } + for (KPMHookRecipient recipient : this) this.executor.runHook(recipient, hook); } + + public void add(@NotNull String className) + { + this.reservedHookClasses.add(className); + } + + /** + * 予約クラス名からフックを作成します。 + * + * @param daemon KPMデーモンのインスタンス + * @throws InvalidInformationFileException 予約クラス名が無効な場合 + */ + public void bakeHooks(@NotNull KPMDaemon daemon) throws InvalidInformationFileException + { + for (String className : this.reservedHookClasses) + { + try + { + Class hookClass = Class.forName(className); + if (!KPMHookRecipient.class.isAssignableFrom(hookClass)) + throw new InvalidInformationFileException("Class " + className + " is not a KPMHookRecipient."); + + Constructor constructor = + hookClass.asSubclass(KPMHookRecipient.class).getConstructor(KPMDaemon.class); + + this.add(constructor.newInstance(daemon)); + } + catch (ClassNotFoundException e) + { + throw new InvalidInformationFileException("Hook recipient class was not found: " + className, e); + } + catch (InstantiationException | IllegalAccessException | InvocationTargetException e) + { + throw new InvalidInformationFileException("Failed to create an instance of hook recipient class: " + + className, e); + } + catch (NoSuchMethodException e) + { + throw new InvalidInformationFileException("Hook recipient class must have a constructor with" + + " a single parameter of type KPMDaemon: " + className, e); + } + } + } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java index a63e6232..a91169f1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java @@ -42,6 +42,9 @@ public KPMInformationFile loadInfo(@NotNull Path path, @NotNull PluginDescriptio KPMInformationFile info = KPMInfoParser.load(this.daemon, path); this.lookupNames.put(descriptionFile.getName(), info); + if (PluginUtil.isPluginLoaded(descriptionFile.getName())) + info.getHooks().bakeHooks(this.daemon); + return info; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java index a2970aac..13a526c9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java @@ -2,7 +2,6 @@ import net.kunmc.lab.kpm.KPMDaemon; import net.kunmc.lab.kpm.hook.HookRecipientList; -import net.kunmc.lab.kpm.hook.KPMHookRecipient; import net.kunmc.lab.kpm.resolver.QueryContext; import net.kunmc.lab.kpm.utils.versioning.Version; import org.jetbrains.annotations.NotNull; @@ -13,8 +12,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -100,7 +97,7 @@ private static QueryContext parseUpdateQuery(Map map) throws InvalidInform @NotNull private static HookRecipientList parseHooks(KPMDaemon daemon, Map map) throws InvalidInformationFileException { - HookRecipientList result = new HookRecipientList(daemon.getHookExecutor()); + HookRecipientList result = new HookRecipientList(daemon, daemon.getHookExecutor()); if (!map.containsKey("hooks")) return result; @@ -116,32 +113,7 @@ private static HookRecipientList parseHooks(KPMDaemon daemon, Map map) thr if (!(hook instanceof String)) throw new InvalidInformationFileException("hooks must be a list of full-qualified class names."); - String hookClassName = (String) hook; - try - { - Class hookClass = Class.forName(hookClassName); - if (!KPMHookRecipient.class.isAssignableFrom(hookClass)) - throw new InvalidInformationFileException("Class " + hookClassName + " is not a KPMHookRecipient."); - - Constructor constructor = - hookClass.asSubclass(KPMHookRecipient.class).getConstructor(KPMDaemon.class); - - result.add(constructor.newInstance(daemon)); - } - catch (ClassNotFoundException e) - { - throw new InvalidInformationFileException("Hook recipient class was not found: " + hookClassName, e); - } - catch (InstantiationException | IllegalAccessException | InvocationTargetException e) - { - throw new InvalidInformationFileException("Failed to create an instance of hook recipient class: " + - hookClassName, e); - } - catch (NoSuchMethodException e) - { - throw new InvalidInformationFileException("Hook recipient class must have a constructor with" + - " a single parameter of type KPMDaemon: " + hookClassName, e); - } + result.add(hook.toString()); } return result; From 3322046cb69fecf90c0238f4ee1ee35e5591afef Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 27 Oct 2022 00:19:21 +0900 Subject: [PATCH 418/745] fix: Invalid signature of KPMHookRecipient constructor --- .../src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java index a88d662d..f5bf91d2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/KPMHookRecipient.java @@ -22,7 +22,7 @@ public abstract class KPMHookRecipient private final HashMap> hooks; - protected KPMHookRecipient(KPMDaemon daemon) + public KPMHookRecipient(KPMDaemon daemon) { this.daemon = daemon; this.hooks = new HashMap<>(); From df8ca5f2aaccf9068c4440362b3aa55805ddbabe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Oct 2022 20:19:55 +0000 Subject: [PATCH 419/745] chore(deps): bump maven-shade-plugin from 3.4.0 to 3.4.1 Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.0...maven-shade-plugin-3.4.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0df69b94..0bef2834 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.4.0 + 3.4.1 package From f8c37cf9c67df4be75e706baddf2ab629007b7a9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 28 Oct 2022 20:40:33 +0900 Subject: [PATCH 420/745] fix: Install doesn't mark as completed when install was failed with exception --- .../lab/kpm/installer/AbstractInstaller.java | 8 ++++++++ .../installer/InstallFailedInstallResult.java | 16 ++++++++++++++++ .../AutoRemoveFinishedSignalHandler.java | 6 ++++-- .../clean/GarbageCleanFinishedSignalHandler.java | 5 ++++- .../intall/InstallFinishedSignalHandler.java | 5 +++++ .../UninstallFinishedSignalHandler.java | 6 ++++++ 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java index 8ae48290..d39a4a0b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java @@ -80,6 +80,14 @@ public InstallResult

    run(@NotNull A arguments) throws IOException { return this.handleTaskError(e.getResult()); } + catch (Exception e) + { + e.printStackTrace(); + InstallFailedInstallResult result = new InstallFailedInstallResult<>(this.progress, e); + this.postSignal(new InstallFinishedSignal(result)); + + return result; + } } /** diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallFailedInstallResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallFailedInstallResult.java index f6f1e315..2036eb72 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallFailedInstallResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallFailedInstallResult.java @@ -15,6 +15,12 @@ public class InstallFailedInstallResult

    , T extends Enum, S extends Enum> extends InstallResult

    { + /** + * 例外が発生した場合の例外 + */ + @Nullable + private final Exception exception; + /** * 失敗した理由を表す列挙型です。 */ @@ -29,6 +35,7 @@ public class InstallFailedInstallResult

    , T extends Enum, S public InstallFailedInstallResult(@NotNull InstallProgress progress, @Nullable T reason, @NotNull S taskStatus) { super(false, progress); + this.exception = null; this.reason = reason; this.taskStatus = taskStatus; } @@ -36,7 +43,16 @@ public InstallFailedInstallResult(@NotNull InstallProgress progress, @Null public InstallFailedInstallResult(InstallProgress progress, @Nullable T reason) { super(false, progress); + this.exception = null; this.reason = reason; this.taskStatus = null; } + + public InstallFailedInstallResult(@NotNull InstallProgress progress, @NotNull Exception exception) + { + super(false, progress); + this.exception = exception; + this.reason = null; + this.taskStatus = null; + } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java index d70dd197..11b56fe9 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/autoremove/AutoRemoveFinishedSignalHandler.java @@ -43,7 +43,9 @@ protected void onFail(InstallFailedInstallResult result) { if (result.getReason() != null && result.getReason() instanceof AutoRemoveErrorCause) this.handleAutoRemoveErrors((AutoRemoveErrorCause) result.getReason()); - - this.terminal.error("プラグインの自動削除に失敗しました。"); + else if (result.getException() != null) + this.terminal.error("プラグインの自動削除中に予期しないエラーが発生しました:%s", result.getException()); + else + this.terminal.error("プラグインの自動削除に失敗しました。"); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java index f640b770..a97c0271 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/clean/GarbageCleanFinishedSignalHandler.java @@ -43,6 +43,9 @@ protected void onFail(InstallFailedInstallResult result) { if (result.getReason() != null && result.getReason() instanceof GarbageCleanErrorCause) this.handleGarbageCleanErrors((GarbageCleanErrorCause) result.getReason()); - this.terminal.error("不要データの削除に失敗しました。"); + else if (result.getException() != null) + this.terminal.error("不要データの削除中に予期しないエラーが発生しました:%s", result.getException()); + else + this.terminal.error("不要データの削除に失敗しました。"); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallFinishedSignalHandler.java index 795f1b3a..05f297a0 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/InstallFinishedSignalHandler.java @@ -141,6 +141,11 @@ protected void onFail(InstallFailedInstallResult result) if (result.getReason() instanceof InstallErrorCause && this.handleGeneralErrors((InstallErrorCause) result.getReason())) return; + if (result.getException() != null) + { + this.terminal.error("プラグインのインストール中に予期しないエラーが発生しました:%s", result.getException()); + return; + } Enum errorCause = result.getReason(); diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java index f55d15ae..f968e411 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallFinishedSignalHandler.java @@ -53,6 +53,12 @@ protected void onFail(InstallFailedInstallResult result) if (result.getReason() instanceof net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallErrorCause && this.handleGeneralErrors((net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallErrorCause) result.getReason())) return; + if (result.getException() != null) + { + this.terminal.error("アンインストール中に予期しないエラーが発生しました:%s", result.getException()); + return; + } + if (result.getReason() instanceof UnInstallErrorCause) { From 2a58b33737be8014c7ebc61c99332be1c1e4dd21 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 28 Oct 2022 20:56:43 +0900 Subject: [PATCH 421/745] docs: Serial field --- .../net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java index d1448988..1b5211c2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java @@ -20,13 +20,16 @@ public class KPMInformationFile /** * 対応するKPMのバージョンです。 * このバージョンより古いKPMではこの情報ファイルを読み込むことができません。 - * YAMLのキーは{@code kpm}です。 + * + * @serial + * @serialField kpm {@link Version} 対応するKPMのバージョンです。 */ @NotNull Version kpmVersion; /** * アップデートで使用するクエリです。 - * YAMLのキーは{@code update}です。 + * @serial + * @serialField update {@link QueryContext} アップデートで使用するクエリです。 */ @Nullable QueryContext updateQuery; @@ -37,6 +40,8 @@ public class KPMInformationFile * @see net.kunmc.lab.kpm.hook.KPMHook * @see KPMHookRecipient * @see net.kunmc.lab.kpm.hook.HookListener + * @serial + * @serialField hooks {@link HookRecipientList} KPMフックを受け取る {@link KPMHookRecipient} のクラス名です。 */ @NotNull HookRecipientList hooks; From 0154e943f3322b443843b5302321c40d38cab1a2 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 28 Oct 2022 21:04:34 +0900 Subject: [PATCH 422/745] refactor: Remove unused event Listener registering --- .../java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java index b84fec45..9c0f05fa 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java @@ -3,9 +3,6 @@ import com.zaxxer.hikari.HikariDataSource; import net.kunmc.lab.kpm.KPMDaemon; import net.kunmc.lab.kpm.utils.db.Transaction; -import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; -import org.bukkit.Bukkit; -import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoadOrder; @@ -26,7 +23,7 @@ * プラグインのメタデータを提供するクラスです。 */ @SuppressWarnings("unused") -public class PluginMetaProvider implements Listener +public class PluginMetaProvider { private final HikariDataSource db; @@ -35,10 +32,6 @@ public PluginMetaProvider(@NotNull Plugin plugin, @NotNull Path databasePath) this.db = Transaction.createDataSource(databasePath); this.initializeTables(); - - // Below lambda will be executed after all plugins are loaded. - // (Bukkit runs task after all plugins are loaded.) - Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, plugin), 1L); } /** From c226ac50ae5c7b7232048f345a5dd09b74946ae9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 28 Oct 2022 21:07:35 +0900 Subject: [PATCH 423/745] fix: Invalid way of removing unused plugin from db --- .../net/kunmc/lab/kpm/meta/PluginMetaIterator.java | 10 +++++----- .../net/kunmc/lab/kpm/meta/PluginMetaProvider.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java index 54c4210a..39c02830 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java @@ -11,6 +11,7 @@ public class PluginMetaIterator implements Iterator, AutoCloseable { + private final PluginMetaProvider provider; private final Transaction transaction; private final Transaction.QueryResult results; private final List removeTargets; @@ -20,6 +21,7 @@ public class PluginMetaIterator implements Iterator, AutoCloseable public PluginMetaIterator(@NotNull PluginMetaProvider metaProvider, @NotNull Transaction transaction) { + this.provider = metaProvider; this.transaction = transaction.renew("SELECT * FROM plugin_meta"); this.results = this.transaction.executeQuery() .setMapper(row -> { @@ -86,12 +88,10 @@ public void close() { this.results.close(); - Transaction transaction = this.transaction.renew("DELETE FROM plugin_meta WHERE name = ?"); for (String name : this.removeTargets) - { - transaction.set(1, name); - transaction.executeUpdate(false); - } + this.provider.removePluginRelationalData(this.transaction.getConnection(), name); + + this.transaction.finishManually(); } catch (SQLException e) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java index 9c0f05fa..a8b34bc0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java @@ -401,7 +401,7 @@ public void removePluginMeta(@NotNull String pluginName) .executeUpdate(); } - private void removePluginRelationalData(Connection connection, String pluginName) throws SQLException + void removePluginRelationalData(Connection connection, String pluginName) throws SQLException { PreparedStatement statement = connection.prepareStatement("DELETE FROM plugin_author WHERE name = ?"); From 82561ece0a90f6dcf66deffac821caf40d5762c5 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 28 Oct 2022 21:25:46 +0900 Subject: [PATCH 424/745] feat: More kpm info --- .../java/net/kunmc/lab/kpm/KPMDaemon.java | 37 +++++++++++++++---- .../net/kunmc/lab/kpm/KPMEnvironment.java | 4 +- .../kunmc/lab/kpm/hook/HookRecipientList.java | 4 ++ .../impls/register/TokenRegisterer.java | 2 +- .../task/tasks/uninstall/UnInstallTask.java | 4 +- .../kunmc/lab/kpm/kpminfo/KPMInfoManager.java | 5 ++- .../kunmc/lab/kpm/loader/PluginLoader.java | 4 +- .../lab/kpm/meta/PluginMetaIterator.java | 2 - .../lab/kpm/meta/PluginMetaProvider.java | 2 +- 9 files changed, 46 insertions(+), 18 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 09cdfc15..1a944735 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -7,6 +7,7 @@ import net.kunmc.lab.kpm.hook.HookExecutor; import net.kunmc.lab.kpm.installer.InstallManager; import net.kunmc.lab.kpm.kpminfo.KPMInfoManager; +import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; import net.kunmc.lab.kpm.loader.PluginLoader; import net.kunmc.lab.kpm.meta.InstallOperator; import net.kunmc.lab.kpm.meta.PluginMeta; @@ -20,15 +21,17 @@ import net.kunmc.lab.kpm.resolver.impl.SpigotMCResolver; import net.kunmc.lab.kpm.utils.http.Requests; import net.kunmc.lab.kpm.utils.versioning.Version; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; /** @@ -131,6 +134,28 @@ public void setupDaemon(@NotNull Path dataFolder, @NotNull List organiza this.setupPluginResolvers(organizationNames); this.setupToken(); this.initializeRequests(); + this.loadKPMInformationFromPlugins(); + } + + private void loadKPMInformationFromPlugins() + { + Runner.runLater(() -> { + + this.logger.info("Loading KPM information from plugins..."); + + KPMInfoManager kpmInfoManager = this.getKpmInfoManager(); + Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); + + int loaded = 0; + for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) + { + KPMInformationFile info = kpmInfoManager.getOrLoadInfo(plugin); + if (info != null) + loaded++; + } + + this.logger.log(Level.INFO, "Loaded {0} KPM information from {1} plugins.", new Object[]{loaded, plugins.length}); + }, 1L); } private void setupDependencyTree() @@ -153,8 +178,7 @@ private void setupDependencyTree() if (pluginNames.contains(meta.getName().toLowerCase())) continue; - - this.logger.info("Plugin {} is not loaded by server. Removing from database ...", meta.getName()); + this.logger.log(Level.INFO, "Found plugin meta: {0}", meta.getName()); iterator.remove(); } } @@ -171,8 +195,7 @@ private void setupDependencyTree() null, false ); - - this.logger.info("Plugin {} is not managed by KPM. Adding to database ...", plugin.getName()); + this.logger.log(Level.INFO, "Plugin {0} is not managed by KPM. Adding to database ...", plugin.getName()); this.pluginMetaManager.getProvider().buildDependencyTree(plugin); } @@ -204,12 +227,12 @@ private void setupToken() tokenAvailable = true; if (!tokenAvailable) - this.logger.warn("Token is not available. Please login with /kpm register"); + this.logger.log(Level.WARNING, "No token is available in this server. Please run /kpm token to set a token."); } catch (IOException e) { e.printStackTrace(); - this.logger.error("Failed to load token"); + this.logger.log(Level.WARNING, "Failed to load token."); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMEnvironment.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMEnvironment.java index 66ad0e92..9a8b4836 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMEnvironment.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMEnvironment.java @@ -5,11 +5,11 @@ import lombok.Singular; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; import java.nio.file.Path; import java.util.List; import java.util.Map; +import java.util.logging.Logger; /** * KPM の実行環境を表すクラスです。 @@ -92,6 +92,6 @@ public static KPMEnvironmentBuilder builder(@NotNull Plugin plugin, @NotNull Log public static KPMEnvironmentBuilder builder(@NotNull Plugin plugin) { - return builder(plugin, plugin.getSLF4JLogger(), plugin.getDataFolder().toPath()); + return builder(plugin, plugin.getLogger(), plugin.getDataFolder().toPath()); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java index c52ffad0..38ae43a8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java @@ -9,6 +9,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; /** * KPMフックの受け取りを行うクラスを管理するクラスです。 @@ -70,7 +71,10 @@ public void bakeHooks(@NotNull KPMDaemon daemon) throws InvalidInformationFileEx { try { + this.daemon.getLogger().setLevel(Level.OFF); Class hookClass = Class.forName(className); + this.daemon.getLogger().setLevel(Level.INFO); + if (!KPMHookRecipient.class.isAssignableFrom(hookClass)) throw new InvalidInformationFileException("Class " + className + " is not a KPMHookRecipient."); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java index 31214800..4acb24dc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java @@ -251,7 +251,7 @@ private VerificationSubmitPollingResponse pollVerifyCodeSubmit(UserVerificationC this.postSignal(new UserVerifyDeniedSignal(apiResponse.getUserCode())); return null; default: - this.daemon.getLogger().warn("Unknown error occurred while polling user verification: " + error); + this.daemon.getLogger().warning("Unknown error occurred while polling user verification: " + error); return null; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java index 9fbf7ba1..b5da89aa 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java @@ -212,13 +212,13 @@ private boolean unloadClasses(@NotNull Plugin plugin) catch (IllegalAccessException e) { e.printStackTrace(); - this.daemon.getLogger().warn("Unable to unload classes of plugin " + plugin.getName()); + this.daemon.getLogger().warning("Unable to unload classes of plugin " + plugin.getName()); return false; } catch (IOException e) { e.printStackTrace(); - this.daemon.getLogger().warn("Unable to close class loader of plugin " + + this.daemon.getLogger().warning("Unable to close class loader of plugin " + plugin.getName()); return false; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java index a91169f1..0ff3c5ca 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoManager.java @@ -86,6 +86,9 @@ public KPMInformationFile getOrLoadInfo(@NotNull Plugin plugin) if (info != null) return info; + if (!this.hasInfo(plugin)) + return null; + try { return this.loadInfo(PluginUtil.getFile(plugin).toPath(), plugin.getDescription()); @@ -121,7 +124,7 @@ public boolean hasInfo(@NotNull Path pluginFile) { try (ZipFile zipFile = new ZipFile(pluginFile.toFile())) { - return zipFile.getEntry("kpm.info") != null; + return zipFile.getEntry("kpm.yml") != null; } catch (Exception e) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoader.java index da490fc1..255e8016 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoader.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/PluginLoader.java @@ -173,12 +173,12 @@ private void unloadClasses(Plugin plugin) catch (IllegalAccessException e) { e.printStackTrace(); - this.daemon.getLogger().warn("Unable to unload classes of plugin " + plugin.getName()); + this.daemon.getLogger().warning("Unable to unload classes of plugin " + plugin.getName()); } catch (IOException e) { e.printStackTrace(); - this.daemon.getLogger().warn("Unable to close class loader of plugin " + plugin.getName()); + this.daemon.getLogger().warning("Unable to close class loader of plugin " + plugin.getName()); } // Check +XX:+DisableExplicitGC flag diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java index 39c02830..b3bbe6cc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java @@ -90,8 +90,6 @@ public void close() for (String name : this.removeTargets) this.provider.removePluginRelationalData(this.transaction.getConnection(), name); - - this.transaction.finishManually(); } catch (SQLException e) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java index a8b34bc0..90e80e92 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java @@ -261,7 +261,7 @@ private void savePluginRelationalData(Connection connection, Plugin plugin) thro catch (SQLException e) { KPMDaemon.getInstance().getLogger() - .warn("Failed to save plugin author data: " + name + " by " + authors); + .warning("Failed to save plugin author data: " + name + " by " + authors); } statement = connection.prepareStatement("INSERT INTO depend(name, dependency) VALUES(?, ?)"); From 3d6688fcf5129dce85d75f7c66c4fcbd627c3e7e Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 28 Oct 2022 21:59:31 +0900 Subject: [PATCH 425/745] chore: v3.0.0-pre6 --- KPMDaemon/pom.xml | 2 +- KPMPlugin/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index 2a5684e5..cb74bff0 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -5,7 +5,7 @@ TeamKunPluginManager net.kunmc.lab - 3.0.0-pre5 + 3.0.0-pre6 ../pom.xml 4.0.0 diff --git a/KPMPlugin/pom.xml b/KPMPlugin/pom.xml index 57c688d3..25993302 100644 --- a/KPMPlugin/pom.xml +++ b/KPMPlugin/pom.xml @@ -5,7 +5,7 @@ TeamKunPluginManager net.kunmc.lab - 3.0.0-pre5 + 3.0.0-pre6 ../pom.xml 4.0.0 @@ -88,7 +88,7 @@ net.kunmc.lab.kpm KPMDaemon - 3.0.0-pre5 + 3.0.0-pre6 compile diff --git a/pom.xml b/pom.xml index 32b132a2..1b38edc9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kunmc.lab TeamKunPluginManager - 3.0.0-pre5 + 3.0.0-pre6 KPMDaemon KPMPlugin From 30b5d7c6accd5e8cd1ef2f72ff1ce086bd8f9e29 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 15:28:00 +0900 Subject: [PATCH 426/745] refactor: Remove unused argument of KPMDaemon#setupDaemon --- KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 1a944735..06f4859a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull; import java.io.IOException; -import java.nio.file.Path; import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -114,7 +113,7 @@ public KPMDaemon(@NotNull KPMEnvironment env) this.installManager = new InstallManager(this); this.hookExecutor = new HookExecutor(this); - this.setupDaemon(env.getDataDirPath(), env.getOrganizations()); + this.setupDaemon(env.getOrganizations()); } /** @@ -128,7 +127,7 @@ public static KPMDaemon getInstance() return INSTANCE; } - public void setupDaemon(@NotNull Path dataFolder, @NotNull List organizationNames) + public void setupDaemon(@NotNull List organizationNames) { this.setupDependencyTree(); this.setupPluginResolvers(organizationNames); From f506b0cc727eb553b6ae1fcc1aaca0970815eec5 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 17:38:40 +0900 Subject: [PATCH 427/745] docs: Fix piled dot --- KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java index 42f1265b..2f178852 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java @@ -9,7 +9,7 @@ public class Alias { /** - * 正式名です。。 + * 正式名です。 */ String name; From a4c09aa7c379c796d0422713a925cdb09c42d481 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 20:06:00 +0900 Subject: [PATCH 428/745] docs: fix docs --- .../net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java index 1b5211c2..1d9b2c17 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java @@ -21,15 +21,14 @@ public class KPMInformationFile * 対応するKPMのバージョンです。 * このバージョンより古いKPMではこの情報ファイルを読み込むことができません。 * - * @serial - * @serialField kpm {@link Version} 対応するKPMのバージョンです。 + * @serial kpm {@link Version} 対応するKPMのバージョンです。 */ @NotNull Version kpmVersion; /** * アップデートで使用するクエリです。 - * @serial - * @serialField update {@link QueryContext} アップデートで使用するクエリです。 + * + * @serial update {@link QueryContext} アップデートで使用するクエリです。 */ @Nullable QueryContext updateQuery; @@ -40,8 +39,7 @@ public class KPMInformationFile * @see net.kunmc.lab.kpm.hook.KPMHook * @see KPMHookRecipient * @see net.kunmc.lab.kpm.hook.HookListener - * @serial - * @serialField hooks {@link HookRecipientList} KPMフックを受け取る {@link KPMHookRecipient} のクラス名です。 + * @serial hooks {@link HookRecipientList} KPMフックを受け取る {@link KPMHookRecipient} のクラス名です。 */ @NotNull HookRecipientList hooks; From 0d64832d732c746077401182e9d0c977def6d025 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 20:10:21 +0900 Subject: [PATCH 429/745] feat: RawURLResolver(was removed with degrade) --- .../java/net/kunmc/lab/kpm/KPMDaemon.java | 2 ++ .../lab/kpm/resolver/PluginResolver.java | 7 ++++- .../lab/kpm/resolver/impl/RawURLResolver.java | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/RawURLResolver.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 06f4859a..d9c3cc97 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -18,6 +18,7 @@ import net.kunmc.lab.kpm.resolver.impl.CurseBukkitResolver; import net.kunmc.lab.kpm.resolver.impl.GitHubURLResolver; import net.kunmc.lab.kpm.resolver.impl.OmittedGitHubResolver; +import net.kunmc.lab.kpm.resolver.impl.RawURLResolver; import net.kunmc.lab.kpm.resolver.impl.SpigotMCResolver; import net.kunmc.lab.kpm.utils.http.Requests; import net.kunmc.lab.kpm.utils.versioning.Version; @@ -214,6 +215,7 @@ private void setupPluginResolvers(List organizationNames) organizationNames, githubResolver )); + this.pluginResolver.addOnNotFoundResolver(new RawURLResolver()); } private void setupToken() diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java index 57a9e3be..b11c5f9b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java @@ -153,7 +153,12 @@ else if (!resolver.isValidResolver(queryContext)) private static boolean isValidURLResolver(URL url, URLResolver resolver) { - for (String host : resolver.getHosts()) + String[] hosts = resolver.getHosts(); + + if (hosts.length == 0) + return true; + + for (String host : hosts) { if (url.getHost().equalsIgnoreCase(host)) return true; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/RawURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/RawURLResolver.java new file mode 100644 index 00000000..f6a03a5d --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/RawURLResolver.java @@ -0,0 +1,29 @@ +package net.kunmc.lab.kpm.resolver.impl; + +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.resolver.interfaces.URLResolver; +import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; + +public class RawURLResolver implements URLResolver +{ + + @Override + public ResolveResult resolve(QueryContext query) + { + return new SuccessResult(this, query.getQuery(), ResolveResult.Source.DIRECT); + } + + @Override + public ResolveResult autoPickOnePlugin(MultiResult multiResult) + { + throw new UnsupportedOperationException(); + } + + @Override + public String[] getHosts() + { + return new String[0]; + } +} From 5101f37cfe1c843775f500650295e6884a041ab8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 20:11:28 +0900 Subject: [PATCH 430/745] refactor: PluginResolver#addOnNotfoundResolver => PluginResolver#addFallbackResolver --- .../src/main/java/net/kunmc/lab/kpm/KPMDaemon.java | 4 ++-- .../net/kunmc/lab/kpm/resolver/PluginResolver.java | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index d9c3cc97..57060b1a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -211,11 +211,11 @@ private void setupPluginResolvers(List organizationNames) this.pluginResolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); this.pluginResolver.addResolver(githubResolver, "github", "gh"); - this.pluginResolver.addOnNotFoundResolver(new BruteforceGitHubResolver( + this.pluginResolver.addFallbackResolver(new BruteforceGitHubResolver( organizationNames, githubResolver )); - this.pluginResolver.addOnNotFoundResolver(new RawURLResolver()); + this.pluginResolver.addFallbackResolver(new RawURLResolver()); } private void setupToken() diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java index b11c5f9b..c7fcdaa3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java @@ -19,13 +19,13 @@ public class PluginResolver { private final HashMap> resolvers; - private final List onNotFoundResolvers; + private final List fallbackResolvers; private final List allResolvers; public PluginResolver() { this.resolvers = new HashMap<>(); - this.onNotFoundResolvers = new ArrayList<>(); + this.fallbackResolvers = new ArrayList<>(); this.allResolvers = new ArrayList<>(); } @@ -54,14 +54,14 @@ public void addResolver(BaseResolver resolver, String... names) } /** - * 代替リゾルバを追加します。 - * 代替リゾルバは、プラグインが見つからなかった場合にフォールバックとして使用されるリゾルバです。 + * フォールバックリゾルバを追加します。 + * フォールバックリゾルバは、プラグインが見つからなかった場合にフォールバックとして使用されるリゾルバです。 * * @param resolver 追加するリゾルバ */ - public void addOnNotFoundResolver(BaseResolver resolver) + public void addFallbackResolver(BaseResolver resolver) { - this.onNotFoundResolvers.add(resolver); + this.fallbackResolvers.add(resolver); } /** @@ -97,7 +97,7 @@ private ResolveResult actuallyResolve(List resolvers, QueryContext { ErrorResult error = (ErrorResult) result; if (error.getCause() != ErrorResult.ErrorCause.VERSION_MISMATCH) - result = this.resolves(this.onNotFoundResolvers, queryContext, url); + result = this.resolves(this.fallbackResolvers, queryContext, url); } return result; From ccd539cb55da244d68a4a989293a0755b84ccddb Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 20:24:23 +0900 Subject: [PATCH 431/745] docs: Fix invalid javadoc --- .../lab/kpm/installer/impls/autoremove/PluginAutoRemover.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java index 5aa35b2f..5f190810 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java @@ -25,7 +25,8 @@ * 自動削除は主に以下の流れで動作します。 * *

      - *
    1. {@link AutoRemoveTasks#} - 自動削除対象のプラグインを検索する。
    2. + *
    3. {@link AutoRemoveTasks#SEARCHING_REMOVABLES} - 自動削除対象のプラグインを検索する。
    4. + *
    5. {@link AutoRemoveTasks#UNINSTALLING_PLUGINS} - 自動削除対象のプラグインを削除する。
    6. *
    */ public class PluginAutoRemover extends AbstractInstaller From 063526856511082ffcb014b4d9b0dafd1a7d3f13 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 20:24:43 +0900 Subject: [PATCH 432/745] docs: Create javadoc compiling --- KPMDaemon/pom.xml | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index cb74bff0..862ca715 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -19,6 +19,54 @@ UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + ${java.version} + ${java.version} + + + + org.projectlombok + lombok-maven-plugin + 1.18.20.0 + + src/main/java + false + + + + generate-sources + + delombok + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.4.1 + + true + ${project.basedir}/docs + ${java.version} + protected + ja_JP + KPM Public API Document + UTF-8 + UTF-8 + UTF-8 + target/generated-sources/delombok + + + + + commons-io From 7016fdddbf6cefac17dba3b7f3b1ef399deb8113 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 20:26:32 +0900 Subject: [PATCH 433/745] docs: Fix invalid javadoc (invalid link) --- .../lab/kpm/installer/impls/register/TokenRegisterer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java index 4acb24dc..9caa4e09 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java @@ -34,7 +34,9 @@ * トークン登録は主に以下の流れで動作します。 * *
      - *
    1. {@link RegisterTasks#} - トークン登録対象のプラグインを検索する。
    2. + *
    3. {@link RegisterTasks#REQUESTING_USER_VERIFICATION_CODE} - ユーザ検証コードの要求しています。
    4. + *
    5. {@link RegisterTasks#POLLING_USER_VERIFICATION} - ユーザ検証コードの入力を待機します。
    6. + *
    7. {@link RegisterTasks#REGISTERING_TOKEN} - トークンの登録中です。
    8. *
    */ public class TokenRegisterer extends AbstractInstaller From caeea52dbc23f1735015310f780e31194159a17b Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 29 Oct 2022 20:26:50 +0900 Subject: [PATCH 434/745] refactor: Remove unused method(urlEncodeAndToBytes) --- .../impls/register/TokenRegisterer.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java index 9caa4e09..55b3020b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/TokenRegisterer.java @@ -25,9 +25,6 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; /** * GitHubのトークンを登録するインストーラーの実装です。 @@ -57,22 +54,6 @@ public TokenRegisterer(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager s super(daemon, signalHandler); } - private static byte[] urlEncodeAndToBytes(String str) - { - try - { - return URLEncoder.encode( - str, - StandardCharsets.UTF_8.name() - ).getBytes(StandardCharsets.UTF_8); - } - catch (UnsupportedEncodingException e) - { - // This exception will never be thrown. - throw new RuntimeException(e); - } - } - @Override public InstallResult execute(@NotNull RegisterArgument argument) throws TaskFailedException { From 21460dfcdd7d3c1b7fb323bf5a47a5ba47d13153 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 30 Oct 2022 16:51:02 +0900 Subject: [PATCH 435/745] feat: RecipesUnregisteringHook --- .../hook/hooks/RecipesUnregisteringHook.java | 72 +++++++++++++++++++ .../task/tasks/uninstall/UnInstallTask.java | 39 ++++++++-- .../signals/PluginRegisteredRecipeSignal.java | 10 +-- 3 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/RecipesUnregisteringHook.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/RecipesUnregisteringHook.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/RecipesUnregisteringHook.java new file mode 100644 index 00000000..415c3e58 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/hooks/RecipesUnregisteringHook.java @@ -0,0 +1,72 @@ +package net.kunmc.lab.kpm.hook.hooks; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.kpm.hook.KPMHook; +import org.bukkit.inventory.Recipe; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; + +/** + * プラグインのレシピが削除されるときに呼び出されるフックです。 + */ +public class RecipesUnregisteringHook implements KPMHook +{ + /** + * 削除対象のレシピを検索するときに呼び出されます。 + */ + @Value + @EqualsAndHashCode(callSuper = false) + public static class Searching extends RecipesUnregisteringHook + { + /** + * 削除対象の名前空間です。 + */ + @NotNull + ArrayList targetNamespaces; + + /** + * 名前空間を追加します。 + * + * @param namespace 名前空間 + */ + public void addTarget(@NotNull String namespace) + { + this.targetNamespaces.add(namespace); + } + } + + /** + * レシピが削除される前に呼び出されます。 + */ + @Data + @EqualsAndHashCode(callSuper = false) + public static class Pre extends RecipesUnregisteringHook + { + /** + * 削除対象のレシピです。 + */ + private final Recipe recipe; + + /** + * 削除をキャンセルするかどうかを表します。 + */ + private boolean cancelled; + } + + /** + * レシピが削除された後に呼び出されます。 + */ + @Value + @EqualsAndHashCode(callSuper = false) + public static class Post extends RecipesUnregisteringHook + { + /** + * 削除対象のレシピです。 + */ + @NotNull + Recipe recipe; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java index b5da89aa..afd706f3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java @@ -2,6 +2,7 @@ import net.kunmc.lab.kpm.KPMDaemon; import net.kunmc.lab.kpm.hook.hooks.PluginUninstallHook; +import net.kunmc.lab.kpm.hook.hooks.RecipesUnregisteringHook; import net.kunmc.lab.kpm.installer.AbstractInstaller; import net.kunmc.lab.kpm.installer.task.InstallTask; import net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals.PluginDisablingSignal; @@ -25,13 +26,14 @@ import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.java.PluginClassLoader; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -154,7 +156,7 @@ private UnInstallErrorCause uninstallOnePlugin(@NotNull Plugin plugin) kpmInfo.getHooks().runHook(new PluginUninstallHook.Pre(plugin.getDescription(), kpmInfo, plugin)); this.taskState = UnInstallState.RECIPES_UNREGISTERING; - this.unregisterRecipes(plugin); + this.unregisterRecipes(plugin, kpmInfo); this.taskState = UnInstallState.COMMANDS_UNPATCHING; COMMANDS_PATCHER.unPatchCommand(plugin, false); @@ -226,11 +228,20 @@ private boolean unloadClasses(@NotNull Plugin plugin) return true; } - private void unregisterRecipes(@NotNull Plugin plugin) + private void unregisterRecipes(@NotNull Plugin plugin, @Nullable KPMInformationFile kpmInfo) { - PluginRegisteredRecipeSignal.Searching signal = new PluginRegisteredRecipeSignal.Searching(plugin); + ArrayList targetNamespaces = + new ArrayList<>(Collections.singletonList(plugin.getName().toLowerCase(Locale.ROOT))); + if (kpmInfo != null) + { + RecipesUnregisteringHook.Searching searchingHook = new RecipesUnregisteringHook.Searching(targetNamespaces); + kpmInfo.getHooks().runHook(searchingHook); + targetNamespaces = searchingHook.getTargetNamespaces(); + } + + PluginRegisteredRecipeSignal.Searching signal = + new PluginRegisteredRecipeSignal.Searching(plugin, targetNamespaces.toArray(new String[0])); this.postSignal(signal); - String[] targetNamespaces = signal.getTargetNamespaces(); Iterator recipeIterator = Bukkit.recipeIterator(); while (recipeIterator.hasNext()) @@ -239,13 +250,27 @@ private void unregisterRecipes(@NotNull Plugin plugin) if (this.isRecipeRemoveTarget(plugin, targetNamespaces, recipe)) { + if (kpmInfo != null) + { + RecipesUnregisteringHook.Pre preHook = new RecipesUnregisteringHook.Pre(recipe); + kpmInfo.getHooks().runHook(preHook); + if (preHook.isCancelled()) + continue; + } + this.postSignal(new PluginRegisteredRecipeSignal.Removing(plugin, recipe)); recipeIterator.remove(); + + if (kpmInfo != null) + { + RecipesUnregisteringHook.Post postHook = new RecipesUnregisteringHook.Post(recipe); + kpmInfo.getHooks().runHook(postHook); + } } } } - private boolean isRecipeRemoveTarget(@NotNull Plugin plugin, @NotNull String[] targetNamespaces, @NotNull Recipe recipe) + private boolean isRecipeRemoveTarget(@NotNull Plugin plugin, @NotNull ArrayList targetNamespaces, @NotNull Recipe recipe) { if (!(recipe instanceof Keyed)) return false; @@ -253,7 +278,7 @@ private boolean isRecipeRemoveTarget(@NotNull Plugin plugin, @NotNull String[] t NamespacedKey recipeKey = ((Keyed) recipe).getKey(); String recipeNamespace = recipeKey.getNamespace(); - String foundSignature = Arrays.stream(targetNamespaces).parallel() + String foundSignature = targetNamespaces.stream().parallel() .filter(recipeNamespace::equalsIgnoreCase) .findFirst().orElse(null); boolean isTargetRecipe = foundSignature != null; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java index 1dee0056..cc813e5d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java @@ -8,7 +8,8 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import java.util.Locale; +import java.util.ArrayList; +import java.util.Arrays; /** * プラグインが登録したレシピについてのシグナルです。 @@ -68,13 +69,12 @@ public static class Searching extends PluginRegisteredRecipeSignal * デフォルトでは, プラグインの名前(Lower case)が使用されます。 */ @NotNull - private String[] targetNamespaces; + private ArrayList targetNamespaces; - public Searching(@NotNull Plugin plugin) + public Searching(@NotNull Plugin plugin, @NotNull String... targetNamespaces) { super(plugin); - - this.targetNamespaces = new String[]{plugin.getName().toLowerCase(Locale.ROOT)}; + this.targetNamespaces = (ArrayList) Arrays.asList(targetNamespaces); } } From c4f794e127041410143c6faec6499b7f052fb3b5 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 30 Oct 2022 17:53:18 +0900 Subject: [PATCH 436/745] feat: KPMRecipe hook --- .../task/tasks/uninstall/UnInstallTask.java | 13 +++++++-- .../kunmc/lab/kpm/kpminfo/KPMInfoParser.java | 28 ++++++++++++++++++- .../lab/kpm/kpminfo/KPMInformationFile.java | 8 ++++++ kpm-info.json | 28 +++++++++++++++++-- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java index afd706f3..96d42a89 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/UnInstallTask.java @@ -33,6 +33,7 @@ import java.lang.reflect.Field; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -234,6 +235,8 @@ private void unregisterRecipes(@NotNull Plugin plugin, @Nullable KPMInformationF new ArrayList<>(Collections.singletonList(plugin.getName().toLowerCase(Locale.ROOT))); if (kpmInfo != null) { + targetNamespaces.addAll(Arrays.asList(kpmInfo.getRecipes())); + RecipesUnregisteringHook.Searching searchingHook = new RecipesUnregisteringHook.Searching(targetNamespaces); kpmInfo.getHooks().runHook(searchingHook); targetNamespaces = searchingHook.getTargetNamespaces(); @@ -276,10 +279,16 @@ private boolean isRecipeRemoveTarget(@NotNull Plugin plugin, @NotNull ArrayList< return false; NamespacedKey recipeKey = ((Keyed) recipe).getKey(); - String recipeNamespace = recipeKey.getNamespace(); + String targetNS = recipeKey.getNamespace().toLowerCase(Locale.ROOT); + String targetKey = recipeKey.getKey().toLowerCase(Locale.ROOT); + String targetFullName = targetNS + ":" + targetKey; String foundSignature = targetNamespaces.stream().parallel() - .filter(recipeNamespace::equalsIgnoreCase) + .filter(key -> + key.equalsIgnoreCase(targetNS) + || key.equalsIgnoreCase(targetKey) + || key.equalsIgnoreCase(targetFullName) + ) .findFirst().orElse(null); boolean isTargetRecipe = foundSignature != null; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java index 13a526c9..f3d67c54 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInfoParser.java @@ -62,8 +62,9 @@ private static KPMInformationFile loadFromMap(@NotNull KPMDaemon daemon, Map kpmVersion [required] QueryContext updateQuery = parseUpdateQuery(map); // Parse update => updateQuery [required] HookRecipientList hooks = parseHooks(daemon, map); // Parse hooks [optional] + String[] recipes = parseRecipes(map); // Parse recipes [optional] - return new KPMInformationFile(version, updateQuery, hooks); + return new KPMInformationFile(version, updateQuery, hooks, recipes); } @NotNull @@ -119,4 +120,29 @@ private static HookRecipientList parseHooks(KPMDaemon daemon, Map map) thr return result; } + private static String[] parseRecipes(Map map) throws InvalidInformationFileException + { + if (!map.containsKey("recipes")) + return new String[0]; + + Object recipesObj = map.get("recipes"); + if (!(recipesObj instanceof List)) + throw new InvalidInformationFileException("recipes must be a list of strings."); + + List recipes = (List) recipesObj; + String[] result = new String[recipes.size()]; + + for (int i = 0; i < recipes.size(); i++) + { + Object recipe = recipes.get(i); + if (!(recipe instanceof String)) + throw new InvalidInformationFileException("recipes must be a list of strings."); + + result[i] = recipe.toString(); + } + + return result; + } + + } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java index 1d9b2c17..de8268b2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/kpminfo/KPMInformationFile.java @@ -43,4 +43,12 @@ public class KPMInformationFile */ @NotNull HookRecipientList hooks; + /** + * プラグインが登録したレシピの名前空間または名前空間キーです。 + * これらは、プラグインが登録したレシピを識別し、アンインストール時に正常に削除するために使用されます。 + * + * @serial recipes {@link String} プラグインが登録したレシピの名前空間または名前空間キーです。 + */ + @NotNull + String[] recipes; } diff --git a/kpm-info.json b/kpm-info.json index 561d4178..dbc81fa9 100644 --- a/kpm-info.json +++ b/kpm-info.json @@ -10,12 +10,20 @@ "query": { "type": "string", "pattern": "^(?[^>]+>)?(?[^=]+)(?:==(?.+))?$" + }, + "namespaceORNamespacedKey": { + "type": "string", + "pattern": "^((?[a-z0-9_.-]+)|(?[a-z0-9_.-]+):(?[a-z0-9_.-]+))$" + }, + "namespacedKey": { + "type": "string", + "pattern": "^(?[a-z0-9_.-]+):(?[a-z0-9_.-]+)$" } }, "properties": { "kpm": { "$ref": "#/definitions/version", - "description": "対応するKPMのバージョンです。このバージョンより古いKPMではプラグインを読み込めません。", + "description": "対応するKPMのバージョンです.\nこのバージョンより古いKPMではプラグインを読み込めません. ", "examples": [ "3.0.0", "v3.0-pre1" @@ -23,7 +31,7 @@ }, "update": { "$ref": "#/definitions/query", - "description": "プラグインを自動更新する時に使用するクエリです。(この機能は将来的に実装される予定です。)", + "description": "プラグインを自動更新する時に使用するクエリです. (この機能は将来的に実装される予定です)", "examples": [ "TeamKUN/DaredemoOpPlugin", "bukkit>daredemo-op-plugin" @@ -31,7 +39,7 @@ }, "hooks": { "type": "array", - "description": "KPMフックを受け取るクラスの一覧です。KPMフックを受け取るには, このフィールドに KPMHookRecipient を実装したクラスのフルパスを指定します。また, KPMフックを受け取るクラスは, 1つのKPMDaemonのみを引数にとるコンストラクタを持つ必要があります。", + "description": "KPMフックを受け取るクラスの一覧です.\nKPMフックを受け取るには, このフィールドに KPMHookRecipient を実装したクラスのフルパスを指定します. \nまた, KPMフックを受け取るクラスは, 1つのKPMDaemonのみを引数にとるコンストラクタを持つ必要があります. ", "items": { "type": "string", "examples": [ @@ -41,6 +49,20 @@ }, "minItems": 1, "uniqueItems": true + }, + "recipes": { + "type": "array", + "description": "プラグインが登録したレシピの名前空間または名前空間付きキーのリストです.\nこのフィールドに指定された名前空間/キーはアンインストール時にサーバから削除されます.\nまた, プラグイン名の名前空間は自動で追加されるため指定する必要はありません.", + "items": { + "$ref": "#/definitions/namespaceORNamespacedKey", + "examples": [ + "examplenamespace", + "examplerecipename", + "bukkit:examplecustomrecipe1" + ] + }, + "minItems": 1, + "uniqueItems": true } }, "required": [ From a9c3f7dd15cd83e14ce1ba3b1d829d4fafc74d77 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 30 Oct 2022 18:37:20 +0900 Subject: [PATCH 437/745] feat: Handling onEnable() errors --- .../tasks/install/PluginsInstallTask.java | 25 ++++++++++++++++++- .../install/signals/PluginEnablingSignal.java | 18 +++++++++++++ .../kunmc/lab/kpm/loader/CommandsPatcher.java | 12 +++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java index 2d858427..52cb3880 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java @@ -20,8 +20,11 @@ import net.kunmc.lab.kpm.utils.versioning.Version; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.Plugin; @@ -194,7 +197,27 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr this.pluginMetaManager.preparePluginModify(target); this.state = PluginsInstallState.PLUGIN_ENABLING; this.postSignal(new PluginEnablingSignal.Pre(target)); - PLUGIN_MANAGER.enablePlugin(target); + if (!PLUGIN_MANAGER.isPluginEnabled(target)) + { + List commands = PluginCommandYamlParser.parse(target); + + if (!commands.isEmpty()) + COMMANDS_PATCHER.registerAll(target.getDescription().getName(), commands); + + try + { + target.getPluginLoader().enablePlugin(target); + } + catch (Throwable e) + { + e.printStackTrace(); + this.postSignal(new PluginEnablingSignal.Error(target, e)); + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.EXCEPTION_OCCURRED); + } + + HandlerList.bakeAll(); + } + this.postSignal(new PluginEnablingSignal.Post(target)); installedPlugins.add(target); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java index afbe2885..a197e2ab 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java @@ -30,6 +30,24 @@ public Pre(@NotNull Plugin plugin) } } + /** + * 有効化中にエラーが発生した場合に送信されるシグナルです。 + */ + public static class Error extends PluginEnablingSignal + { + /** + * エラーの原因です。 + */ + @NotNull + private final Throwable cause; + + public Error(@NotNull Plugin plugin, @NotNull Throwable cause) + { + super(plugin); + this.cause = cause; + } + } + /** * 有効化を行った後に送信されるシグナルです。 */ diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/CommandsPatcher.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/CommandsPatcher.java index f9d5d1a0..7a0df693 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/CommandsPatcher.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/loader/CommandsPatcher.java @@ -16,6 +16,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.List; import java.util.Map; /** @@ -310,4 +311,15 @@ public void unPatchCommand(@NotNull Plugin plugin) { this.unPatchCommand(plugin, true); } + + /** + * コマンドをすべて登録します。 + * + * @param fallbackPrefix フォールバックのプレフィックス + * @param commands コマンド + */ + public void registerAll(String fallbackPrefix, List commands) + { + this.getCommandMap().registerAll(fallbackPrefix, commands); + } } From f24993386d69f791209219a5fca835adbcf61eb1 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 30 Oct 2022 18:42:52 +0900 Subject: [PATCH 438/745] fix: Unused plugin meta removing --- KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java | 2 +- .../java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java | 3 +++ .../java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 57060b1a..26c65673 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -178,7 +178,7 @@ private void setupDependencyTree() if (pluginNames.contains(meta.getName().toLowerCase())) continue; - this.logger.log(Level.INFO, "Found plugin meta: {0}", meta.getName()); + this.logger.log(Level.INFO, "Found unused plugin meta: {0}", meta.getName()); iterator.remove(); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java index b3bbe6cc..8edb0f03 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaIterator.java @@ -89,7 +89,10 @@ public void close() this.results.close(); for (String name : this.removeTargets) + { + this.provider.removePluginMeta(name, this.transaction); this.provider.removePluginRelationalData(this.transaction.getConnection(), name); + } } catch (SQLException e) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java index 90e80e92..4234336a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaProvider.java @@ -401,6 +401,14 @@ public void removePluginMeta(@NotNull String pluginName) .executeUpdate(); } + void removePluginMeta(String pluginName, Transaction transaction) + { + transaction.renew("DELETE FROM plugin_meta WHERE name = ?") + .set(1, pluginName) + .beforeCommit(tr -> this.removePluginRelationalData(tr.getConnection(), pluginName)) + .executeUpdate(false); + } + void removePluginRelationalData(Connection connection, String pluginName) throws SQLException { PreparedStatement statement = From 084b6d205ef5772dbc952b21f858733ad548e648 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 30 Oct 2022 18:46:28 +0900 Subject: [PATCH 439/745] fix: Invalid exception handling --- .../tasks/install/PluginsInstallTask.java | 25 +++---------------- .../install/signals/PluginEnablingSignal.java | 13 +++------- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java index 52cb3880..b445e433 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java @@ -20,11 +20,8 @@ import net.kunmc.lab.kpm.utils.versioning.Version; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.Plugin; @@ -197,25 +194,11 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr this.pluginMetaManager.preparePluginModify(target); this.state = PluginsInstallState.PLUGIN_ENABLING; this.postSignal(new PluginEnablingSignal.Pre(target)); - if (!PLUGIN_MANAGER.isPluginEnabled(target)) + PLUGIN_MANAGER.enablePlugin(target); + if (!target.isEnabled()) { - List commands = PluginCommandYamlParser.parse(target); - - if (!commands.isEmpty()) - COMMANDS_PATCHER.registerAll(target.getDescription().getName(), commands); - - try - { - target.getPluginLoader().enablePlugin(target); - } - catch (Throwable e) - { - e.printStackTrace(); - this.postSignal(new PluginEnablingSignal.Error(target, e)); - return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.EXCEPTION_OCCURRED); - } - - HandlerList.bakeAll(); + this.postSignal(new PluginEnablingSignal.Failed(target)); + return new PluginsInstallResult(false, this.state, PluginsInstallErrorCause.EXCEPTION_OCCURRED); } this.postSignal(new PluginEnablingSignal.Post(target)); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java index a197e2ab..cefe0ed3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java @@ -31,20 +31,13 @@ public Pre(@NotNull Plugin plugin) } /** - * 有効化中にエラーが発生した場合に送信されるシグナルです。 + * 有効化中に失敗した場合に送信されるシグナルです。 */ - public static class Error extends PluginEnablingSignal + public static class Failed extends PluginEnablingSignal { - /** - * エラーの原因です。 - */ - @NotNull - private final Throwable cause; - - public Error(@NotNull Plugin plugin, @NotNull Throwable cause) + public Failed(@NotNull Plugin plugin) { super(plugin); - this.cause = cause; } } From 531b293c67ce78626f2c7ac8f1ebab0925b758d7 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 14:38:34 +0900 Subject: [PATCH 440/745] fix: Install progresses as async --- .../lab/kpm/installer/task/InstallTask.java | 83 +++++++++++++++++++ .../tasks/install/PluginsInstallTask.java | 19 +++-- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/InstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/InstallTask.java index 7f1a3b21..1f42ce35 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/InstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/InstallTask.java @@ -4,8 +4,14 @@ import net.kunmc.lab.kpm.installer.InstallProgress; import net.kunmc.lab.kpm.signal.Signal; import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import org.jetbrains.annotations.NotNull; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; + /** * インストールに使用するタスクの基底クラスです。 * @@ -38,4 +44,81 @@ protected void postSignal(@NotNull Signal signal) { this.signalHandler.handleSignal(this.progress, signal); } + + protected void runSyncThrowing(@NotNull ThrowingRunnable runnable) throws Exception + { + CyclicBarrier barrier = new CyclicBarrier(2); + + AtomicReference errorRef = new AtomicReference<>(); + Runner.run(() -> { + runnable.run(); + barrier.await(); + }, (e, task) -> { + errorRef.set(e); + try + { + barrier.await(); + } + catch (InterruptedException | BrokenBarrierException ex) + { + throw new RuntimeException(ex); + } + }); + + try + { + barrier.await(); + } + catch (BrokenBarrierException | InterruptedException e) + { + throw new RuntimeException(e); + } + + if (errorRef.get() != null) + throw errorRef.get(); + } + + protected T runSyncThrowing(@NotNull ThrowingSupplier supplier) throws Exception + { + AtomicReference resultRef = new AtomicReference<>(); + this.runSyncThrowing(() -> resultRef.set(supplier.get())); + + return resultRef.get(); + } + + protected void runSync(@NotNull Runnable runnable) + { + try + { + this.runSyncThrowing(runnable::run); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + protected T runSync(@NotNull Supplier supplier) + { + try + { + return this.runSyncThrowing(supplier::get); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + @FunctionalInterface + protected interface ThrowingSupplier + { + T get() throws Exception; + } + + @FunctionalInterface + protected interface ThrowingRunnable + { + void run() throws Exception; + } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java index b445e433..6e51d9e1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/PluginsInstallTask.java @@ -161,8 +161,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr // Load plugin this.state = PluginsInstallState.PLUGIN_LOADING; this.postSignal(new PluginLoadSignal.Pre(path, pluginDescription)); - target = PLUGIN_MANAGER.loadPlugin(targetPath.toFile()); - assert target != null; + target = this.runSyncThrowing(() -> PLUGIN_MANAGER.loadPlugin(targetPath.toFile())); this.postSignal(new PluginLoadSignal.Post(path, pluginDescription, target)); this.progress.addPending(target.getName()); @@ -170,7 +169,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr // Run Plugin#onLoad this.state = PluginsInstallState.ONLOAD_RUNNING; this.postSignal(new PluginOnLoadRunningSignal.Pre(target)); - target.onLoad(); + this.runSyncThrowing(target::onLoad); this.postSignal(new PluginOnLoadRunningSignal.Post(target)); } @@ -194,7 +193,7 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr this.pluginMetaManager.preparePluginModify(target); this.state = PluginsInstallState.PLUGIN_ENABLING; this.postSignal(new PluginEnablingSignal.Pre(target)); - PLUGIN_MANAGER.enablePlugin(target); + this.runSync(() -> PLUGIN_MANAGER.enablePlugin(target)); if (!target.isEnabled()) { this.postSignal(new PluginEnablingSignal.Failed(target)); @@ -213,11 +212,13 @@ private PluginsInstallResult installOne(@NotNull Path path, @NotNull PluginDescr ); if (kpmInformationFile != null) - kpmInformationFile.getHooks().runHook(new PluginInstalledHook( - operator, - isDependency, - query - )); + this.runSync(() -> + kpmInformationFile.getHooks().runHook(new PluginInstalledHook( + operator, + isDependency, + query + )) + ); return new PluginsInstallResult(true, this.state, null, null, target, installedPlugins); } From 08f3ef21f2ae8b0ab56a3c6bc3aa533f06deb00a Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 14:40:06 +0900 Subject: [PATCH 441/745] fix: Arrays.asList's fault --- .../tasks/uninstall/signals/PluginRegisteredRecipeSignal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java index cc813e5d..7524fa47 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java @@ -74,7 +74,7 @@ public static class Searching extends PluginRegisteredRecipeSignal public Searching(@NotNull Plugin plugin, @NotNull String... targetNamespaces) { super(plugin); - this.targetNamespaces = (ArrayList) Arrays.asList(targetNamespaces); + this.targetNamespaces = new ArrayList<>(Arrays.asList(targetNamespaces)); } } From 39ae09f2bb17c14a8a57618f644feb1422446ae7 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 14:51:36 +0900 Subject: [PATCH 442/745] fix: Hook clearing --- .../src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java index 38ae43a8..1e99c806 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java @@ -98,5 +98,7 @@ public void bakeHooks(@NotNull KPMDaemon daemon) throws InvalidInformationFileEx " a single parameter of type KPMDaemon: " + className, e); } } + + this.reservedHookClasses.clear(); } } From 32a4e1e07ebd43c5a58a82b573660ad90ccef326 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 14:55:32 +0900 Subject: [PATCH 443/745] fix: Duplicate hook registering --- .../net/kunmc/lab/kpm/hook/HookRecipientList.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java index 1e99c806..36d8ff02 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/hook/HookRecipientList.java @@ -8,6 +8,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.logging.Level; @@ -67,8 +68,11 @@ public void add(@NotNull String className) */ public void bakeHooks(@NotNull KPMDaemon daemon) throws InvalidInformationFileException { - for (String className : this.reservedHookClasses) + Iterator iterator = this.reservedHookClasses.iterator(); + while (iterator.hasNext()) { + String className = iterator.next(); + try { this.daemon.getLogger().setLevel(Level.OFF); @@ -97,8 +101,12 @@ public void bakeHooks(@NotNull KPMDaemon daemon) throws InvalidInformationFileEx throw new InvalidInformationFileException("Hook recipient class must have a constructor with" + " a single parameter of type KPMDaemon: " + className, e); } - } + finally + { + this.daemon.getLogger().setLevel(Level.INFO); - this.reservedHookClasses.clear(); + iterator.remove(); + } + } } } From eb8883d3c5ec54d05830cc03359592532f461c8d Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 14:58:29 +0900 Subject: [PATCH 444/745] fix: Recipe remove spamming --- .../handlers/uninstall/UninstallerSignalHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallerSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallerSignalHandler.java index 49f4a092..95192f70 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallerSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/uninstall/UninstallerSignalHandler.java @@ -13,10 +13,12 @@ public class UninstallerSignalHandler { private final Terminal terminal; + private boolean oneRecipeRemoved; public UninstallerSignalHandler(Terminal terminal) { this.terminal = terminal; + this.oneRecipeRemoved = false; } private static String getErrorCauseMessage(PluginUninstallErrorSignal signal) @@ -41,7 +43,11 @@ public void onPluginUninstall(PluginUninstallingSignal signal) @SignalHandler public void onRecipeRemove(PluginRegisteredRecipeSignal.Removing signal) { - this.terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " のレシピを削除しています ..."); + if (!this.oneRecipeRemoved) + { + this.terminal.writeLine(ChatColor.RED + PluginUtil.getPluginString(signal.getPlugin()) + " のレシピを削除しています ..."); + this.oneRecipeRemoved = true; + } } @SignalHandler From a4fd6ba850e85f8c1663fa6fb70a3196e5964c25 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 15:06:25 +0900 Subject: [PATCH 445/745] fix: Missing success handler --- .../lab/kpm/installer/impls/uninstall/PluginUninstaller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index fd09cfa7..41b43d2e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -155,7 +155,7 @@ public InstallResult execute(@NotNull UninstallArgument argument .submitAll(new DependsComputeOrderArgument(computeOrderTarget)); // endregion - return new PluginUninstallSucceedResult(this.progress, uninstallResult); + return this.success(new PluginUninstallSucceedResult(this.progress, uninstallResult)); } private Plugin getPlugin(String query) From 03aa2f71aa6fe8bf3bae0209fffdffee27f59415 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 15:13:45 +0900 Subject: [PATCH 446/745] refactor: Migrate plugin modify log to logger --- .../java/net/kunmc/lab/kpm/KPMDaemon.java | 2 +- .../kunmc/lab/kpm/meta/PluginMetaManager.java | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 26c65673..5f9391c9 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -105,7 +105,7 @@ public KPMDaemon(@NotNull KPMEnvironment env) { this.envs = env; this.logger = env.getLogger(); - this.pluginMetaManager = new PluginMetaManager(env.getPlugin(), env.getMetadataDBPath()); + this.pluginMetaManager = new PluginMetaManager(this, env); this.kpmInfoManager = new KPMInfoManager(this); this.tokenStore = new TokenStore(env.getTokenPath(), env.getTokenKeyPath()); this.pluginResolver = new PluginResolver(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java index 1bac8cf4..bfab6ccd 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java @@ -1,6 +1,8 @@ package net.kunmc.lab.kpm.meta; import lombok.Getter; +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.KPMEnvironment; import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import org.bukkit.Bukkit; @@ -12,7 +14,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -21,6 +22,7 @@ */ public class PluginMetaManager implements Listener { + private final KPMDaemon daemon; /** * メタデータを提供するプロバイダです。 */ @@ -28,14 +30,15 @@ public class PluginMetaManager implements Listener private final PluginMetaProvider provider; private final List exceptedPluginModifications; - public PluginMetaManager(@NotNull Plugin plugin, @NotNull Path databasePath) + public PluginMetaManager(@NotNull KPMDaemon daemon, @NotNull KPMEnvironment env) { - this.provider = new PluginMetaProvider(plugin, databasePath); + this.daemon = daemon; + this.provider = new PluginMetaProvider(env.getPlugin(), env.getMetadataDBPath()); this.exceptedPluginModifications = new ArrayList<>(); // Below lambda will be executed after all plugins are loaded. // (Bukkit runs task after all plugins are loaded.) - Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, plugin), 1L); + Runner.runLater(() -> Bukkit.getPluginManager().registerEvents(this, env.getPlugin()), 1L); } /** @@ -71,12 +74,12 @@ public void onPluginEnable(PluginEnableEvent event) String pluginNameFull = PluginUtil.getPluginString(plugin); - System.out.println("プラグインの追加が検出されました: " + pluginNameFull); + this.daemon.getLogger().info("プラグインの追加が検出されました: " + pluginNameFull); - System.out.println("プラグインのメタデータを作成してします ..."); + this.daemon.getLogger().info("プラグインのメタデータを作成しています ..."); this.onInstalled(plugin, InstallOperator.UNKNOWN, null, false); - System.out.println("依存関係ツリーを構築しています ..."); + this.daemon.getLogger().info("依存関係ツリーを構築しています ..."); this.provider.buildDependencyTree(plugin); } @@ -94,12 +97,12 @@ public void onDisable(PluginDisableEvent event) String pluginNameFull = PluginUtil.getPluginString(plugin); - System.out.println("プラグインの削除が検出されました: " + pluginNameFull); + this.daemon.getLogger().info("プラグインの削除が検出されました: " + pluginNameFull); - System.out.println("プラグインのメタデータを削除しています ..."); + this.daemon.getLogger().info("プラグインのメタデータを削除しています ..."); this.onUninstalled(pluginNameFull); - System.out.println("依存関係ツリーを構築しています ..."); + this.daemon.getLogger().info("依存関係ツリーを構築しています ..."); this.provider.deleteFromDependencyTree(pluginNameFull); } From cf43554402d7ef18ba34bfc47f66999eb2022639 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 15:58:23 +0900 Subject: [PATCH 447/745] fix: invalid exclusion control --- .../net/kunmc/lab/kpm/meta/PluginMetaManager.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java index bfab6ccd..02d1524c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java @@ -49,7 +49,11 @@ public PluginMetaManager(@NotNull KPMDaemon daemon, @NotNull KPMEnvironment env) */ public void preparePluginModify(@NotNull String pluginName) { - this.exceptedPluginModifications.add(pluginName); + synchronized (this.exceptedPluginModifications) + { + if (!this.exceptedPluginModifications.contains(pluginName)) + this.exceptedPluginModifications.add(pluginName); + } } /** @@ -171,13 +175,9 @@ public boolean hasPluginMeta(@NotNull Plugin plugin) private boolean checkNoAutoCreateMetadata(Plugin plugin) { - String pluginName = plugin.getName(); - if (this.exceptedPluginModifications.contains(pluginName)) + synchronized (this.exceptedPluginModifications) { - this.exceptedPluginModifications.remove(pluginName); - return true; + return this.exceptedPluginModifications.remove(plugin.getName()); } - - return false; } } From 9f5b5621beb3e16ccb276ea22b39d9efa744dd76 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 31 Oct 2022 16:36:11 +0900 Subject: [PATCH 448/745] feat: ServerConditionChecker --- .../java/net/kunmc/lab/kpm/KPMDaemon.java | 8 ++ .../kunmc/lab/kpm/meta/PluginMetaManager.java | 4 +- .../net/kunmc/lab/kpm/utils/PluginUtil.java | 22 +----- .../lab/kpm/utils/ServerConditionChecker.java | 78 +++++++++++++++++++ 4 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ServerConditionChecker.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 5f9391c9..ea008725 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -20,6 +20,7 @@ import net.kunmc.lab.kpm.resolver.impl.OmittedGitHubResolver; import net.kunmc.lab.kpm.resolver.impl.RawURLResolver; import net.kunmc.lab.kpm.resolver.impl.SpigotMCResolver; +import net.kunmc.lab.kpm.utils.ServerConditionChecker; import net.kunmc.lab.kpm.utils.http.Requests; import net.kunmc.lab.kpm.utils.versioning.Version; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; @@ -97,6 +98,12 @@ public class KPMDaemon @NotNull private final HookExecutor hookExecutor; + /** + * サーバの状態を判定するクラスです。 + */ + @NotNull + private final ServerConditionChecker serverConditionChecker; + { INSTANCE = this; } @@ -113,6 +120,7 @@ public KPMDaemon(@NotNull KPMEnvironment env) this.pluginLoader = new PluginLoader(this); this.installManager = new InstallManager(this); this.hookExecutor = new HookExecutor(this); + this.serverConditionChecker = new ServerConditionChecker(this); this.setupDaemon(env.getOrganizations()); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java index 02d1524c..2b8a93f8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMetaManager.java @@ -4,6 +4,7 @@ import net.kunmc.lab.kpm.KPMDaemon; import net.kunmc.lab.kpm.KPMEnvironment; import net.kunmc.lab.kpm.utils.PluginUtil; +import net.kunmc.lab.kpm.utils.ServerConditionChecker; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; @@ -91,7 +92,8 @@ public void onPluginEnable(PluginEnableEvent event) @EventHandler public void onDisable(PluginDisableEvent event) { - if (!PluginUtil.isServerRunning()) + ServerConditionChecker conditions = this.daemon.getServerConditionChecker(); + if (conditions.isStopping() || conditions.isReloading()) return; // The server is being stopped. Plugin plugin = event.getPlugin(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/PluginUtil.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/PluginUtil.java index 22562e4d..7415ac13 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/PluginUtil.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/PluginUtil.java @@ -26,22 +26,14 @@ public class PluginUtil { private static final Method pluginGetFile; - private static final Field fIsRunning; // Lnet/minecraft/server//MinecraftServer; -> isRunning:Z - private static final Object oMinecraftServer; // Lnet/minecraft/server//MinecraftServer; -> Lnet/minecraft/server//DedicatedServer; - static { try { pluginGetFile = ReflectionUtils.getAccessibleMethod(JavaPlugin.class, "getFile"); pluginGetFile.setAccessible(true); - - Class cMinecraftServer = ReflectionUtils.PackageType.MINECRAFT_SERVER.getClass("MinecraftServer"); - fIsRunning = ReflectionUtils.getAccessibleField(cMinecraftServer, true, "isRunning"); - - oMinecraftServer = ReflectionUtils.getValue(Bukkit.getServer(), true, "console"); } - catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) + catch (NoSuchMethodException e) { throw new RuntimeException(e); } @@ -164,16 +156,4 @@ public static PluginDescriptionFile loadDescription(File file) throws InvalidDes return desc; } - public static boolean isServerRunning() - { - try - { - return fIsRunning.getBoolean(oMinecraftServer); - } - catch (IllegalAccessException e) - { - e.printStackTrace(); - return false; - } - } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ServerConditionChecker.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ServerConditionChecker.java new file mode 100644 index 00000000..bb974ff0 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ServerConditionChecker.java @@ -0,0 +1,78 @@ +package net.kunmc.lab.kpm.utils; + +import net.kunmc.lab.kpm.KPMDaemon; +import org.bukkit.Bukkit; + +import java.lang.reflect.Field; + +/** + * サーバの状態を判定するクラスです。 + */ +public class ServerConditionChecker +{ + private static final Field fReloadCount; // Lorg/craftbukkit//CraftServer; -> reloadCount:I + private static final Field fIsRunning; // Lnet/minecraft/server//MinecraftServer; -> isRunning:Z + private static final Object oMinecraftServer; // Lnet/minecraft/server//MinecraftServer; -> Lnet/minecraft/server//DedicatedServer; + + + static + { + try + { + Class cCraftServer = ReflectionUtils.PackageType.CRAFTBUKKIT.getClass("CraftServer"); + fReloadCount = ReflectionUtils.getAccessibleField(cCraftServer, true, "reloadCount"); + Class cMinecraftServer = ReflectionUtils.PackageType.MINECRAFT_SERVER.getClass("MinecraftServer"); + fIsRunning = ReflectionUtils.getAccessibleField(cMinecraftServer, true, "isRunning"); + oMinecraftServer = ReflectionUtils.getValue(Bukkit.getServer(), true, "console"); + } + catch (NoSuchFieldException | ClassNotFoundException | IllegalAccessException e) + { + throw new RuntimeException(e); + } + } + + private final long currentSessionReloadCount; + + public ServerConditionChecker(KPMDaemon daemon) + { + try + { + this.currentSessionReloadCount = fReloadCount.getLong(Bukkit.getServer()); + } + catch (IllegalAccessException e) + { + daemon.getLogger().warning("Failed to initialize ServerReloadDetector."); + throw new RuntimeException(e); + } + } + + public boolean isStopping() + { + try + { + return fIsRunning.getBoolean(oMinecraftServer); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + return false; + } + } + + /** + * サーバがリロード中かどうかを返します。 + * + * @return サーバがリロード中かどうか + */ + public boolean isReloading() + { + try + { + return fReloadCount.getLong(Bukkit.getServer()) != this.currentSessionReloadCount; + } + catch (IllegalAccessException e) + { + throw new RuntimeException(e); + } + } +} From f50e7e84982b8cec0db968c95ce8d2d829dfa35a Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 2 Nov 2022 17:41:25 +0900 Subject: [PATCH 449/745] perf: Reduce commons io dependency --- KPMDaemon/pom.xml | 6 ------ .../java/net/kunmc/lab/kpm/installer/InstallProgress.java | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index 862ca715..fcf7da1f 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -68,12 +68,6 @@ - - commons-io - commons-io - 2.11.0 - compile - com.zaxxer HikariCP diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallProgress.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallProgress.java index 7278c477..a87f7049 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallProgress.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/InstallProgress.java @@ -8,7 +8,7 @@ import net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.DependsCollectStatus; import net.kunmc.lab.kpm.signal.Signal; import net.kunmc.lab.kpm.signal.SignalHandleManager; -import org.apache.commons.io.FileUtils; +import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; From 91324581fc0513eedac43f4eb63e8e3ae84ba2a1 Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 2 Nov 2022 20:32:09 +0900 Subject: [PATCH 450/745] refactor: Reduce peyangpaperutils --- KPMDaemon/pom.xml | 32 +++++++++++++++++++++++++ KPMPlugin/pom.xml | 12 ++++++++++ KPMPlugin/src/main/resources/plugin.yml | 2 -- pom.xml | 7 +----- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/KPMDaemon/pom.xml b/KPMDaemon/pom.xml index fcf7da1f..40212f1a 100644 --- a/KPMDaemon/pom.xml +++ b/KPMDaemon/pom.xml @@ -64,6 +64,32 @@ target/generated-sources/delombok
    + + org.apache.maven.plugins + maven-shade-plugin + 3.3.0 + + + package + + shade + + + + + com.zaxxer.hikari + net.kunmc.lab.kpm.hikari + + + + + org.slf4j:* + + + + + + @@ -74,5 +100,11 @@ 4.0.3 compile + + com.github.TeamKUN + PeyangPaperUtils + ${pyglib.version} + compile + diff --git a/KPMPlugin/pom.xml b/KPMPlugin/pom.xml index 25993302..087f105f 100644 --- a/KPMPlugin/pom.xml +++ b/KPMPlugin/pom.xml @@ -48,6 +48,12 @@ true + + + net.kunmc.lab.peyangpaperutils + net.kunmc.lab.kpm.pyglib + + org.slf4j:* @@ -91,5 +97,11 @@ 3.0.0-pre6 compile + + com.github.TeamKUN + PeyangPaperUtils + ${pyglib.version} + provided + diff --git a/KPMPlugin/src/main/resources/plugin.yml b/KPMPlugin/src/main/resources/plugin.yml index c878b1e8..02c19468 100644 --- a/KPMPlugin/src/main/resources/plugin.yml +++ b/KPMPlugin/src/main/resources/plugin.yml @@ -6,8 +6,6 @@ api-version: 1.16 description: Manage your plugin! website: https://kunmc.net/ -softdepend: [PeyangPaperUtils] - commands: kunpluginmanager: aliases: [pm, kpm, kunpm, kunmgmt] #devicemgmt.mscへの恨み diff --git a/pom.xml b/pom.xml index 1b38edc9..590a4e43 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ 1.8 UTF-8 + 1.0.12 https://kunmc.net/ @@ -72,11 +73,5 @@ 5.9.0 test - - com.github.TeamKUN - PeyangPaperUtils - 1.0.12 - compile - From 89dda0573a7698f202c8775655e72e968297a9bc Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 11 Nov 2022 23:10:29 +0900 Subject: [PATCH 451/745] chore(deps): Bump PeyangPaperUtils to v2.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 590a4e43..bef5b4e9 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 1.8 UTF-8 - 1.0.12 + 2.0.0 https://kunmc.net/ From 44070a9ff9a422ac2b221f4ac0713ec65a460bf9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 11 Nov 2022 23:10:48 +0900 Subject: [PATCH 452/745] refactor: Apply new PeyangPaperUtils features --- .../alias/source/download/SourceDownloadResult.java | 2 +- .../alias/source/download/SourceDownloadTask.java | 2 +- .../task/tasks/alias/update/UpdateAliasesArgument.java | 2 +- .../task/tasks/alias/update/UpdateAliasesTask.java | 2 +- .../dependencies/collector/DependsCollectTask.java | 2 +- .../src/main/java/net/kunmc/lab/kpm/utils/Pair.java | 10 ---------- .../java/net/kunmc/lab/kpm/TeamKunPluginManager.java | 3 +++ 7 files changed, 8 insertions(+), 15 deletions(-) delete mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/Pair.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadResult.java index 7b70c000..d3e4e3c6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadResult.java @@ -3,7 +3,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.task.TaskResult; -import net.kunmc.lab.kpm.utils.Pair; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadTask.java index 22d8b219..fd19c49e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/SourceDownloadTask.java @@ -9,7 +9,7 @@ import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadResult; import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadTask; import net.kunmc.lab.kpm.signal.SignalHandleManager; -import net.kunmc.lab.kpm.utils.Pair; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import org.jetbrains.annotations.NotNull; import java.net.MalformedURLException; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesArgument.java index 852a947d..1706c882 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesArgument.java @@ -3,7 +3,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.task.TaskArgument; -import net.kunmc.lab.kpm.utils.Pair; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import java.net.URL; import java.nio.file.Path; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesTask.java index 052de20d..cbc58d5e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/UpdateAliasesTask.java @@ -10,7 +10,7 @@ import net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals.AliasUpdateSignal; import net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals.InvalidSourceSignal; import net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals.SourcePreparedSignal; -import net.kunmc.lab.kpm.utils.Pair; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import org.jetbrains.annotations.NotNull; import java.io.BufferedReader; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectTask.java index ba235569..9e120639 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/DependsCollectTask.java @@ -23,8 +23,8 @@ import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; import net.kunmc.lab.kpm.resolver.result.ResolveResult; import net.kunmc.lab.kpm.resolver.result.SuccessResult; -import net.kunmc.lab.kpm.utils.Pair; import net.kunmc.lab.kpm.utils.PluginUtil; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/Pair.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/Pair.java deleted file mode 100644 index 58b1fb00..00000000 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/Pair.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.kunmc.lab.kpm.utils; - -import lombok.Value; - -@Value -public class Pair -{ - L left; - R right; -} diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java index 6a71acef..2f69d030 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java @@ -12,6 +12,7 @@ import net.kunmc.lab.kpm.commands.CommandStatus; import net.kunmc.lab.kpm.commands.CommandUninstall; import net.kunmc.lab.kpm.commands.CommandUpdate; +import net.kunmc.lab.peyangpaperutils.PeyangPaperUtils; import net.kunmc.lab.peyangpaperutils.lib.command.CommandManager; import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import org.bukkit.configuration.file.FileConfiguration; @@ -52,6 +53,7 @@ public void registerCommands(CommandManager commandManager) @Override public void onDisable() { + PeyangPaperUtils.dispose(); this.daemon.shutdown(); } @@ -72,6 +74,7 @@ private HashMap setupSources() @Override public void onEnable() { + PeyangPaperUtils.init(this); this.saveDefaultConfig(); plugin = this; this.pluginConfig = this.getConfig(); From 6a50befa25759709424a9323dd22839c6eee3e65 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 11 Nov 2022 23:14:08 +0900 Subject: [PATCH 453/745] feat: Auto exclude bStats from cleaner --- .../kunmc/lab/kpm/installer/impls/clean/CleanArgument.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanArgument.java index 0be2e863..8f3e64ea 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/CleanArgument.java @@ -21,14 +21,15 @@ public class CleanArgument extends AbstractInstallerArgument @NotNull private final List excludeDataNames; - private CleanArgument(@NotNull List excludeDataNames) + public CleanArgument(List excludeDataNames) { - this.excludeDataNames = excludeDataNames; + this.excludeDataNames = new ArrayList<>(excludeDataNames); } public CleanArgument() { - this(new ArrayList<>()); + this.excludeDataNames = new ArrayList<>(); + this.excludeDataNames.add("bStats"); } /** From 25646b0bb2369535c68a60b5f172e9fa677cd725 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 12 Nov 2022 15:36:51 +0900 Subject: [PATCH 454/745] fix: Pickup invalid resolver while url is null --- .../main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java index c7fcdaa3..3cb8f17b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java @@ -141,8 +141,11 @@ private ResolveResult actuallyResolve(BaseResolver resolver, QueryContext queryC { if (resolver instanceof URLResolver) { + if (url == null) + return null; + URLResolver urlResolver = (URLResolver) resolver; - if (url != null && !isValidURLResolver(url, urlResolver)) + if (!isValidURLResolver(url, urlResolver)) return null; } else if (!resolver.isValidResolver(queryContext)) From fe02d2cd42bb1b6e44782c708fd92059bd0f25fc Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 12 Nov 2022 17:41:33 +0900 Subject: [PATCH 455/745] refactor: AutoRemove to singular --- .../impls/autoremove/AutoRemoveArgument.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveArgument.java index cc277fd9..06054f9b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/AutoRemoveArgument.java @@ -1,7 +1,9 @@ package net.kunmc.lab.kpm.installer.impls.autoremove; +import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Singular; import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -14,12 +16,14 @@ */ @Data @EqualsAndHashCode(callSuper = true) +@Builder public class AutoRemoveArgument extends AbstractInstallerArgument { /** * 自動削除から除外するプラグインのリストです。 */ @NotNull + @Singular("exclude") private final List excludePlugins; private AutoRemoveArgument(@NotNull List excludePlugins) @@ -32,18 +36,6 @@ public AutoRemoveArgument() this(new ArrayList<>()); } - /** - * 除外するプラグインを追加します。 - * - * @param pluginName 除外するプラグインの名前 - * @return このインスタンス - */ - public AutoRemoveArgument addExcludePlugin(@NotNull String pluginName) - { - this.excludePlugins.add(pluginName); - return this; - } - /** * 除外するプラグインを追加します。 * @@ -52,7 +44,7 @@ public AutoRemoveArgument addExcludePlugin(@NotNull String pluginName) */ public AutoRemoveArgument addExcludePlugin(@NotNull Plugin plugin) { - this.addExcludePlugin(plugin.getName()); + this.excludePlugins.add(plugin.getName()); return this; } From f1ee007da5125457ef6beade42c3b60c3d99737b Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 13 Nov 2022 18:06:49 +0900 Subject: [PATCH 456/745] feat(daemon): Prerelease support --- .../kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java | 8 +++++++- .../kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java index ced70e1d..4a185389 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubSuccessResult.java @@ -46,7 +46,12 @@ public class GitHubSuccessResult extends SuccessResult implements MarketplaceRes */ private final long releaseId; - public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String repoName, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId) + /** + * プレリリースかどうか + */ + private final boolean isPreRelease; + + public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downloadUrl, @Nullable String fileName, @Nullable String version, @NotNull String repoName, @NotNull String owner, long size, @NotNull String releaseName, @NotNull String releaseBody, long releaseId, boolean isPreRelease) { super(resolver, downloadUrl, fileName, version, Source.GITHUB); this.owner = owner; @@ -56,6 +61,7 @@ public GitHubSuccessResult(@NotNull BaseResolver resolver, @NotNull String downl this.releaseName = releaseName; this.releaseBody = releaseBody; this.repoName = repoName; + this.isPreRelease = isPreRelease; } @Nonnull diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java index 0675106b..06bb9f16 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java @@ -173,8 +173,9 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso String downloadURL = assetObject.get("url").getAsString(); String fileName = assetObject.get("name").getAsString(); long size = assetObject.get("size").getAsLong(); + boolean isPreRelease = object.get("prerelease").getAsBoolean(); - GitHubSuccessResult result = new GitHubSuccessResult(this, downloadURL, fileName, version, repositoryName, owner, size, releaseName, body, releaseId); + GitHubSuccessResult result = new GitHubSuccessResult(this, downloadURL, fileName, version, repositoryName, owner, size, releaseName, body, releaseId, isPreRelease); if (assets.size() == 1) return result; From 795aa1737434b2087321f2d8a955aca31e800e26 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 13 Nov 2022 18:07:30 +0900 Subject: [PATCH 457/745] fix(daemon): GitHubURLResolver always returns MultiResult --- .../net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java index 06bb9f16..21229558 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java @@ -183,6 +183,9 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso results.add(result); } + if (results.size() == 1) + return results.get(0); + return new MultiResult(this, results.toArray(new GitHubSuccessResult[0])); } From 20deedc95a7b0e6901cf61cd8d81aeb22f30b08a Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 13 Nov 2022 18:08:37 +0900 Subject: [PATCH 458/745] fix(daemon): invalid source --- .../net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java index 801e5b89..3548c3ad 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/BaseResolver.java @@ -43,7 +43,7 @@ default ResolveResult autoPickFirst(MultiResult multiResult, ResolveResult.Sourc ResolveResult[] results = multiResult.getResults(); if (results.length == 0) - return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, source); ResolveResult result = results[0]; if (result instanceof MultiResult) From d627aa54caf9723036297dd5ca7804c06f2759f1 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 13 Nov 2022 20:16:06 +0900 Subject: [PATCH 459/745] feat(daemon): Enchant GitHubURLResolver#autoPickOnePlugin --- .../kpm/resolver/impl/GitHubURLResolver.java | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java index 21229558..d8f43a0b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java @@ -12,10 +12,14 @@ import net.kunmc.lab.kpm.utils.http.HTTPResponse; import net.kunmc.lab.kpm.utils.http.RequestContext; import net.kunmc.lab.kpm.utils.http.Requests; +import net.kunmc.lab.kpm.utils.versioning.Version; +import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -75,10 +79,75 @@ else if (tagGroup != null && !tagGroup.isEmpty()) return this.processGitHubAPI(owner, repositoryName, repository, tag, query.getVersion()); } + private static boolean endsWithIgn(String str, String suffix) + { + return StringUtils.endsWithIgnoreCase(str, suffix); + } + + private static boolean endsWithIgn(String str, String suffix, String suffix2) + { + return endsWithIgn(str, suffix) || endsWithIgn(str, suffix2); + } + + private static long evalResult(GitHubSuccessResult result) + { + long reputation = 0; + + String fileName = result.getFileName(); + String version = result.getVersion(); + boolean isPreRelease = result.isPreRelease(); + assert fileName != null; + assert version != null; + + Version versionObj; + if (Version.isValidVersionString(version)) + versionObj = Version.of(version); + else + versionObj = Version.of("0.0.0"); + + reputation += versionObj.getMajor().getIntValue() + versionObj.getMinor().getIntValue() + versionObj.getPatch().getIntValue(); + reputation *= 100L; + + if (endsWithIgn(fileName, ".jar", ".zip")) + reputation += 10; + + if (endsWithIgn(fileName, ".plugin.jar", ".plugin.zip")) + reputation += 5; + else if (endsWithIgn(fileName, ".api.jar", ".api.zip")) + reputation -= 5; + + if (isPreRelease) + reputation -= 5; + + return reputation; + } + @Override public ResolveResult autoPickOnePlugin(MultiResult multiResult) { - return this.autoPickFirst(multiResult, ResolveResult.Source.GITHUB); + HashMap map = new HashMap<>(); + ErrorResult firstError = null; + for (ResolveResult result : multiResult.getResults()) + { + if (result instanceof GitHubSuccessResult) + { + GitHubSuccessResult successResult = (GitHubSuccessResult) result; + map.put(evalResult(successResult), successResult); + } + else if (result instanceof ErrorResult) + { + if (firstError == null) + firstError = (ErrorResult) result; + } + } + + if (map.isEmpty()) + return firstError; + + return map.entrySet().stream().parallel() + .max(Map.Entry.comparingByKey()) + .map(Map.Entry::getValue) + .orElse(null); } private ResolveResult processGitHubAPI(String owner, String repositoryName, String repository, String tag, @Nullable String version) From 0c7df944dd23c2dc70cf9c4e22ff027f8ad56dd8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 13 Nov 2022 20:32:59 +0900 Subject: [PATCH 460/745] feat(daemon): Enchant GitHubURLResolver#autoPickOnePlugin --- .../net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java index d8f43a0b..b5c928b1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java @@ -106,6 +106,10 @@ private static long evalResult(GitHubSuccessResult result) versionObj = Version.of("0.0.0"); reputation += versionObj.getMajor().getIntValue() + versionObj.getMinor().getIntValue() + versionObj.getPatch().getIntValue(); + if (versionObj.getPreRelease() != null) + reputation += versionObj.getPreRelease().getRawValue().chars().sum(); + if (versionObj.getBuildMetadata() != null) + reputation += versionObj.getBuildMetadata().getRawValue().chars().sum(); reputation *= 100L; if (endsWithIgn(fileName, ".jar", ".zip")) From 2e56dc647da590b8c00e693c58c3a4a28c51aa0a Mon Sep 17 00:00:00 2001 From: Peyang Date: Wed, 16 Nov 2022 22:18:38 +0900 Subject: [PATCH 461/745] fix(daemon): search direction of dependency --- .../kpm/installer/impls/uninstall/PluginUninstaller.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index 41b43d2e..975f2b67 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -84,7 +84,7 @@ public InstallResult execute(@NotNull UninstallArgument argument // endregion - // region Check plugin are depended by other plugins + // region Check other plugins depends on this plugin. for (Plugin plugin : plugins) { @@ -177,17 +177,17 @@ private ArrayList getAllDependencies(Plugin target) ArrayList plugins = new ArrayList<>(); List dependencies = - this.daemon.getPluginMetaManager().getProvider().getDependOn(target.getName()); + this.daemon.getPluginMetaManager().getProvider().getDependedBy(target.getName()); for (DependencyNode depend : dependencies) { - Plugin dependPlugin = this.getPlugin(depend.getDependsOn()); + Plugin dependPlugin = this.getPlugin(depend.getPlugin()); if (dependPlugin != null) { plugins.add(dependPlugin); plugins.addAll(this.getAllDependencies(dependPlugin)); } - // if depend plugin not found, ignore it because it only exist in database. + // if it cannot find the plugin, ignore it because it only exist in database. // Doesn't exist in filesystem and server plugins. } From 27e0e1aa578c182d7df3b3f9e9f5cd552495e9c0 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 18 Nov 2022 01:44:27 +0900 Subject: [PATCH 462/745] refactor(daemon): Migrate KPMCollectors and ReversedCollector --- .../impls/uninstall/PluginUninstaller.java | 4 +- .../kunmc/lab/kpm/utils/KPMCollectors.java | 57 +++++++++++++++++++ .../lab/kpm/utils/ReversedCollector.java | 53 ----------------- 3 files changed, 59 insertions(+), 55 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java delete mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReversedCollector.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index 975f2b67..79304ba3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -16,8 +16,8 @@ import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallTask; import net.kunmc.lab.kpm.meta.DependencyNode; import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.kpm.utils.KPMCollectors; import net.kunmc.lab.kpm.utils.PluginUtil; -import net.kunmc.lab.kpm.utils.ReversedCollector; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; @@ -148,7 +148,7 @@ public InstallResult execute(@NotNull UninstallArgument argument List ordered = computeResult.getOrder(); List orderedPlugins = ordered.stream() .map(element -> namePluginMap.get(element.getPluginName())) - .collect(ReversedCollector.toList()); // Convert load order to unload order. + .collect(KPMCollectors.toReversedList()); // Convert load order to unload order. return new UnInstallArgument(orderedPlugins); }) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java new file mode 100644 index 00000000..588f6e16 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java @@ -0,0 +1,57 @@ +package net.kunmc.lab.kpm.utils; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; + +public class KPMCollectors +{ + public static ReversedCollector toReversedList() + { + return new ReversedCollector<>(); + } + + private static class ReversedCollector implements Collector, List> + { + @Override + public Supplier> supplier() + { + return ArrayList::new; + } + + @Override + public BiConsumer, T> accumulator() + { + return (list, t) -> list.add(0, t); + } + + @Override + public BinaryOperator> combiner() + { + return (list1, list2) -> + { + list1.addAll(0, list2); + return list1; + }; + } + + @Override + public Function, List> finisher() + { + return list -> list; + } + + @Override + public Set characteristics() + { + return EnumSet.of(Characteristics.CONCURRENT); + } + } + +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReversedCollector.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReversedCollector.java deleted file mode 100644 index 85f56e96..00000000 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/ReversedCollector.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.kunmc.lab.kpm.utils; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collector; - -public class ReversedCollector implements Collector, List> -{ - public static ReversedCollector toList() - { - return new ReversedCollector<>(); - } - - @Override - public Supplier> supplier() - { - return ArrayList::new; - } - - @Override - public BiConsumer, T> accumulator() - { - return (list, t) -> list.add(0, t); - } - - @Override - public BinaryOperator> combiner() - { - return (list1, list2) -> - { - list1.addAll(0, list2); - return list1; - }; - } - - @Override - public Function, List> finisher() - { - return list -> list; - } - - @Override - public Set characteristics() - { - return EnumSet.of(Characteristics.CONCURRENT); - } -} From 3ebbbcb2da2429752369b3b5a62b2e32cfcdfdea Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 18 Nov 2022 01:54:51 +0900 Subject: [PATCH 463/745] feat(daemon): Lookup task --- .../task/tasks/lookup/LookupArgument.java | 20 ++++ .../task/tasks/lookup/LookupErrorCause.java | 12 +++ .../task/tasks/lookup/LookupResult.java | 36 ++++++++ .../task/tasks/lookup/LookupState.java | 20 ++++ .../task/tasks/lookup/PluginLookupTask.java | 92 +++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupArgument.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupErrorCause.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupResult.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupState.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/PluginLookupTask.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupArgument.java new file mode 100644 index 00000000..cf7e55ba --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupArgument.java @@ -0,0 +1,20 @@ +package net.kunmc.lab.kpm.installer.task.tasks.lookup; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.kpm.installer.task.TaskArgument; +import org.jetbrains.annotations.NotNull; + +/** + * プラグインの検索を行うタスクの引数です。 + */ +@Value +@EqualsAndHashCode(callSuper = false) +public class LookupArgument extends TaskArgument +{ + /** + * 検索するクエリです。 + */ + @NotNull + String[] queries; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupErrorCause.java new file mode 100644 index 00000000..31e036a3 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupErrorCause.java @@ -0,0 +1,12 @@ +package net.kunmc.lab.kpm.installer.task.tasks.lookup; + +/** + * プラグインの検索のエラーを表す列挙型です。 + */ +public enum LookupErrorCause +{ + /** + * 不正なクエリが指定されたことを示します。 + */ + INVALID_QUERY +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupResult.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupResult.java new file mode 100644 index 00000000..71cd63d3 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupResult.java @@ -0,0 +1,36 @@ +package net.kunmc.lab.kpm.installer.task.tasks.lookup; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.kunmc.lab.kpm.installer.task.TaskResult; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.LinkedHashMap; + +/** + * プラグインの検索を行うタスクの結果です。 + */ +@Value +@EqualsAndHashCode(callSuper = true) +public class LookupResult extends TaskResult +{ + /** + * 検索に成功した場合、そのプラグインらが格納されます。 + */ + @Nullable + LinkedHashMap<@NotNull String, @Nullable Plugin> plugins; + + public LookupResult(boolean success, @NotNull LookupState state, @NotNull LinkedHashMap plugins) + { + super(success, state, null); + this.plugins = plugins; + } + + public LookupResult(boolean success, @NotNull LookupState state, @Nullable LookupErrorCause errorCause) + { + super(success, state, errorCause); + this.plugins = null; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupState.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupState.java new file mode 100644 index 00000000..1927d407 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/LookupState.java @@ -0,0 +1,20 @@ +package net.kunmc.lab.kpm.installer.task.tasks.lookup; + +/** + * プラグインの検索の状態を表します。 + */ +public enum LookupState +{ + /** + * プラグインの検索が初期化されたことを示します。 + */ + INITIALIZED, + /** + * クエリの解析中であることを示します。 + */ + QUERY_PARSING, + /** + * プラグインの検索中であることを示します。 + */ + PLUGIN_LOOKUP +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/PluginLookupTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/PluginLookupTask.java new file mode 100644 index 00000000..cbf76d68 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/lookup/PluginLookupTask.java @@ -0,0 +1,92 @@ +package net.kunmc.lab.kpm.installer.task.tasks.lookup; + +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.task.InstallTask; +import net.kunmc.lab.kpm.resolver.QueryContext; +import net.kunmc.lab.kpm.utils.KPMCollectors; +import net.kunmc.lab.kpm.utils.versioning.Version; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * サーバに導入されているプラグインを検索するタスクです。 + * クエリを指定し、マッチするプラグインを検索します。 + */ +public class PluginLookupTask extends InstallTask +{ + private LookupState state; + + public PluginLookupTask(@NotNull AbstractInstaller installer) + { + super(installer.getProgress(), installer.getProgress().getSignalHandler()); + + this.state = LookupState.INITIALIZED; + } + + private static LinkedHashMap lookupAll(QueryContext[] queries, String[] queryStrings) + { + AtomicInteger count = new AtomicInteger(0); + return Arrays.stream(queries) + .map(query -> Pair.of(queryStrings[count.getAndIncrement()], lookupOne(query))) + .collect(KPMCollectors.toPairMap(LinkedHashMap::new)); + } + + private static Plugin lookupOne(QueryContext query) + { + Plugin plugin; + if ((plugin = Bukkit.getPluginManager().getPlugin(query.getQuery())) == null) + return null; + + if (query.getVersion() == null) + return plugin; + + String pluginVersionStr = plugin.getDescription().getVersion(); + if (!Version.isValidVersionString(pluginVersionStr)) + return null; + + Version pluginVersion = Version.of(pluginVersionStr); + + if (!query.getVersion().isEqualTo(pluginVersion)) + return null; + + return plugin; + } + + private static QueryContext[] parseQueries(String[] queries) + { + try + { + QueryContext[] result = Arrays.stream(queries) + .map(QueryContext::fromString) + .toArray(QueryContext[]::new); + + return result.length == queries.length ? result: null; + } + catch (IllegalArgumentException e) + { + return null; + } + } + + @Override + public @NotNull LookupResult runTask(@NotNull LookupArgument arguments) + { + this.state = LookupState.QUERY_PARSING; + String[] queryStrs = arguments.getQueries(); + QueryContext[] queries = parseQueries(queryStrs); + + if (queries == null) + return new LookupResult(false, this.state, LookupErrorCause.INVALID_QUERY); + + this.state = LookupState.PLUGIN_LOOKUP; + LinkedHashMap result = lookupAll(queries, queryStrs); + + return new LookupResult(true, this.state, result); + } +} From 463f95b92ec64b7e3c2c9fd36373dd936454a7cd Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 18 Nov 2022 01:55:25 +0900 Subject: [PATCH 464/745] feat(daemon): Pair mapping in KPMCollectors --- .../kunmc/lab/kpm/utils/KPMCollectors.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java index 588f6e16..dde4bb13 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/KPMCollectors.java @@ -1,8 +1,13 @@ package net.kunmc.lab.kpm.utils; +import lombok.AllArgsConstructor; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; + import java.util.ArrayList; import java.util.EnumSet; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; @@ -17,6 +22,16 @@ public static ReversedCollector toReversedList() return new ReversedCollector<>(); } + public static > PairMapper toPairMap(Supplier mapSupplier) + { + return new PairMapper<>(mapSupplier); + } + + public static PairMapper> toPairHashMap() + { + return new PairMapper<>(HashMap::new); + } + private static class ReversedCollector implements Collector, List> { @Override @@ -54,4 +69,44 @@ public Set characteristics() } } + // pair to hashmap + @AllArgsConstructor + private static class PairMapper> implements Collector, M, M> + { + private final Supplier supplier; + + @Override + public Supplier supplier() + { + return this.supplier; + } + + @Override + public BiConsumer> accumulator() + { + return (map, pair) -> map.put(pair.getLeft(), pair.getRight()); + } + + @Override + public BinaryOperator combiner() + { + return (map1, map2) -> + { + map1.putAll(map2); + return map1; + }; + } + + @Override + public Function finisher() + { + return map -> map; + } + + @Override + public Set characteristics() + { + return EnumSet.of(Characteristics.CONCURRENT); + } + } } From c5e326055c34213113d58ec7dc8e59085135c0b4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 18 Nov 2022 01:58:31 +0900 Subject: [PATCH 465/745] refactor(daemon): installQuery => resolveQuery in PluginMeta --- KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java index 6935a6df..2b8f5c0b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/meta/PluginMeta.java @@ -39,7 +39,8 @@ public class PluginMeta */ boolean isDependency; /** - * プラグインのインストールに使用した解決クエリです。 + * プラグインの解決に使用するクエリです。 + * このクエリは, アップグレード機能で使用されます。 */ @Nullable String resolveQuery; From 5a3ea54628a29b908f495ed9605e94c2693052c0 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 19 Nov 2022 15:12:14 +0900 Subject: [PATCH 466/745] feat(daemon): Auto pickup resolve result supporting --- .../task/tasks/resolve/PluginResolveTask.java | 10 +--------- .../net/kunmc/lab/kpm/resolver/PluginResolver.java | 12 ++++++++++++ .../kpm/resolver/impl/BruteforceGitHubResolver.java | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java index fa178508..6f48a688 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java @@ -44,15 +44,7 @@ public PluginResolveTask(@NotNull AbstractInstaller installer) if (signal.getSpecifiedResult() != null) return signal.getSpecifiedResult(); // Plugin actually resolved by SignalHandler. - ResolveResult result = results.getResults()[0]; - - if (result instanceof MultiResult) - { - MultiResult multiResult = (MultiResult) result; - return this.resolveMultipleResults(query, multiResult); // Recursive call. - } - - return result; + return this.resolver.pickUpOne(results); } @Override diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java index 3cb8f17b..cdbff923 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java @@ -3,6 +3,7 @@ import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; import net.kunmc.lab.kpm.resolver.interfaces.URLResolver; import net.kunmc.lab.kpm.resolver.result.ErrorResult; +import net.kunmc.lab.kpm.resolver.result.MultiResult; import net.kunmc.lab.kpm.resolver.result.PipeResult; import net.kunmc.lab.kpm.resolver.result.ResolveResult; @@ -82,6 +83,17 @@ public ResolveResult resolve(String query) return this.actuallyResolve(this.resolvers.get(context.getResolverName().toLowerCase()), context); } + /** + * 複数の結果({@link MultiResult})を一つの結果にピックアップします。 + * + * @param multiResult 複数の結果 + * @return 一つの結果 + */ + public ResolveResult pickUpOne(MultiResult multiResult) + { + return multiResult.getResolver().autoPickOnePlugin(multiResult); + } + private ResolveResult actuallyResolve(List resolvers, QueryContext queryContext) { URL url = null; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java index d9189186..b3acdeed 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java @@ -46,7 +46,7 @@ public ResolveResult resolve(QueryContext query) @Override public ResolveResult autoPickOnePlugin(MultiResult multiResult) { - return null; + return this.gitHubURLResolver.autoPickOnePlugin(multiResult); } @Override From 0f58a45b568d900cc37828152c87dc877a9bad86 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 19 Nov 2022 23:47:12 +0900 Subject: [PATCH 467/745] refactor: Invert flag of cancelInstall to continueInstall --- .../lab/kpm/installer/impls/install/PluginInstaller.java | 2 +- .../kpm/installer/impls/uninstall/PluginUninstaller.java | 2 +- .../installer/signals/assertion/IgnoredPluginSignal.java | 6 +++--- .../kunmc/lab/kpm/commands/debug/DebugSignalHandler.java | 2 +- .../kpm/signal/handlers/common/CheckEnvSignalHandler.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java index faf26824..f415a12b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java @@ -186,7 +186,7 @@ private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescripti IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(pluginDescription); this.postSignal(ignoredPluginSignal); - if (ignoredPluginSignal.isCancelInstall()) + if (!ignoredPluginSignal.isContinueInstall()) return InstallErrorCause.PLUGIN_IGNORED; } // endregion diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index 79304ba3..fc63d9d0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -77,7 +77,7 @@ public InstallResult execute(@NotNull UninstallArgument argument { IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(plugin.getDescription()); this.postSignal(ignoredPluginSignal); - if (ignoredPluginSignal.isCancelInstall()) + if (!ignoredPluginSignal.isContinueInstall()) return this.error(UnInstallErrorCause.PLUGIN_IGNORED); } } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java index c9ea8a4e..63918b79 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java @@ -7,7 +7,7 @@ /** * 指定されたプラグインが無視リストに登録されていることを示すシグナルです。 - * {@link IgnoredPluginSignal#setCancelInstall(boolean)} を変更することで、インストールのキャンセルを設定できます。 + * {@link IgnoredPluginSignal#setContinueInstall(boolean)} を変更することで、インストールのキャンセルを設定できます。 */ @Data public class IgnoredPluginSignal implements Signal @@ -17,13 +17,13 @@ public class IgnoredPluginSignal implements Signal @NotNull private final PluginDescriptionFile pluginDescription; - private boolean cancelInstall; + private boolean continueInstall; public IgnoredPluginSignal(@NotNull PluginDescriptionFile pluginDescription) { this.pluginDescription = pluginDescription; this.pluginName = pluginDescription.getName(); - this.cancelInstall = true; + this.continueInstall = false; } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/DebugSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/DebugSignalHandler.java index 5a802cc6..4f9747f1 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/DebugSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/DebugSignalHandler.java @@ -45,7 +45,7 @@ else if (signal instanceof IgnoredPluginSignal) IgnoredPluginSignal ignoredPluginSignal = (IgnoredPluginSignal) signal; Question question = terminal.getInput().showYNQuestion("Cancel?"); - ignoredPluginSignal.setCancelInstall(question.waitAndGetResult().test(QuestionAttribute.YES)); + ignoredPluginSignal.setContinueInstall(question.waitAndGetResult().test(QuestionAttribute.NO)); } } catch (Exception e) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/CheckEnvSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/CheckEnvSignalHandler.java index 15d7aaaa..7606471d 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/CheckEnvSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/CheckEnvSignalHandler.java @@ -40,7 +40,7 @@ public void onPluginIsIgnored(IgnoredPluginSignal signal) this.terminal.writeLine(ChatColor.DARK_RED + "W: 強制的な操作は予期しない問題を引き起こす可能性があります。"); - signal.setCancelInstall(!SignalHandlingUtils.askContinue(this.terminal)); + signal.setContinueInstall(SignalHandlingUtils.askContinue(this.terminal)); } private void printKeyValue(String key, String value) From e56dd163a0d8afdcb0c65a0be10f0166cd464607 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 20 Nov 2022 19:14:36 +0900 Subject: [PATCH 468/745] fix(daemon): UninstallArgument builder --- .../impls/autoremove/PluginAutoRemover.java | 3 +- .../impls/uninstall/PluginUninstaller.java | 19 ++++--- .../impls/uninstall/UninstallArgument.java | 52 +++++++++++++++---- .../lab/kpm/commands/CommandUninstall.java | 5 +- .../commands/debug/CommandUninstallDebug.java | 2 +- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java index 5f190810..e2473508 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/PluginAutoRemover.java @@ -83,7 +83,8 @@ public InstallResult execute(@NotNull AutoRemoveArgument argume return this.error(AutoRemoveErrorCause.UNINSTALLER_INIT_FAILED); } - UninstallArgument uninstallArgument = new UninstallArgument(targetPlugins.toArray(new String[0])); + UninstallArgument uninstallArgument = UninstallArgument.builder(targetPlugins.toArray(new String[0])) + .build(); InstallResult uninstallResult = uninstaller.execute(uninstallArgument); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index fc63d9d0..9f0a1704 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -55,16 +55,21 @@ public InstallResult execute(@NotNull UninstallArgument argument // region Search plugin this.progress.setCurrentTask(UnInstallTasks.SEARCHING_PLUGIN); - for (String pluginName : argument.getPlugins()) - { - Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); - if (plugin == null) - return this.error(UnInstallErrorCause.PLUGIN_NOT_FOUND); + if (argument.getPluginNames() != null) + for (String pluginName : argument.getPluginNames()) + { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin == null) + return this.error(UnInstallErrorCause.PLUGIN_NOT_FOUND); - plugins.add(plugin); + plugins.add(plugin); + } + else + { + assert argument.getPlugins() != null; + plugins.addAll(argument.getPlugins()); } - // endregion // region Do assertions. diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java index ac60e316..c10614ef 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java @@ -1,32 +1,62 @@ package net.kunmc.lab.kpm.installer.impls.uninstall; -import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; -import org.jetbrains.annotations.NotNull; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** * アンインストールの引数を格納するクラスです。 */ @Data -@AllArgsConstructor @EqualsAndHashCode(callSuper = true) +@Builder public class UninstallArgument extends AbstractInstallerArgument { /** - * アンインストールするプラグインの名前 + * アンインストールするプラグインの名前です。 + * {@link #plugins} またはこのフィールドのどちらかが指定されている必要があります。 */ - @NotNull - private final String[] plugins; + @Nullable + @Unmodifiable + private final List pluginNames; /** - * 単一のプラグインをアンインストールするための引数を生成します。 - * - * @param plugin アンインストールするプラグイン + * アンインストールするプラグインのインスタンスです。 + * {@link #pluginNames} またはこのフィールドのどちらかが指定されている必要があります。 */ - public UninstallArgument(@NotNull String plugin) + @Nullable + @Unmodifiable + private final List plugins; + + public static UninstallArgumentBuilder builder(Plugin plugin) + { + return new UninstallArgumentBuilder() + .plugins(Collections.singletonList(plugin)); + } + + public static UninstallArgumentBuilder builder(String pluginName) + { + return new UninstallArgumentBuilder() + .pluginNames(Collections.singletonList(pluginName)); + } + + public static UninstallArgumentBuilder builder(Plugin... plugins) + { + return new UninstallArgumentBuilder() + .plugins(Arrays.asList(plugins)); + } + + public static UninstallArgumentBuilder builder(String... pluginNames) { - this(new String[]{plugin}); + return new UninstallArgumentBuilder() + .pluginNames(Arrays.asList(pluginNames)); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUninstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUninstall.java index b0f098e3..1f157f05 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUninstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUninstall.java @@ -31,7 +31,10 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String query = args[0]; Runner.runAsync(() -> - this.plugin.getHeadInstallers().runUninstall(terminal, new UninstallArgument(query)) + this.plugin.getHeadInstallers().runUninstall( + terminal, + UninstallArgument.builder(query).build() + ) ); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandUninstallDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandUninstallDebug.java index 4de21f7d..c17421e2 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandUninstallDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandUninstallDebug.java @@ -41,7 +41,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, PluginUninstaller installer = new PluginUninstaller(this.daemon, DebugSignalHandler.toManager(terminal)); - InstallResult installResult = installer.execute(new UninstallArgument(query)); + InstallResult installResult = installer.execute(UninstallArgument.builder(query).build()); if (installResult instanceof InstallFailedInstallResult) { From ddee15d9eca3d96747159fd9ebc1dddeb72bdc7b Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 20 Nov 2022 22:51:04 +0900 Subject: [PATCH 469/745] refactor(daemon): Remove unused IOException throws signature --- .../java/net/kunmc/lab/kpm/installer/AbstractInstaller.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java index d39a4a0b..ce8b6aae 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/AbstractInstaller.java @@ -67,10 +67,9 @@ protected void postSignal(@NotNull Signal signal) * * @param arguments インストーラに渡す引数 * @return インストールの結果 - * @throws IOException ファイルの読み書きに失敗した場合 * @see AbstractInstaller#execute(AbstractInstallerArgument) */ - public InstallResult

    run(@NotNull A arguments) throws IOException + public InstallResult

    run(@NotNull A arguments) { try { From 3e5de1569a800353167edbfaafca84271b8b3e6c Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 20 Nov 2022 22:58:36 +0900 Subject: [PATCH 470/745] feat(daemon): Create skip env checks on uninstaller --- .../impls/uninstall/PluginUninstaller.java | 26 ++++++++++--------- .../impls/uninstall/UninstallArgument.java | 20 ++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index 9f0a1704..b92dd0a5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -76,40 +76,42 @@ public InstallResult execute(@NotNull UninstallArgument argument this.progress.setCurrentTask(UnInstallTasks.CHECKING_ENVIRONMENT); // region Check is plugin marked as ignored - for (Plugin plugin : plugins) + if (!argument.isSkipExcludeChecks()) { - if (this.isPluginIgnored(plugin.getName())) + for (Plugin plugin : plugins) { + if (!this.isPluginIgnored(plugin.getName())) + continue; IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(plugin.getDescription()); this.postSignal(ignoredPluginSignal); - if (!ignoredPluginSignal.isContinueInstall()) + if (!(argument.isForceUninstall() || ignoredPluginSignal.isContinueInstall())) return this.error(UnInstallErrorCause.PLUGIN_IGNORED); } } - // endregion // region Check other plugins depends on this plugin. - - for (Plugin plugin : plugins) + if (!argument.isSkipDependencyChecks()) { - List dependencies = this.getAllDependencies(plugin); - dependencies.removeAll(plugins); - - if (!dependencies.isEmpty()) + for (Plugin plugin : plugins) { + List dependencies = this.getAllDependencies(plugin); + dependencies.removeAll(plugins); + + if (dependencies.isEmpty()) + continue; PluginIsDependencySignal pluginIsDependencySignal = new PluginIsDependencySignal(plugin, dependencies); this.postSignal(pluginIsDependencySignal); - if (pluginIsDependencySignal.isForceUninstall()) + if (argument.isForceUninstall() || pluginIsDependencySignal.isForceUninstall()) plugins.addAll(dependencies); else return this.error(UnInstallErrorCause.PLUGIN_IS_DEPENDENCY); } - } + } // endregion // endregion diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java index c10614ef..a0722ae8 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/UninstallArgument.java @@ -36,6 +36,26 @@ public class UninstallArgument extends AbstractInstallerArgument @Unmodifiable private final List plugins; + /** + * 除外チェックをスキップするかどうかのフラグです。 + */ + @Builder.Default + private final boolean skipExcludeChecks = false; + + /** + * 依存関係チェックをスキップするかどうかのフラグです。 + */ + @Builder.Default + private final boolean skipDependencyChecks = false; + + /** + * 強制アンインストールを行うかどうかのフラグです。 + * デフォルトでは, 状況に応じたシグナルが送信され, 選択を促されます。 + * このフラグが true の場合, シグナルは送信されますが, シグナルの選択は無視され, アンインストールが行われます。 + */ + @Builder.Default + private final boolean forceUninstall = false; + public static UninstallArgumentBuilder builder(Plugin plugin) { return new UninstallArgumentBuilder() From edf173ba3edc7b2943df1ee5d7e407b679ec37d8 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 21 Nov 2022 01:54:48 +0900 Subject: [PATCH 471/745] feat(daemon): ResolveResult in InstallArgument --- .../impls/install/InstallArgument.java | 47 +++++++++++++++- .../impls/install/PluginInstaller.java | 56 ++++++++++++------- 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallArgument.java index 33a17d9a..94c23536 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallArgument.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/InstallArgument.java @@ -1,20 +1,63 @@ package net.kunmc.lab.kpm.installer.impls.install; +import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * インストールの引数を格納するクラスです。 */ @Data @EqualsAndHashCode(callSuper = true) +@Builder public class InstallArgument extends AbstractInstallerArgument { /** - * インストールするプラグインのクエリ + * インストールするプラグインのクエリです。 + * {@link #resolveResult} またはこのフィールドのどちらかが指定されている必要があります。 */ - @NotNull + @Nullable private final String query; + /** + * インストールするプラグインの解決結果です。 + * {@link #query} またはこのフィールドのどちらかが指定されている必要があります。 + */ + @Nullable + private final SuccessResult resolveResult; + + /** + * 除外チェックをスキップするかどうかのフラグです。 + */ + @Builder.Default + private final boolean skipExcludeChecks = false; + + /** + * 同じプラグインが既にインストールされている場合に置換するかどうかのフラグです。 + * このフラグが true の場合, シグナルの選択は無視して置換されます。 + */ + @Builder.Default + private final boolean replaceOldPlugin = false; + + /** + * 強制インストールを行うかどうかのフラグです。 + * デフォルトでは, 状況に応じたシグナルが送信され, 選択を促されます。 + * このフラグが true の場合, シグナルは送信されますが, シグナルの選択は無視され, インストールが行われます。 + */ + @Builder.Default + private final boolean forceInstall = false; + + public static InstallArgumentBuilder builder(@NotNull String query) + { + return new InstallArgumentBuilder().query(query); + } + + public static InstallArgumentBuilder builder(@NotNull SuccessResult result) + { + return new InstallArgumentBuilder().resolveResult(result); + } } + diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java index f415a12b..b103b416 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/PluginInstaller.java @@ -23,6 +23,7 @@ import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveTask; import net.kunmc.lab.kpm.kpminfo.InvalidInformationFileException; import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import net.kunmc.lab.kpm.signal.SignalHandleManager; import net.kunmc.lab.kpm.utils.PluginUtil; import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; @@ -62,27 +63,39 @@ public PluginInstaller(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager s public InstallResult execute(@NotNull InstallArgument argument) throws TaskFailedException { String query = argument.getQuery(); + SuccessResult resolveResult = argument.getResolveResult(); Path pluginFilePath; PluginDescriptionFile pluginDescription; String pluginName; // region Do plugin resolve, download and description load. - TaskResult pluginDescriptionResult = - this.submitter( - InstallTasks.RESOLVING_QUERY, - new PluginResolveTask(this) - ) - .then(InstallTasks.DOWNLOADING, new DownloadTask(this)) - .bridgeArgument(result -> { - if (result.getResolveResult() == null) - throw new IllegalArgumentException("Plugin Resolving must be successful"); - - return new DownloadArgument(result.getResolveResult().getDownloadUrl()); - }) - .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(this)) - .bridgeArgument(result -> new DescriptionLoadArgument(result.getPath())) - .submitAll(new PluginResolveArgument(query)); + TaskResult pluginDescriptionResult; + + if (query != null) + pluginDescriptionResult = this.submitter( + InstallTasks.RESOLVING_QUERY, + new PluginResolveTask(this) + ) + .then(InstallTasks.DOWNLOADING, new DownloadTask(this)) + .bridgeArgument(result -> { + assert result.getResolveResult() != null; + return new DownloadArgument(result.getResolveResult().getDownloadUrl()); + }) + .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(this)) + .bridgeArgument(result -> new DescriptionLoadArgument(result.getPath())) + .submitAll(new PluginResolveArgument(query)); + else if (resolveResult != null) + pluginDescriptionResult = this.submitter( + InstallTasks.DOWNLOADING, + new DownloadTask(this) + ) + .bridgeArgument(result -> new DownloadArgument(resolveResult.getDownloadUrl())) + .then(InstallTasks.LOADING_PLUGIN_DESCRIPTION, new DescriptionLoadTask(this)) + .bridgeArgument(result -> new DescriptionLoadArgument(result.getPath())) + .submitAll(new DownloadArgument(resolveResult.getDownloadUrl())); + else + throw new IllegalArgumentException("Query or ResolveResult must be specified"); DescriptionLoadResult descriptionLoadResult = (DescriptionLoadResult) pluginDescriptionResult; @@ -115,7 +128,7 @@ public InstallResult execute(@NotNull InstallArgument argument) th this.progress.setCurrentTask(InstallTasks.CHECKING_ENVIRONMENT); - InstallErrorCause checkEnvErrorResult = this.checkEnvironment(pluginDescription); + InstallErrorCause checkEnvErrorResult = this.checkEnvironment(pluginDescription, argument); if (checkEnvErrorResult != null) return this.error(checkEnvErrorResult); @@ -129,7 +142,9 @@ public InstallResult execute(@NotNull InstallArgument argument) th new AlreadyInstalledPluginSignal(sameServerPlugin.getDescription(), pluginDescription); this.postSignal(alreadyInstalledPluginSignal); - replacePlugin = alreadyInstalledPluginSignal.isReplacePlugin(); + replacePlugin = alreadyInstalledPluginSignal.isReplacePlugin() || + argument.isReplaceOldPlugin() || + argument.isForceInstall(); if (!replacePlugin) return this.error(InstallErrorCause.PLUGIN_ALREADY_INSTALLED); @@ -175,18 +190,17 @@ public InstallResult execute(@NotNull InstallArgument argument) th } @Nullable - private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescription) + private InstallErrorCause checkEnvironment(PluginDescriptionFile pluginDescription, InstallArgument argument) { String pluginName = pluginDescription.getName(); - // region Check if the plugin is marked as ignored - if (this.isPluginIgnored(pluginName)) + if (!argument.isSkipExcludeChecks() && this.isPluginIgnored(pluginName)) { IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(pluginDescription); this.postSignal(ignoredPluginSignal); - if (!ignoredPluginSignal.isContinueInstall()) + if (!(argument.isForceInstall() || ignoredPluginSignal.isContinueInstall())) return InstallErrorCause.PLUGIN_IGNORED; } // endregion From 4ca595768a68262562ee5bccf278df3cfc0d3f4e Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 21 Nov 2022 01:55:08 +0900 Subject: [PATCH 472/745] feat(daemon): Version parsing with QueryContext --- .../kunmc/lab/kpm/resolver/QueryContext.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/QueryContext.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/QueryContext.java index 0789b5ec..2e7937eb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/QueryContext.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/QueryContext.java @@ -2,6 +2,7 @@ import lombok.Builder; import lombok.Data; +import net.kunmc.lab.kpm.utils.versioning.Version; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +28,7 @@ public class QueryContext * 指定バージョンです。 */ @Nullable - String version; + Version version; private static final String resolverNameQuerySeparator = ">"; private static final String versionEqualQuerySeparator = "=="; @@ -49,17 +50,23 @@ public static QueryContext fromString(@NotNull String query) if (queryParts.length >= 2) resolverName = queryParts[0]; - String version = null; + String bodyAndVersion = queryParts[queryParts.length - 1]; - String part = queryParts[queryParts.length - 1]; + int versionSeparatorIndex = bodyAndVersion.lastIndexOf(versionEqualQuerySeparator); - int versionSeparatorIndex = part.lastIndexOf(versionEqualQuerySeparator); + String versionStr = null; + Version version = null; if (versionSeparatorIndex != -1) - version = part.substring(versionSeparatorIndex + 2); + { + versionStr = bodyAndVersion.substring(versionSeparatorIndex + 2); + if (!Version.isValidVersionString(versionStr)) + throw new IllegalArgumentException("Invalid version string: " + versionStr); + version = Version.of(versionStr); + } - String plainQuery = part; - if (version != null) - plainQuery = part.substring(0, versionSeparatorIndex); + String plainQuery = bodyAndVersion; + if (versionStr != null) + plainQuery = bodyAndVersion.substring(0, versionSeparatorIndex); return new QueryContext(resolverName, plainQuery, version); } From fbd1e1afc30533c8bf1e5c9ced02cb406082b033 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 21 Nov 2022 01:55:23 +0900 Subject: [PATCH 473/745] feat(daemon): Plugin upgrader --- .../impls/upgrade/PluginUpgrader.java | 295 ++++++++++++++++++ .../impls/upgrade/UpgradeArgument.java | 25 ++ .../impls/upgrade/UpgradeErrorCause.java | 40 +++ .../installer/impls/upgrade/UpgradeTasks.java | 36 +++ .../upgrade/signals/InstallFailedSignal.java | 23 ++ .../upgrade/signals/PluginNotFoundSignal.java | 30 ++ .../upgrade/signals/ResolveFailedSignal.java | 40 +++ .../signals/UpdateQueryRetrievedSignal.java | 26 ++ .../upgrade/signals/UpgradeReadySignal.java | 53 ++++ 9 files changed, 568 insertions(+) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeArgument.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeTasks.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/ResolveFailedSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java new file mode 100644 index 00000000..2b9cc283 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java @@ -0,0 +1,295 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade; + +import net.kunmc.lab.kpm.KPMDaemon; +import net.kunmc.lab.kpm.installer.AbstractInstaller; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.install.InstallArgument; +import net.kunmc.lab.kpm.installer.impls.install.InstallTasks; +import net.kunmc.lab.kpm.installer.impls.install.PluginInstaller; +import net.kunmc.lab.kpm.installer.impls.uninstall.PluginUninstaller; +import net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallTasks; +import net.kunmc.lab.kpm.installer.impls.uninstall.UninstallArgument; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.InstallFailedSignal; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.PluginNotFoundSignal; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.ResolveFailedSignal; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.UpgradeReadySignal; +import net.kunmc.lab.kpm.installer.signals.assertion.IgnoredPluginSignal; +import net.kunmc.lab.kpm.installer.task.TaskFailedException; +import net.kunmc.lab.kpm.installer.task.tasks.lookup.LookupArgument; +import net.kunmc.lab.kpm.installer.task.tasks.lookup.LookupResult; +import net.kunmc.lab.kpm.installer.task.tasks.lookup.PluginLookupTask; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveArgument; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveResult; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveTask; +import net.kunmc.lab.kpm.meta.PluginMeta; +import net.kunmc.lab.kpm.meta.PluginMetaProvider; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.signal.SignalHandleManager; +import net.kunmc.lab.kpm.utils.KPMCollectors; +import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * プラグインをアップグレードするインストーラーの実装です。 + * アップグレードは主に以下の流れで動作します。 + * + *

      + *
    1. {@link UpgradeTasks#SEARCHING_PLUGIN} - アップグレード対象のプラグインを検索する。
    2. + *
    3. {@link UpgradeTasks#CHECKING_ENVIRONMENT} - アップグレードの環境を確認する。
    4. + *
    5. {@link UpgradeTasks#RETRIEVING_METADATA} - 検索したプラグインのメタデータを取得する。
    6. + *
    7. {@link UpgradeTasks#RETRIEVING_UPDATE_QUERY} - プラグインのアップデートクエリを取得する。
    8. + *
    9. {@link UpgradeTasks#RESOLVING_PLUGIN} - アップデートクエリを解決する。
    10. + *
    11. {@link UpgradeTasks#UNINSTALLING_PLUGIN} - プラグインをアンインストールする。
    12. + *
    + *

    + * また、このインストーラは{@link net.kunmc.lab.kpm.installer.impls.uninstall.PluginUninstaller} と {@link net.kunmc.lab.kpm.installer.impls.install.PluginInstaller} を内部で呼び出します。 + * そのため、対応したシグナルハンドラを登録しておく必要があります。 + */ +public class PluginUpgrader extends AbstractInstaller +{ + public PluginUpgrader(@NotNull KPMDaemon daemon, @NotNull SignalHandleManager signalHandler) throws IOException + { + super(daemon, signalHandler); + } + + @Override + public InstallResult execute(@NotNull UpgradeArgument argument) throws TaskFailedException + { + List targetPlugins; + // region Search plugins + this.progress.setCurrentTask(UpgradeTasks.SEARCHING_PLUGIN); + + targetPlugins = this.searchPlugin(argument.getTargetPlugins()); + if (targetPlugins == null) + return this.error(UpgradeErrorCause.PLUGIN_NOT_FOUND); + // endregion + + // region Do environment check + this.progress.setCurrentTask(UpgradeTasks.CHECKING_ENVIRONMENT); + for (Plugin plugin : targetPlugins) + { + UpgradeErrorCause mayEnvErrorCause = this.checkEnvironment(plugin.getDescription()); + if (mayEnvErrorCause != null) + return this.error(mayEnvErrorCause); + } + // endregion + + Map updateQueries; + // region Retrieve update queries + this.progress.setCurrentTask(UpgradeTasks.RETRIEVING_METADATA); + HashMap pluginMetas = this.retrievePluginMetadata(targetPlugins); + + this.progress.setCurrentTask(UpgradeTasks.RETRIEVING_UPDATE_QUERY); + updateQueries = pluginMetas.entrySet().stream().parallel() + .map(entry -> + Pair.of( + entry.getKey(), + entry.getValue().getResolveQuery() == null ? entry.getKey().getName(): + entry.getValue().getResolveQuery() + ) + ) + .collect(KPMCollectors.toPairHashMap()); + // endregion + + Map resolveResults; + // region Fetch updates + resolveResults = this.resolvePlugins(updateQueries); + if (resolveResults == null) + return this.error(UpgradeErrorCause.PLUGIN_RESOLVE_FAILED); + + // endregion + + // Notify upgrade is ready + resolveResults = this.notifyUpgradeReady(resolveResults); + if (resolveResults.isEmpty()) // Cancelled + return this.error(UpgradeErrorCause.CANCELLED); + + // region Uninstall plugins + this.progress.setCurrentTask(UpgradeTasks.UNINSTALLING_PLUGIN); + + PluginUninstaller uninstaller; + try + { + uninstaller = new PluginUninstaller(this.daemon, this.signalHandler); + } + catch (IOException e) + { + e.printStackTrace(); + return this.error(UpgradeErrorCause.UNINSTALLER_INSTANTIATION_FAILED); + } + + InstallResult uninstallResult = uninstaller.run( + UninstallArgument.builder(targetPlugins.toArray(new Plugin[0])) + .skipExcludeChecks(true) + .forceUninstall(true) + .build()); + + Arrays.stream(uninstallResult.getRemoved()).parallel() + .forEach(this.progress::addPending); + + if (!uninstallResult.isSuccess()) + return this.error(UpgradeErrorCause.UNINSTALL_FAILED); + // endregion + + // region Install plugins + this.progress.setCurrentTask(UpgradeTasks.INSTALLING_PLUGIN); + for (SuccessResult resolveResult : resolveResults.values()) + { + PluginInstaller installer; + try + { + installer = new PluginInstaller(this.daemon, this.signalHandler); + } + catch (IOException e) + { + e.printStackTrace(); + return this.error(UpgradeErrorCause.INSTALLER_INSTANTIATION_FAILED); + } + + InstallResult installResult = installer.run( + InstallArgument.builder(resolveResult) + .forceInstall(true) + .build()); + + if (installResult.isSuccess()) + continue; + + // Install failed + InstallFailedSignal signal = new InstallFailedSignal(installResult); + this.postSignal(signal); + if (!signal.isContinueUpgrade()) + return this.error(UpgradeErrorCause.INSTALL_FAILED); + } + + // endregion + + return this.success(); + } + + @Nullable + private UpgradeErrorCause checkEnvironment(PluginDescriptionFile pluginDescription) + { + String pluginName = pluginDescription.getName(); + + // region Check if the plugin is marked as excluded + if (this.isPluginIgnored(pluginName)) + { + IgnoredPluginSignal ignoredPluginSignal = new IgnoredPluginSignal(pluginDescription); + this.postSignal(ignoredPluginSignal); + + if (ignoredPluginSignal.isContinueInstall()) + return UpgradeErrorCause.PLUGIN_EXCLUDED; + } + // endregion + + return null; // No error with environment. + } + + private Map notifyUpgradeReady(@NotNull Map resolveResults) + { + UpgradeReadySignal resolvedSignal = new UpgradeReadySignal(resolveResults); + this.postSignal(resolvedSignal); + + return resolvedSignal.getPlugins().stream().parallel() + .filter(UpgradeReadySignal.ResolvedPluginElement::isContinueUpgrade) + .map(element -> Pair.of(element.getPlugin(), element.getResolveResult())) + .collect(KPMCollectors.toPairHashMap()); + } + + private HashMap retrievePluginMetadata(@NotNull List targets) + { + PluginMetaProvider metaProvider = this.daemon.getPluginMetaManager().getProvider(); + return targets.stream() + .map(plugin -> Pair.of(plugin, metaProvider.getPluginMeta(plugin.getName()))) + .collect(KPMCollectors.toPairHashMap()); + } + + private List searchPlugin(@Nullable List targets) throws TaskFailedException + { + if (targets == null) + return new ArrayList<>(Arrays.asList(Bukkit.getPluginManager().getPlugins())); + + LookupResult lookupResult = (LookupResult) this.submitter(UpgradeTasks.SEARCHING_PLUGIN, new PluginLookupTask(this)) + .submitAll(new LookupArgument(targets.toArray(new String[0]))); + + HashMap foundPlugins = lookupResult.getPlugins(); + assert foundPlugins != null; + + targets.removeAll(foundPlugins.keySet()); + + if (!targets.isEmpty()) + { + boolean isContinue = targets.stream().allMatch(target -> { + PluginNotFoundSignal signal = new PluginNotFoundSignal(target); + PluginUpgrader.this.postSignal(signal); + return signal.isContinueUpgrade(); + }); + + if (!isContinue) + return null; + } + + return new ArrayList<>(foundPlugins.values()); + } + + private Map resolvePlugins(Map queries) + { + Map resolvedQueries = new HashMap<>(); + + try + { + for (Map.Entry entry : queries.entrySet()) + { + Plugin plugin = entry.getKey(); + String query = entry.getValue(); + + ResolveResult result = this.resolveOne(plugin, query); + + resolvedQueries.put(plugin, (SuccessResult) result); + } + } + catch (TaskFailedException ignored) + { + resolvedQueries = null; + } + + return resolvedQueries; + } + + private ResolveResult resolveOne(Plugin plugin, String query) throws TaskFailedException + { + try + { + PluginResolveResult result = (PluginResolveResult) this.submitter(UpgradeTasks.RESOLVING_PLUGIN, new PluginResolveTask(this)) + .submitAll(new PluginResolveArgument(query)); + + return result.getResolveResult(); + } + catch (TaskFailedException e) + { + assert e.getResult() instanceof PluginResolveResult; + PluginResolveResult result = (PluginResolveResult) e.getResult(); + + assert result.getErrorCause() != null; + ResolveFailedSignal signal = new ResolveFailedSignal(plugin, result.getErrorCause(), result.getState()); + this.postSignal(signal); + + if (signal.isContinueUpgrade()) + return null; + else + throw e; + } + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeArgument.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeArgument.java new file mode 100644 index 00000000..43f7b263 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeArgument.java @@ -0,0 +1,25 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.kpm.installer.AbstractInstallerArgument; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +/** + * アップグレードの引数を格納するクラスです。 + */ +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class UpgradeArgument extends AbstractInstallerArgument +{ + /** + * アップグレード対象のプラグインの名前のリストです。 + * これをnullにすると、全てのプラグインをアップグレードします。 + */ + @Nullable + private List targetPlugins; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java new file mode 100644 index 00000000..5ee8819e --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java @@ -0,0 +1,40 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade; + +/** + * アップグレードのエラーを表す列挙型です。 + */ +public enum UpgradeErrorCause +{ + /** + * 指定されたプラグインが見つかりませんでした。 + */ + PLUGIN_NOT_FOUND, + /** + * プラグインの解決に失敗しました。 + */ + PLUGIN_RESOLVE_FAILED, + /** + * アップグレードがキャンセルされました。 + */ + CANCELLED, + /** + * プラグインが構成等で除外されています。 + */ + PLUGIN_EXCLUDED, + /** + * アンインストーラのインスタンス化に失敗しました。 + */ + UNINSTALLER_INSTANTIATION_FAILED, + /** + * アンインストールに失敗しました。 + */ + UNINSTALL_FAILED, + /** + * インストーラのインスタンス化に失敗しました。 + */ + INSTALLER_INSTANTIATION_FAILED, + /** + * インストールに失敗しました。 + */ + INSTALL_FAILED, +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeTasks.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeTasks.java new file mode 100644 index 00000000..0a29ee4c --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeTasks.java @@ -0,0 +1,36 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade; + +/** + * アップグレードのタスクを表す列挙型です。 + */ +public enum UpgradeTasks +{ + /** + * アップグレード対象の検索中であることを示します。 + */ + SEARCHING_PLUGIN, + /** + * 環境の状態を確認中であることを示します。 + */ + CHECKING_ENVIRONMENT, + /** + * アップグレード対象のメタデータの取得中であることを示します。 + */ + RETRIEVING_METADATA, + /** + * アップグレード対象のクエリの取得中であることを示します。 + */ + RETRIEVING_UPDATE_QUERY, + /** + * プラグインの解決中であることを示します。 + */ + RESOLVING_PLUGIN, + /** + * プラグインのアンインストール中であることを示します。 + */ + UNINSTALLING_PLUGIN, + /** + * プラグインのインストール中であることを示します。 + */ + INSTALLING_PLUGIN, +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java new file mode 100644 index 00000000..1b867fc8 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java @@ -0,0 +1,23 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade.signals; + +import lombok.Data; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.install.InstallTasks; +import net.kunmc.lab.kpm.signal.Signal; + +/** + * インストールに失敗したことを表すシグナルです。 + */ +@Data +public class InstallFailedSignal implements Signal +{ + /** + * 失敗した原因の特定のためのインストール失敗結果です。 + */ + private final InstallResult failedResult; + + /** + * このままアップグレードを続けるかどうかのフラグです。 + */ + private boolean continueUpgrade; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java new file mode 100644 index 00000000..f85db250 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java @@ -0,0 +1,30 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade.signals; + +import lombok.Data; +import net.kunmc.lab.kpm.signal.Signal; +import org.jetbrains.annotations.NotNull; + +/** + * 指定されたプラグインが見つからなかったことを示すシグナルです。 + */ +@Data +public class PluginNotFoundSignal implements Signal +{ + /** + * 指定されたプラグインの名前です。 + */ + @NotNull + private final String specifiedPluginName; + + /** + * アップグレードを続けるかどうかのフラグです。 + * このフラグをfalseにすると、アップグレードは中断され、{@link net.kunmc.lab.kpm.installer.impls.upgrade.PluginUpgrader}は失敗します。 + */ + private boolean continueUpgrade; + + public PluginNotFoundSignal(@NotNull String specifiedPluginName) + { + this.specifiedPluginName = specifiedPluginName; + this.continueUpgrade = true; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/ResolveFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/ResolveFailedSignal.java new file mode 100644 index 00000000..7d9ce982 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/ResolveFailedSignal.java @@ -0,0 +1,40 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade.signals; + +import lombok.Getter; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveErrorCause; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.PluginResolveState; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +/** + * 依存関係の解決に失敗したことを示すシグナルです。 + */ +@Getter +public class ResolveFailedSignal extends PluginNotFoundSignal +{ + /** + * 依存関係の解決に失敗したプラグインです。 + */ + @NotNull + private final Plugin plugin; + + /** + * 依存関係の解決に失敗した理由です。 + */ + @NotNull + private final PluginResolveErrorCause errorCause; + + /** + * 依存関係の解決に失敗したときの状態です。 + */ + @NotNull + private final PluginResolveState resolveStateState; + + public ResolveFailedSignal(@NotNull Plugin plugin, @NotNull PluginResolveErrorCause errorCause, @NotNull PluginResolveState resolveStateState) + { + super(plugin.getDescription().getName()); + this.plugin = plugin; + this.errorCause = errorCause; + this.resolveStateState = resolveStateState; + } +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java new file mode 100644 index 00000000..db741cf4 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java @@ -0,0 +1,26 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade.signals; + +import lombok.Data; +import net.kunmc.lab.kpm.signal.Signal; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * アップグレードのクエリを取得したことを示すシグナルです。 + */ +@Data +public class UpdateQueryRetrievedSignal implements Signal +{ + /** + * アップグレード対象のプラグインです。 + */ + @NotNull + private final Plugin plugin; + + /** + * アップグレードに使用するクエリです。 + */ + @Nullable + private String query; +} diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java new file mode 100644 index 00000000..edafb037 --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java @@ -0,0 +1,53 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade.signals; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; +import net.kunmc.lab.kpm.signal.Signal; +import org.bukkit.plugin.Plugin; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * アップグレードの準備が完了したことを示すシグナルです。 + */ +@Data +public class UpgradeReadySignal implements Signal +{ + private final List plugins; + + public UpgradeReadySignal(Map resolveResult) + { + this.plugins = resolveResult.entrySet().stream() + .map(e -> new ResolvedPluginElement(e.getKey(), e.getValue())) + .collect(Collectors.toList()); + } + + public void setContinueUpgrade(boolean value) + { + this.plugins.forEach(e -> e.setContinueUpgrade(value)); + } + + @Data + @AllArgsConstructor + public static class ResolvedPluginElement + { + /** + * アップグレード対象のプラグインです。 + */ + private final Plugin plugin; + /** + * アップグレードのために解決された解決結果です。 + */ + private final SuccessResult resolveResult; + + private boolean continueUpgrade; + + public ResolvedPluginElement(Plugin plugin, SuccessResult resolveResult) + { + this(plugin, resolveResult, true); + } + } +} From e7053bf85241ba61c9528a282708a19d991ee4bc Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 21 Nov 2022 02:15:25 +0900 Subject: [PATCH 474/745] fix(daemon): Versioning degrade --- .../kpm/resolver/impl/GitHubURLResolver.java | 20 +++++++++++++------ .../lab/kpm/commands/CommandInstall.java | 2 +- .../commands/debug/CommandInstallDebug.java | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java index b5c928b1..5cb6db8e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/GitHubURLResolver.java @@ -154,7 +154,7 @@ else if (result instanceof ErrorResult) .orElse(null); } - private ResolveResult processGitHubAPI(String owner, String repositoryName, String repository, String tag, @Nullable String version) + private ResolveResult processGitHubAPI(String owner, String repositoryName, String repository, String tag, @Nullable Version version) { String apiURL; if (tag != null) @@ -218,7 +218,7 @@ else if (isNoAssets) return new MultiResult(this, results.toArray(new ResolveResult[0])); } - private ResolveResult buildResultSingle(String owner, String repositoryName, JsonObject object, @Nullable String queryVersion) + private ResolveResult buildResultSingle(String owner, String repositoryName, JsonObject object, @Nullable Version queryVersion) { List results = new ArrayList<>(); @@ -227,14 +227,22 @@ private ResolveResult buildResultSingle(String owner, String repositoryName, Jso String version = object.get("tag_name").getAsString(); long releaseId = object.get("id").getAsLong(); - if (queryVersion != null && !queryVersion.equalsIgnoreCase(version) && - !("v" + queryVersion).equalsIgnoreCase(queryVersion) && !queryVersion.equalsIgnoreCase("v" + queryVersion)) - return new ErrorResult(this, ErrorResult.ErrorCause.VERSION_MISMATCH, ResolveResult.Source.GITHUB); + if (queryVersion != null && !(Version.isValidVersionString(version) && + Version.of(version).isEqualTo(queryVersion))) + return new ErrorResult( + this, + ErrorResult.ErrorCause.VERSION_MISMATCH, + ResolveResult.Source.GITHUB + ); JsonArray assets = object.getAsJsonArray("assets"); if (assets.size() == 0) - return new ErrorResult(this, ErrorResult.ErrorCause.ASSET_NOT_FOUND, ResolveResult.Source.GITHUB); + return new ErrorResult( + this, + ErrorResult.ErrorCause.ASSET_NOT_FOUND, + ResolveResult.Source.GITHUB + ); for (JsonElement asset : assets) { diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInstall.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInstall.java index b937148e..1db13ada 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInstall.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandInstall.java @@ -28,7 +28,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String query = args[0]; Runner.runAsync(() -> - this.plugin.getHeadInstallers().runInstall(terminal, new InstallArgument(query)) + this.plugin.getHeadInstallers().runInstall(terminal, InstallArgument.builder(query).build()) ); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandInstallDebug.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandInstallDebug.java index c2058073..c29cfa39 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandInstallDebug.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/debug/CommandInstallDebug.java @@ -41,7 +41,8 @@ public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, DebugSignalHandler.toManager(terminal) ); - InstallResult installResult = installer.execute(new InstallArgument(query)); + InstallResult installResult = + installer.execute(InstallArgument.builder(query).build()); if (installResult instanceof InstallFailedInstallResult) { From ab3a8d827f731c4520c48141a10074a1cc21a26c Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 21 Nov 2022 02:28:52 +0900 Subject: [PATCH 475/745] fix(daemon): Plugin resolving degrade --- .../net/kunmc/lab/kpm/resolver/PluginResolver.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java index cdbff923..48edfdee 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/PluginResolver.java @@ -96,26 +96,20 @@ public ResolveResult pickUpOne(MultiResult multiResult) private ResolveResult actuallyResolve(List resolvers, QueryContext queryContext) { - URL url = null; - - String resolverName = queryContext.getResolverName(); - if (resolverName != null) - url = toURL(queryContext.getQuery()); - - ResolveResult result = this.resolves(resolvers, queryContext, url); + ResolveResult result = this.resolves(resolvers, queryContext); if (result instanceof ErrorResult) { ErrorResult error = (ErrorResult) result; if (error.getCause() != ErrorResult.ErrorCause.VERSION_MISMATCH) - result = this.resolves(this.fallbackResolvers, queryContext, url); + result = this.resolves(this.fallbackResolvers, queryContext); } return result; } - private ResolveResult resolves(List resolvers, QueryContext queryContext, URL url) + private ResolveResult resolves(List resolvers, QueryContext queryContext) { List finishedResolvers = new ArrayList<>(); @@ -127,6 +121,7 @@ private ResolveResult resolves(List resolvers, QueryContext queryC finishedResolvers.add(resolver); + URL url = toURL(queryContext.getQuery()); ResolveResult result = this.actuallyResolve(resolver, queryContext, url); if (result == null || result instanceof PipeResult) From 4b7f6f3462497e32107bbd9b2fd20c00b39b0c9e Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 21 Nov 2022 02:50:16 +0900 Subject: [PATCH 476/745] fix(daemon): Progressbar degrade --- .../handlers/common/DownloadingSignalHandler.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/DownloadingSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/DownloadingSignalHandler.java index 844ff3ca..e3d495db 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/DownloadingSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/common/DownloadingSignalHandler.java @@ -32,8 +32,13 @@ private void startDownloads(String id) this.currentDownload = id; this.downloadTotalSize = 0; this.downloadStarted = System.currentTimeMillis(); - this.downloadProgressBar = this.terminal.createProgressbar("ダウンロード"); - this.downloadProgressBar.setProgressMax(100); + if (this.terminal.isPlayer()) + { + this.downloadProgressBar = this.terminal.createProgressbar("ダウンロード"); + this.downloadProgressBar.setProgressMax(100); + } + else + this.downloadProgressBar = null; } private void addDownloadArtifact(String url, long size) @@ -69,6 +74,9 @@ public void onDownloadingSignal(DownloadProgressSignal signal) this.addDownloadArtifact(signal.getUrl(), signal.getTotalSize()); } + if (this.downloadProgressBar == null) + return; + double percent = (double) signal.getDownloaded() / signal.getTotalSize(); this.downloadProgressBar.setProgress((int) (percent * 100)); // max 100 } From 4965a3bbc26a8f9a2741001f3b876b17cd0d4af4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Mon, 21 Nov 2022 17:38:56 +0900 Subject: [PATCH 477/745] refactor(daemon): Force cast in TaskSubmitter --- .../installer/impls/clean/GarbageCleaner.java | 2 +- .../impls/uninstall/PluginUninstaller.java | 35 +++++++++---------- .../installer/impls/update/AliasUpdater.java | 2 +- .../impls/upgrade/PluginUpgrader.java | 4 +-- .../lab/kpm/installer/task/TaskChain.java | 9 +++-- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleaner.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleaner.java index be86c3bb..4c3ec887 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleaner.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/clean/GarbageCleaner.java @@ -53,7 +53,7 @@ public InstallResult execute(@NotNull CleanArgument argument) throws .map(Plugin::getName) .collect(Collectors.toList()); - GarbageCleanResult result = (GarbageCleanResult) this.submitter( + GarbageCleanResult result = this.submitter( CleanTasks.SEARCHING_GARBAGE, new GarbageSearchTask(this) ) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java index b92dd0a5..e2b550da 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/PluginUninstaller.java @@ -142,24 +142,23 @@ public InstallResult execute(@NotNull UninstallArgument argument Map namePluginMap = plugins.stream().parallel() .collect(Collectors.toMap(Plugin::getName, pl -> pl)); - UnInstallResult uninstallResult = (UnInstallResult) - this.submitter( - UnInstallTasks.COMPUTING_UNINSTALL_ORDER, - new DependsComputeOrderTask(this) - ) - .then( - UnInstallTasks.UNINSTALLING_PLUGINS, - new UnInstallTask(this) - ) - .bridgeArgument(computeResult -> { - List ordered = computeResult.getOrder(); - List orderedPlugins = ordered.stream() - .map(element -> namePluginMap.get(element.getPluginName())) - .collect(KPMCollectors.toReversedList()); // Convert load order to unload order. - - return new UnInstallArgument(orderedPlugins); - }) - .submitAll(new DependsComputeOrderArgument(computeOrderTarget)); + UnInstallResult uninstallResult = this.submitter( + UnInstallTasks.COMPUTING_UNINSTALL_ORDER, + new DependsComputeOrderTask(this) + ) + .then( + UnInstallTasks.UNINSTALLING_PLUGINS, + new UnInstallTask(this) + ) + .bridgeArgument(computeResult -> { + List ordered = computeResult.getOrder(); + List orderedPlugins = ordered.stream() + .map(element -> namePluginMap.get(element.getPluginName())) + .collect(KPMCollectors.toReversedList()); // Convert load order to unload order. + + return new UnInstallArgument(orderedPlugins); + }) + .submitAll(new DependsComputeOrderArgument(computeOrderTarget)); // endregion return this.success(new PluginUninstallSucceedResult(this.progress, uninstallResult)); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/AliasUpdater.java index 7f620b3f..cf066970 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/AliasUpdater.java @@ -38,7 +38,7 @@ public InstallResult execute(@NotNull UpdateArgument argument) thro Map remotes = argument.getRemotes(); UpdateAliasesResult result = - (UpdateAliasesResult) this.submitter( + this.submitter( UpdateTasks.DOWNLOADING_SOURCES, new SourceDownloadTask(this) ) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java index 2b9cc283..b8cf940d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java @@ -221,7 +221,7 @@ private List searchPlugin(@Nullable List targets) throws TaskFai if (targets == null) return new ArrayList<>(Arrays.asList(Bukkit.getPluginManager().getPlugins())); - LookupResult lookupResult = (LookupResult) this.submitter(UpgradeTasks.SEARCHING_PLUGIN, new PluginLookupTask(this)) + LookupResult lookupResult = this.submitter(UpgradeTasks.SEARCHING_PLUGIN, new PluginLookupTask(this)) .submitAll(new LookupArgument(targets.toArray(new String[0]))); HashMap foundPlugins = lookupResult.getPlugins(); @@ -272,7 +272,7 @@ private ResolveResult resolveOne(Plugin plugin, String query) throws TaskFailedE { try { - PluginResolveResult result = (PluginResolveResult) this.submitter(UpgradeTasks.RESOLVING_PLUGIN, new PluginResolveTask(this)) + PluginResolveResult result = this.submitter(UpgradeTasks.RESOLVING_PLUGIN, new PluginResolveTask(this)) .submitAll(new PluginResolveArgument(query)); return result.getResolveResult(); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskChain.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskChain.java index 7ccf0def..eac2d9dd 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskChain.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/TaskChain.java @@ -172,11 +172,16 @@ public TaskChain bridgeArgument(@NotNull Function argu * @throws TaskFailedException タスクの実行に失敗した場合 * @throws IllegalStateException タスクチェーンが設定されていない場合 */ - public @NotNull TaskResult submitAll(@NotNull TaskArgument argument) throws TaskFailedException, IllegalStateException + @SuppressWarnings("unchecked") + public @NotNull R submitAll(@NotNull TaskArgument argument) throws TaskFailedException, IllegalStateException { if (this.first == null) throw new IllegalStateException("No task chain defined"); - return this.first.submitFromThis(argument); + + // Suppress unchecked cast warning because this method calls tasks from the first task to the last task(this task). + // If any error occurs, it will be thrown as TaskFailedException, so this method will not return any value. + // So this method returns the last value type of the task chain, the type is R. + return (R) this.first.submitFromThis(argument); } } From 5c82b3d25ae420393ae1e86ebc578502a4a5b2a0 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 24 Nov 2022 01:15:01 +0900 Subject: [PATCH 478/745] =?UTF-8?q?chore:=20=E3=83=A9=E3=82=A4=E3=82=BB?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=81=AE=E5=B9=B4=E3=82=92=E4=B8=8A=E3=81=92?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index bd8e250e..1765cd63 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 TeamKun., Peyang +Copyright (c) 2021-2022 TeamKun., Peyang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 65696cc07468131e4ad479020b125ad3265c1a7d Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 01:30:58 +0900 Subject: [PATCH 479/745] docs: Undoc HeadSignalHandler --- .../kunmc/lab/kpm/signal/HeadSignalHandlers.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java index ff2bad72..bf07fac3 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java @@ -25,9 +25,6 @@ import java.util.Arrays; import java.util.List; -/** - * シグナルを受け取り, 処理を行うクラス をまとめるためのユーティリティクラスです. - */ public class HeadSignalHandlers { private static List createHandlersList(List base, Object... handlers) @@ -57,12 +54,6 @@ public static List getCommonHandlers(@NotNull Terminal terminal) ); } - /** - * インストールに使用するハンドラを返します. - * - * @param terminal ターミナル - * @return インストールに使用するハンドラ - */ public static List getInstallHandlers(@NotNull Terminal terminal) { return createHandlersList( @@ -76,12 +67,6 @@ public static List getInstallHandlers(@NotNull Terminal terminal) ); } - /** - * アンインストールに使用するハンドラを返します. - * - * @param terminal ターミナル - * @return アンインストールに使用するハンドラ - */ public static List getUninstallHandlers(@NotNull Terminal terminal) { return createHandlersList( From 1ec07ab0c1a26318d571a7db720a762345162ca5 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 02:04:29 +0900 Subject: [PATCH 480/745] feat: Early GC of PluginUpgrader --- .../lab/kpm/installer/impls/upgrade/PluginUpgrader.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java index b8cf940d..3d2af54c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java @@ -175,6 +175,15 @@ public InstallResult execute(@NotNull UpgradeArgument argument) th // endregion + // region clean VM(Unlink old Plugin data) + targetPlugins.clear(); + resolveResults.clear(); + updateQueries.clear(); + pluginMetas.clear(); + + System.gc(); + // endregion + return this.success(); } From 0424704e67c16c19c91ae9fb67181df93036f98b Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 02:26:32 +0900 Subject: [PATCH 481/745] docs: Undoc HeadInstallers --- .../net/kunmc/lab/kpm/HeadInstallers.java | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java index 44febc3d..046ecd94 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java @@ -50,12 +50,6 @@ public class HeadInstallers } } - /** - * インストールを実行します。 - * - * @param terminal ターミナル - * @param argument インストールの引数 - */ public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argument) { SignalHandleManager handleManager = new SignalHandleManager(); @@ -76,12 +70,6 @@ public void runInstall(@NotNull Terminal terminal, @NotNull InstallArgument argu this.headRun(terminal, installer, argument); } - /** - * アンインストールを実行します。 - * - * @param terminal ターミナル - * @param argument アンインストールするプラグインのクエリ - */ public void runUninstall(@NotNull Terminal terminal, @NotNull UninstallArgument argument) { SignalHandleManager handleManager = new SignalHandleManager(); @@ -122,12 +110,6 @@ public void runUpdate(@NotNull Terminal terminal, @NotNull UpdateArgument argume this.headRun(terminal, updater, argument); } - /** - * プラグインの自動削除を実行します。 - * - * @param terminal ターミナル - * @param argument 自動削除の引数 - */ public void runAutoRemove(@NotNull Terminal terminal, @NotNull AutoRemoveArgument argument) { SignalHandleManager handleManager = new SignalHandleManager(); @@ -148,13 +130,6 @@ public void runAutoRemove(@NotNull Terminal terminal, @NotNull AutoRemoveArgumen this.headRun(terminal, autoRemover, argument); } - /** - * 不要データ(ガベージ)の削除を実行します。 - * - * @param terminal ターミナル - * @param argument 不要データ削除の引数 - * @throws IllegalStateException インストールが進行中の場合 - */ public void runGarbageClean(@NotNull Terminal terminal, @NotNull CleanArgument argument) throws IllegalStateException { SignalHandleManager handleManager = new SignalHandleManager(); @@ -175,13 +150,6 @@ public void runGarbageClean(@NotNull Terminal terminal, @NotNull CleanArgument a this.headRun(terminal, garbageCleaner, argument); } - /** - * トークンの登録を実行します。 - * - * @param terminal ターミナル - * @param argument トークン登録の引数 - * @throws IllegalStateException インストールが進行中の場合 - */ public void runRegister(@NotNull Terminal terminal, @NotNull RegisterArgument argument) throws IllegalStateException { SignalHandleManager handleManager = new SignalHandleManager(); From ca714395aedd762769530f17be6fdd3083db5f91 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 02:30:12 +0900 Subject: [PATCH 482/745] feat(plugin): Head of Upgrader --- .../net/kunmc/lab/kpm/HeadInstallers.java | 22 ++++ .../kunmc/lab/kpm/TeamKunPluginManager.java | 2 + .../lab/kpm/commands/CommandUpgrade.java | 64 +++++++++++ .../lab/kpm/signal/HeadSignalHandlers.java | 36 +++++- .../upgrade/UpgradeFinishedSignalHandler.java | 83 ++++++++++++++ .../upgrade/UpgradeSignalHandler.java | 104 ++++++++++++++++++ 6 files changed, 307 insertions(+), 4 deletions(-) create mode 100644 KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUpgrade.java create mode 100644 KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeFinishedSignalHandler.java create mode 100644 KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java index 046ecd94..369e4226 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/HeadInstallers.java @@ -17,6 +17,8 @@ import net.kunmc.lab.kpm.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.kpm.installer.impls.update.AliasUpdater; import net.kunmc.lab.kpm.installer.impls.update.UpdateArgument; +import net.kunmc.lab.kpm.installer.impls.upgrade.PluginUpgrader; +import net.kunmc.lab.kpm.installer.impls.upgrade.UpgradeArgument; import net.kunmc.lab.kpm.signal.HeadSignalHandlers; import net.kunmc.lab.kpm.signal.SignalHandleManager; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; @@ -169,4 +171,24 @@ public void runRegister(@NotNull Terminal terminal, @NotNull RegisterArgument ar this.headRun(terminal, register, argument); } + + public void runUpgrade(@NotNull Terminal terminal, @NotNull UpgradeArgument argument) throws IllegalStateException + { + SignalHandleManager handleManager = new SignalHandleManager(); + HeadSignalHandlers.getUpgraderHandlers(terminal).forEach(handleManager::register); + + PluginUpgrader upgrader; + try + { + upgrader = new PluginUpgrader(this.daemon, handleManager); + } + catch (IOException e) + { + e.printStackTrace(); + terminal.error("インストーラの初期化に失敗しました:" + e.getMessage()); + return; + } + + this.headRun(terminal, upgrader, argument); + } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java index 2f69d030..d48a59ea 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java @@ -12,6 +12,7 @@ import net.kunmc.lab.kpm.commands.CommandStatus; import net.kunmc.lab.kpm.commands.CommandUninstall; import net.kunmc.lab.kpm.commands.CommandUpdate; +import net.kunmc.lab.kpm.commands.CommandUpgrade; import net.kunmc.lab.peyangpaperutils.PeyangPaperUtils; import net.kunmc.lab.peyangpaperutils.lib.command.CommandManager; import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; @@ -47,6 +48,7 @@ public void registerCommands(CommandManager commandManager) commandManager.registerCommand("status", new CommandStatus(this.daemon)); commandManager.registerCommand("uninstall", new CommandUninstall(this), "remove", "rm"); commandManager.registerCommand("update", new CommandUpdate(this, this.daemon)); + commandManager.registerCommand("upgrade", new CommandUpgrade(this)); commandManager.registerCommand("debug", new CommandDebug()); } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUpgrade.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUpgrade.java new file mode 100644 index 00000000..48e3dac0 --- /dev/null +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/commands/CommandUpgrade.java @@ -0,0 +1,64 @@ +package net.kunmc.lab.kpm.commands; + +import lombok.AllArgsConstructor; +import net.kunmc.lab.kpm.TeamKunPluginManager; +import net.kunmc.lab.kpm.installer.impls.upgrade.UpgradeArgument; +import net.kunmc.lab.peyangpaperutils.lib.command.CommandBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@AllArgsConstructor +public class CommandUpgrade extends CommandBase +{ + private final TeamKunPluginManager plugin; + + @Override + public void onCommand(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + if (indicateArgsLengthInvalid(terminal, args, 0, 1)) + return; + + List targets = null; + if (args.length == 1) + targets = new ArrayList<>(Arrays.asList(args)); + + UpgradeArgument argument = new UpgradeArgument(targets); + Runner.runAsync(() -> + this.plugin.getHeadInstallers().runUpgrade(terminal, argument) + ); + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Terminal terminal, String[] args) + { + return null; + } + + @Override + public @Nullable String getPermission() + { + return "kpm.upgrade"; + } + + @Override + public TextComponent getHelpOneLine() + { + return of("プラグインをアップグレードします。"); + } + + @Override + public String[] getArguments() + { + return new String[]{ + optional("query", "string") + }; + } +} diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java index bf07fac3..e37bdf4a 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java @@ -18,18 +18,21 @@ import net.kunmc.lab.kpm.signal.handlers.uninstall.UninstallReadySignalHandler; import net.kunmc.lab.kpm.signal.handlers.uninstall.UninstallerSignalHandler; import net.kunmc.lab.kpm.signal.handlers.update.UpdateAliasesSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.upgrade.UpgradeSignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; public class HeadSignalHandlers { private static List createHandlersList(List base, Object... handlers) { List list = new ArrayList<>(base); + list.removeIf(Objects::isNull); list.addAll(Arrays.asList(handlers)); return list; } @@ -54,7 +57,7 @@ public static List getCommonHandlers(@NotNull Terminal terminal) ); } - public static List getInstallHandlers(@NotNull Terminal terminal) + public static List getInstallHandlers(@NotNull Terminal terminal, boolean handleFinish) { return createHandlersList( getCommonHandlers(terminal), @@ -63,21 +66,31 @@ public static List getInstallHandlers(@NotNull Terminal terminal) new CheckEnvSignalHandler(terminal), new DependenciesSignalHandler(terminal), new InstallerSignalHandler(terminal), - new InstallFinishedSignalHandler(terminal) + handleFinish ? new InstallFinishedSignalHandler(terminal): null ); } - public static List getUninstallHandlers(@NotNull Terminal terminal) + public static List getInstallHandlers(@NotNull Terminal terminal) + { + return getInstallHandlers(terminal, true); + } + + public static List getUninstallHandlers(@NotNull Terminal terminal, boolean handleFinish) { return createHandlersList( getCommonHandlers(terminal), new UninstallerSignalHandler(terminal), new PluginIsDependencySignalHandler(terminal), new UninstallReadySignalHandler(terminal), - new UninstallFinishedSignalHandler(terminal) + handleFinish ? new UninstallFinishedSignalHandler(terminal): null ); } + public static List getUninstallHandlers(@NotNull Terminal terminal) + { + return getUninstallHandlers(terminal, true); + } + public static List getUpdateHandlers(@NotNull Terminal terminal) { return createHandlersList( @@ -114,4 +127,19 @@ public static List getTokenRegistererHandlers(Terminal terminal) new TokenGenerateSignalHandler(terminal) ); } + + public static List getUpgraderHandlers(Terminal terminal, int targets) + { + return createHandlersList( + getCommonHandlers(terminal), + getInstallHandlers(terminal, false), + getUninstallHandlers(terminal, false), + new UpgradeSignalHandler(terminal, targets) + ); + } + + public static List getUpgraderHandlers(Terminal terminal) + { + return getUpgraderHandlers(terminal, -1); + } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeFinishedSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeFinishedSignalHandler.java new file mode 100644 index 00000000..7695d58d --- /dev/null +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeFinishedSignalHandler.java @@ -0,0 +1,83 @@ +package net.kunmc.lab.kpm.signal.handlers.upgrade; + +import net.kunmc.lab.kpm.Utils; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.InstallResult; +import net.kunmc.lab.kpm.installer.impls.upgrade.UpgradeErrorCause; +import net.kunmc.lab.kpm.installer.impls.upgrade.UpgradeTasks; +import net.kunmc.lab.kpm.signal.handlers.common.InstallFinishedSignalBase; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; + +public class UpgradeFinishedSignalHandler extends InstallFinishedSignalBase +{ + public UpgradeFinishedSignalHandler(Terminal terminal) + { + super(terminal); + this.setPrintResult(false); + } + + @Override + protected void onSuccess(InstallResult result) + { + if (!(result.getProgress().getCurrentTask() instanceof UpgradeTasks)) + return; + + Utils.printInstallStatistics(this.terminal, result); + } + + private boolean handleGeneralErrors(UpgradeErrorCause cause) + { + switch (cause) + { + case CANCELLED: + this.terminal.error("アップグレードがキャンセルされました。"); + return true; + case PLUGIN_NOT_FOUND: + this.terminal.error("指定されたプラグインが見つかりませんでした。"); + return true; + case INSTALL_FAILED: + this.terminal.error("プラグインのインストールに失敗しました。"); + return true; + case INSTALLER_INSTANTIATION_FAILED: + this.terminal.error("プラグインインストーラの生成に失敗しました。"); + return true; + case PLUGIN_RESOLVE_FAILED: + this.terminal.error("プラグインの解決に失敗しました。"); + return true; + case PLUGIN_EXCLUDED: + this.terminal.error("指定されたプラグインが除外リストに登録されています。"); + return true; + case UNINSTALL_FAILED: + this.terminal.error("プラグインのアンインストールに失敗しました。"); + return true; + case UNINSTALLER_INSTANTIATION_FAILED: + this.terminal.error("プラグインアンインストーラの生成に失敗しました。"); + return true; + default: + return false; + } + } + + @Override + protected void onFail(InstallFailedInstallResult result) + { + if (!(result.getProgress().getCurrentTask() instanceof UpgradeTasks)) + return; + + if (result.getException() != null) + { + this.terminal.error("アップグレード中に予期しないエラーが発生しました:%s", result.getException()); + Utils.printInstallStatistics(this.terminal, result); + return; + } + + if (result.getReason() instanceof UpgradeErrorCause && + this.handleGeneralErrors((UpgradeErrorCause) result.getReason())) + { + Utils.printInstallStatistics(this.terminal, result); + return; + } + + this.terminal.error("アップグレード中に予期しないエラーが発生しました。"); + } +} diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java new file mode 100644 index 00000000..fa6096ed --- /dev/null +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java @@ -0,0 +1,104 @@ +package net.kunmc.lab.kpm.signal.handlers.upgrade; + +import net.kunmc.lab.kpm.Utils; +import net.kunmc.lab.kpm.installer.InstallFailedInstallResult; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.InstallFailedSignal; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.PluginNotFoundSignal; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.ResolveFailedSignal; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.UpgradeReadySignal; +import net.kunmc.lab.kpm.signal.SignalHandler; +import net.kunmc.lab.kpm.signal.SignalHandlingUtils; +import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; +import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; + +import java.util.stream.Collectors; + +public class UpgradeSignalHandler +{ + // ignore UpdateQueryRetrievedSignal + + private final Terminal terminal; + private final int targetPluginCount; + private int currentPluginCount = 0; + private int currentPluginResolvedCount = 0; + + public UpgradeSignalHandler(Terminal terminal, int targetPlugins) + { + this.terminal = terminal; + this.targetPluginCount = targetPlugins; + } + + private boolean askCancelOrContinue(int currentCount) + { + + if (currentCount == this.targetPluginCount) // allow -1 + { + this.terminal.warn("プラグインのアップグレードを中止します。"); + return false; + } + else + { + this.terminal.info("この警告を無視してアップデートを続行できます。"); + return SignalHandlingUtils.askContinue(this.terminal); + } + } + + @SignalHandler + public void onPluginNotFound(PluginNotFoundSignal signal) + { + this.terminal.warn("プラグイン " + signal.getSpecifiedPluginName() + " が見つかりませんでした。"); + signal.setContinueUpgrade(this.askCancelOrContinue(++this.currentPluginCount)); + } + + @SignalHandler + public void onResolveFailed(ResolveFailedSignal signal) + { + this.terminal.warn("プラグイン " + signal.getPlugin().getName() + + " の解決は " + + signal.getErrorCause().name() + " で失敗しました。"); + signal.setContinueUpgrade(this.askCancelOrContinue(++this.currentPluginResolvedCount)); + } + + @SignalHandler + public void onUpgradeReady(UpgradeReadySignal signal) + { + this.terminal.writeLine( + ChatColor.GREEN + "以下のプラグインは「" + + ChatColor.YELLOW + "アップグレード" + + ChatColor.GREEN + "」されます。" + ); + + this.terminal.writeLine(" " + signal.getPlugins().stream() + .map(element -> { + Plugin plugin = element.getPlugin(); + return ChatColor.GREEN + plugin.getName() + " (" + + ChatColor.DARK_GREEN + plugin.getDescription().getVersion() + ChatColor.WHITE + " -> " + + ChatColor.YELLOW + element.getResolveResult().getVersion() + ChatColor.GREEN + ")"; + }) + .sorted() + .collect(Collectors.joining(" " + ChatColor.GREEN))); + + Utils.printInstallStatistics( + this.terminal, + 0, + 0, + signal.getPlugins().size(), + 0 + ); + + signal.setContinueUpgrade(SignalHandlingUtils.askContinue(this.terminal)); + } + + @SignalHandler + public void onInstallFailed(InstallFailedSignal signal) + { + InstallFailedInstallResult result = (InstallFailedInstallResult) signal.getFailedResult(); + + this.terminal.warn("プラグイン(不明) のアップグレードは " + + result.getTaskStatus() + " で " + result.getReason() + + "により失敗しました。"); + + signal.setContinueUpgrade(this.askCancelOrContinue(++this.currentPluginCount)); + } +} From 424d2723396e6c530ac0c36722d28a4df82e2996 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 02:44:13 +0900 Subject: [PATCH 483/745] fix(daemon): Degrade of progressbar using --- .../register/TokenGenerateSignalHandler.java | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenGenerateSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenGenerateSignalHandler.java index fcc3c065..de373d97 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenGenerateSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/register/TokenGenerateSignalHandler.java @@ -22,8 +22,13 @@ public class TokenGenerateSignalHandler public TokenGenerateSignalHandler(Terminal terminal) { this.terminal = terminal; - this.progressbar = terminal.createProgressbar("codeExpire"); - this.progressbar.setPrefix(ChatColor.GREEN + "コード有効期限: "); + if (terminal.isPlayer()) + { + this.progressbar = terminal.createProgressbar("codeExpire"); + this.progressbar.setPrefix(ChatColor.GREEN + "コード有効期限: "); + } + else + this.progressbar = null; } @SignalHandler @@ -66,45 +71,57 @@ public void onVerificationCodeReceived(VerificationCodeReceivedSignal signal) int expiresInSecInt = (int) expiresInSec; if (this.terminal.isPlayer()) + { this.terminal.showNotification(userCode, "GitHubでこのコードを入力して有効化してください。", expiresInSecInt * 1000 ); - this.progressbar.setProgressMax(expiresInSecInt); - this.progressbar.setProgress(expiresInSecInt); - this.progressbar.show(); + this.progressbar.setProgressMax(expiresInSecInt); + this.progressbar.setProgress(expiresInSecInt); + this.progressbar.show(); + } } @SignalHandler public void onVerificationCodeExpired(VerificationCodeExpiredSignal signal) { this.terminal.error("コードが失効しました: " + signal.getUserCode()); + this.terminal.info("コードを再取得するには /kpm register を実行してください。"); - this.progressbar.hide(); + if (!this.terminal.isPlayer()) + + this.progressbar.hide(); this.terminal.removeProgressbar("codeExpire"); } @SignalHandler public void onUserDoesntCompleteVerify(UserDoesntCompleteVerifySignal signal) { - this.progressbar.setProgress((int) signal.getRemainTime()); + if (this.terminal.isPlayer()) + this.progressbar.setProgress((int) signal.getRemainTime()); } @SignalHandler public void onUserVerifyDenied(UserVerifyDeniedSignal signal) { + this.terminal.error("コードの有効化に失敗しました:ユーザがコードの有効化を拒否しました。"); + + if (!this.terminal.isPlayer()) + return; + this.progressbar.hide(); this.terminal.removeProgressbar("codeExpire"); - - this.terminal.error("コードの有効化に失敗しました:ユーザがコードの有効化を拒否しました。"); } @SignalHandler public void onUserVerifySucceeded(UserVerificationSuccessSignal signal) { + this.terminal.success("コードの有効化に成功しました。"); + + if (!this.terminal.isPlayer()) + return; + this.progressbar.hide(); this.terminal.removeProgressbar("codeExpire"); - - this.terminal.success("コードの有効化に成功しました。"); } } From d30a70bf91cf851ea9a6240b998c0916266b1825 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 03:54:22 +0900 Subject: [PATCH 484/745] fix(daemon): Upgrade cancel doesn't work --- .../kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java index 3d2af54c..db79d7cf 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java @@ -266,6 +266,9 @@ private Map resolvePlugins(Map queries) ResolveResult result = this.resolveOne(plugin, query); + if (result == null) + return null; // Cancelled + resolvedQueries.put(plugin, (SuccessResult) result); } } From 7ea00a972cb312228e7e6c2607c348207963e475 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 04:21:18 +0900 Subject: [PATCH 485/745] fix(daemon): Upgrade signal handling failure --- .../lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java index fa6096ed..963612f8 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java @@ -47,6 +47,9 @@ private boolean askCancelOrContinue(int currentCount) @SignalHandler public void onPluginNotFound(PluginNotFoundSignal signal) { + if (signal instanceof ResolveFailedSignal) + return; // implemented in #onResolveFailed(ResolveFailedSignal) + this.terminal.warn("プラグイン " + signal.getSpecifiedPluginName() + " が見つかりませんでした。"); signal.setContinueUpgrade(this.askCancelOrContinue(++this.currentPluginCount)); } From 45b3e76fd25322c59a7142754866802e71b52f60 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 04:24:03 +0900 Subject: [PATCH 486/745] fix(daemon): UpgradeFinishedSignalHandler aren't registered --- .../java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java index e37bdf4a..d7904d65 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java @@ -18,6 +18,7 @@ import net.kunmc.lab.kpm.signal.handlers.uninstall.UninstallReadySignalHandler; import net.kunmc.lab.kpm.signal.handlers.uninstall.UninstallerSignalHandler; import net.kunmc.lab.kpm.signal.handlers.update.UpdateAliasesSignalHandler; +import net.kunmc.lab.kpm.signal.handlers.upgrade.UpgradeFinishedSignalHandler; import net.kunmc.lab.kpm.signal.handlers.upgrade.UpgradeSignalHandler; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; import org.jetbrains.annotations.NotNull; @@ -134,7 +135,8 @@ public static List getUpgraderHandlers(Terminal terminal, int targets) getCommonHandlers(terminal), getInstallHandlers(terminal, false), getUninstallHandlers(terminal, false), - new UpgradeSignalHandler(terminal, targets) + new UpgradeSignalHandler(terminal, targets), + new UpgradeFinishedSignalHandler(terminal) ); } From f3f925cbfdc7bdc5beba8cdbf67682dfaf033745 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 05:46:45 +0900 Subject: [PATCH 487/745] fix(daemon): AliasPluginResolver calls recursive --- .../main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java index cd8b2d6c..9e85ad90 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java @@ -34,7 +34,7 @@ public ResolveResult resolve(QueryContext query) try { - ResolveResult detailedResult = this.resolver.resolve(alias.getName()); + ResolveResult detailedResult = this.resolver.resolve(alias.getAlias()); if (detailedResult instanceof SuccessResult) return new SuccessResult(this, ((SuccessResult) detailedResult).getDownloadUrl(), ResolveResult.Source.LOCAL_KNOWN); else From 963aa5569315607d3519d899153adec1691ef332 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 05:47:06 +0900 Subject: [PATCH 488/745] feat(daemon): Connection leak detector --- .../kunmc/lab/kpm/utils/db/Transaction.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/Transaction.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/Transaction.java index 1420c17f..105c9654 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/Transaction.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/utils/db/Transaction.java @@ -27,6 +27,13 @@ */ public class Transaction implements AutoCloseable { + private static final boolean CONN_LEAK_TRACE; + + static + { + CONN_LEAK_TRACE = Boolean.getBoolean("kpm.conn-leak-trace"); + } + /** * Dbのコネクションです。 */ @@ -38,6 +45,7 @@ public class Transaction implements AutoCloseable private TransactionRun beforeCommit; + private Transaction(Connection connection, String query) throws SQLException { this.connection = connection; @@ -47,6 +55,31 @@ private Transaction(Connection connection, String query) throws SQLException this.preparedStatement = this.connection.prepareStatement(query); else this.preparedStatement = null; + + if (!CONN_LEAK_TRACE) + return; + + // Get stack and get the caller of this class + StackTraceElement[] stack = Thread.currentThread().getStackTrace(); + StackTraceElement caller; + for (int i = 0; i < stack.length; i++) + { + caller = stack[i]; + if (!caller.getClassName().equals(this.getClass().getName())) + continue; + + if (i + 1 >= stack.length) + continue; + + caller = stack[i + 1]; + if (caller.getClassName().equals(this.getClass().getName())) + continue; + + System.out.println("Transaction(" + this.connection.hashCode() + + ") created by " + caller.getClassName() + "#" + caller.getMethodName() + " at " + + caller.getFileName() + ":" + caller.getLineNumber()); + break; + } } /** @@ -438,14 +471,7 @@ public int executeUpdate(boolean autoFinish) { if (autoFinish) - try - { - this.connection.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + this.close(); } } @@ -521,14 +547,7 @@ public void doTransaction(TransactionRun transactionRun) } finally { - try - { - this.connection.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + this.close(); } } @@ -558,14 +577,7 @@ public void finishManually() } finally { - try - { - this.connection.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + this.close(); } } @@ -583,14 +595,7 @@ public void abortManually() throw new IllegalStateException(e1); } - try - { - this.connection.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + this.close(); } /** @@ -620,15 +625,7 @@ public boolean isExists(boolean closeConnection) } finally { - try - { - if (closeConnection) - this.connection.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + this.close(); } } @@ -649,6 +646,9 @@ public void close() { if (!this.connection.isClosed()) this.connection.close(); + + if (CONN_LEAK_TRACE) + System.out.println("Transaction(" + this.connection.hashCode() + ") is closed."); } catch (SQLException ignored) { From a18f8cc35ae5844da5ae6b2f076fdc066e826acb Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 05:50:51 +0900 Subject: [PATCH 489/745] feat(plugin): Invalid daemon setup of organization specify --- .../src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java index d48a59ea..3a2c69dc 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/TeamKunPluginManager.java @@ -91,7 +91,7 @@ public void onEnable() .tokenKeyPath(dataDir.resolve("token_key.dat")) .metadataDBPath(dataDir.resolve("plugins.db")) .aliasesDBPath(dataDir.resolve("aliases.db")) - .organizations(this.getPluginConfig().getStringList("githubName")) + .organizations(this.getPluginConfig().getStringList("gitHubName")) .sources(this.setupSources()) .build() ); From aa3af40ec29ac13afbd40d8d9ed3991e0cfdea60 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 17:27:14 +0900 Subject: [PATCH 490/745] feat(daemon): Fix ConcurrentModificationException when installer handler is preparing --- .../main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java index 1f143ab5..1e09a414 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandlerList.java @@ -37,7 +37,7 @@ public void bakeAll(Object object) { synchronized (this.handlers) { - Arrays.stream(object.getClass().getMethods()).parallel() + Arrays.stream(object.getClass().getMethods()) .filter(method -> method.isAnnotationPresent(SignalHandler.class)) .filter(method -> !this.isBaked(method)) .filter(method -> method.getParameterCount() == 1) From 0de0260d733b4caab7efdc08604ffd514a866159 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sat, 26 Nov 2022 17:35:50 +0900 Subject: [PATCH 491/745] feat(daemon): Deep alias retrieving --- .../main/java/net/kunmc/lab/kpm/KPMDaemon.java | 2 +- .../lab/kpm/alias/AliasPluginResolver.java | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index ea008725..4418167c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -213,9 +213,9 @@ private void setupDependencyTree() private void setupPluginResolvers(List organizationNames) { GitHubURLResolver githubResolver = new GitHubURLResolver(); + this.pluginResolver.addResolver(new AliasPluginResolver(this), "local", "alias"); this.pluginResolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); this.pluginResolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); - this.pluginResolver.addResolver(new AliasPluginResolver(this), "local", "alias"); this.pluginResolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); this.pluginResolver.addResolver(githubResolver, "github", "gh"); diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java index 9e85ad90..6be7f356 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java @@ -6,8 +6,8 @@ import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; import net.kunmc.lab.kpm.resolver.result.ErrorResult; import net.kunmc.lab.kpm.resolver.result.MultiResult; +import net.kunmc.lab.kpm.resolver.result.PipeResult; import net.kunmc.lab.kpm.resolver.result.ResolveResult; -import net.kunmc.lab.kpm.resolver.result.SuccessResult; import org.jetbrains.annotations.NotNull; /** @@ -32,19 +32,8 @@ public ResolveResult resolve(QueryContext query) if (alias == null) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); - try - { - ResolveResult detailedResult = this.resolver.resolve(alias.getAlias()); - if (detailedResult instanceof SuccessResult) - return new SuccessResult(this, ((SuccessResult) detailedResult).getDownloadUrl(), ResolveResult.Source.LOCAL_KNOWN); - else - return detailedResult; - } - catch (StackOverflowError ignored) - { - } - - return new SuccessResult(this, alias.getName(), null, null, ResolveResult.Source.LOCAL_KNOWN); + query.setQuery(alias.getAlias()); + return new PipeResult(this, query); } @Override From e8f73ae569432bb19bbf20752f24e920728b56e9 Mon Sep 17 00:00:00 2001 From: Peyang Date: Sun, 27 Nov 2022 04:30:18 +0900 Subject: [PATCH 492/745] fix(daemon): Alias doesn't work completely --- .../java/net/kunmc/lab/kpm/alias/Alias.java | 9 +++--- .../lab/kpm/alias/AliasPluginResolver.java | 6 ++-- .../kunmc/lab/kpm/alias/AliasProvider.java | 29 ++++++++++--------- .../net/kunmc/lab/kpm/alias/AliasUpdater.java | 16 +++++----- .../impl/BruteforceGitHubResolver.java | 11 +++++-- 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java index 2f178852..f052b64f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/Alias.java @@ -8,15 +8,14 @@ @Value public class Alias { - /** - * 正式名です。 - */ - String name; - /** * エイリアスです。 */ String alias; + /** + * クエリです。 + */ + String query; /** * エイリアスのソースです。 */ diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java index 6be7f356..6e3e85dc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasPluginResolver.java @@ -27,19 +27,19 @@ public AliasPluginResolver(@NotNull KPMDaemon daemon) @Override public ResolveResult resolve(QueryContext query) { - Alias alias = this.aliasProvider.getNameByAlias(query.getQuery()); + Alias alias = this.aliasProvider.getQueryByAlias(query.getQuery()); if (alias == null) return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.LOCAL_KNOWN); - query.setQuery(alias.getAlias()); + query.setQuery(alias.getQuery()); return new PipeResult(this, query); } @Override public ResolveResult autoPickOnePlugin(MultiResult multiResult) { - throw new UnsupportedOperationException("Why you call me?"); + throw new UnsupportedOperationException(); } @Override diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasProvider.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasProvider.java index 936ddde0..b244cec2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasProvider.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasProvider.java @@ -6,6 +6,7 @@ import net.kunmc.lab.kpm.utils.db.ResultRow; import net.kunmc.lab.kpm.utils.db.Transaction; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.sql.Statement; @@ -32,13 +33,13 @@ private void initializeTables() Statement stmt = tr.getConnection().createStatement(); stmt.execute("CREATE TABLE IF NOT EXISTS alias(" + - "name TEXT NOT NULL, " + "alias TEXT NOT NULL PRIMARY KEY," + + "query TEXT NOT NULL," + "source_id TEXT NOT NULL" + ")"); stmt.execute("CREATE TABLE IF NOT EXISTS source(" + - "name TEXT PRIMARY KEY NOT NULL, " + + "name TEXT PRIMARY KEY NOT NULL," + "source TEXT NOT NULL," + "type TEXT NOT NULL" + ")"); @@ -68,13 +69,14 @@ public AliasUpdater createUpdater(@NotNull String sourceName, @NotNull String so /** * エイリアスが存在するかどうかを返します。 * - * @param name エイリアス対象の名前 + * @param query エイリアス対象のkueri * @return エイリアスが存在するかどうか */ - public boolean hasAlias(@NotNull String name) + public boolean hasAlias(@NotNull String query) + { - return Transaction.create(this.db, "SELECT COUNT(*) FROM alias WHERE name = ?") - .set(1, name) + return Transaction.create(this.db, "SELECT COUNT(*) FROM alias WHERE query = ?") + .set(1, query) .isExists(); } @@ -118,15 +120,16 @@ public AliasSource getSource(String id) } /** - * エイリアスを取得します。 + * エイリアスからクエリを取得します。 * - * @param name エイリアス対象の名前 - * @return エイリアス + * @param alias エイリアス + * @return 名前 */ - public Alias getNameByAlias(String name) + @Nullable + public Alias getQueryByAlias(String alias) { - try (Transaction transaction = Transaction.create(this.db, "SELECT * FROM alias WHERE name = ?") - .set(1, name); + try (Transaction transaction = Transaction.create(this.db, "SELECT * FROM alias WHERE alias = ?") + .set(1, alias); ResultRow row = transaction .executeQuery() .stream() @@ -136,8 +139,8 @@ public Alias getNameByAlias(String name) return null; return new Alias( - row.getString("name"), row.getString("alias"), + row.getString("query"), row.getString("source_id") ); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasUpdater.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasUpdater.java index faf14753..67bca89e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasUpdater.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/alias/AliasUpdater.java @@ -28,7 +28,7 @@ public AliasUpdater(String sourceName, String sourceURL, AliasProvider provider) private void createCheckTable(String sourceName) { - this.transaction.renew("CREATE TABLE v_exists_alias AS SELECT name FROM alias WHERE source_id = ?") + this.transaction.renew("CREATE TABLE v_exists_alias AS SELECT alias FROM alias WHERE source_id = ?") .set(1, sourceName) .executeUpdate(false); } @@ -42,14 +42,14 @@ private void dropCheckTable() /** * エイリアスのアップデートを行います。 * - * @param name エイリアス対象の名前 * @param alias エイリアス + * @param query クエリ */ - public void update(String name, String alias) + public void update(String alias, String query) { - this.transaction.renew("INSERT OR REPLACE INTO alias (name, alias, source_id) VALUES (?, ?, ?)") - .set(1, name) - .set(2, alias) + this.transaction.renew("INSERT OR REPLACE INTO alias (alias, query, source_id) VALUES (?, ?, ?)") + .set(1, alias) + .set(2, query) .set(3, this.sourceName) .executeUpdate(false); @@ -58,8 +58,8 @@ public void update(String name, String alias) private void deleteRemovedAlias() { - this.transaction.renew("DELETE FROM alias WHERE name IN " + - "(SELECT name FROM v_exists_alias EXCEPT SELECT name FROM alias WHERE source_id = ?)") + this.transaction.renew("DELETE FROM alias WHERE alias IN " + + "(SELECT alias FROM v_exists_alias EXCEPT SELECT alias FROM alias WHERE source_id = ?)") .set(1, this.sourceName) .executeUpdate(false); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java index b3acdeed..a30d8c9e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java @@ -22,6 +22,7 @@ public ResolveResult resolve(QueryContext query) for (String str : this.gitHubName) { + String oldQuery = query.getQuery(); query.setQuery("https://github.com/" + str + "/" + query.getQuery()); result = this.gitHubURLResolver.resolve(query); @@ -30,10 +31,16 @@ public ResolveResult resolve(QueryContext query) ErrorResult error = (ErrorResult) result; if (error.getCause() == ErrorResult.ErrorCause.INVALID_QUERY) + { + query.setQuery(oldQuery); return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); - + } if (error.getCause() != ErrorResult.ErrorCause.PLUGIN_NOT_FOUND) - return error; + { + query.setQuery(oldQuery); + return result; + } + continue; } From 67ac039e94a44d01e1ec92ccd2e3ab6d96263e9f Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 03:17:55 +0900 Subject: [PATCH 493/745] fix(daemon): Resolver returns SuccessResult when plugin is not found(because of RawURLResolver passing) --- .../java/net/kunmc/lab/kpm/KPMDaemon.java | 2 +- .../impl/BruteforceGitHubResolver.java | 20 +++++++++--------- .../resolver/impl/OmittedGitHubResolver.java | 21 ++++++++++++++++--- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java index 4418167c..8a78ad40 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/KPMDaemon.java @@ -216,7 +216,7 @@ private void setupPluginResolvers(List organizationNames) this.pluginResolver.addResolver(new AliasPluginResolver(this), "local", "alias"); this.pluginResolver.addResolver(new SpigotMCResolver(), "spigotmc", "spigot", "spiget"); this.pluginResolver.addResolver(new CurseBukkitResolver(), "curseforge", "curse", "forge", "bukkit"); - this.pluginResolver.addResolver(new OmittedGitHubResolver(), "github", "gh"); + this.pluginResolver.addResolver(new OmittedGitHubResolver(githubResolver), "github", "gh"); this.pluginResolver.addResolver(githubResolver, "github", "gh"); this.pluginResolver.addFallbackResolver(new BruteforceGitHubResolver( diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java index a30d8c9e..949ccd90 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/BruteforceGitHubResolver.java @@ -19,10 +19,10 @@ public class BruteforceGitHubResolver implements BaseResolver public ResolveResult resolve(QueryContext query) { ResolveResult result = new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + String oldQuery = query.getQuery(); for (String str : this.gitHubName) { - String oldQuery = query.getQuery(); query.setQuery("https://github.com/" + str + "/" + query.getQuery()); result = this.gitHubURLResolver.resolve(query); @@ -32,21 +32,21 @@ public ResolveResult resolve(QueryContext query) if (error.getCause() == ErrorResult.ErrorCause.INVALID_QUERY) { - query.setQuery(oldQuery); - return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + result = new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); + break; } - if (error.getCause() != ErrorResult.ErrorCause.PLUGIN_NOT_FOUND) - { - query.setQuery(oldQuery); - return result; - } - - continue; + else if (error.getCause() == ErrorResult.ErrorCause.PLUGIN_NOT_FOUND) + continue; + else + break; } return result; } + // Result is always ErrorResult so we have to restore old query to pass it to next resolver. + query.setQuery(oldQuery); + return result; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/OmittedGitHubResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/OmittedGitHubResolver.java index 9320bd43..87bef9b5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/OmittedGitHubResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/impl/OmittedGitHubResolver.java @@ -1,21 +1,36 @@ package net.kunmc.lab.kpm.resolver.impl; +import lombok.AllArgsConstructor; import net.kunmc.lab.kpm.resolver.QueryContext; import net.kunmc.lab.kpm.resolver.interfaces.BaseResolver; +import net.kunmc.lab.kpm.resolver.result.ErrorResult; import net.kunmc.lab.kpm.resolver.result.MultiResult; -import net.kunmc.lab.kpm.resolver.result.PipeResult; import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import org.apache.commons.lang.StringUtils; +@AllArgsConstructor public class OmittedGitHubResolver implements BaseResolver { + private final GitHubURLResolver gitHubURLResolver; + private static final String DELIMITER = "/"; @Override public ResolveResult resolve(QueryContext query) { - query.setQuery("https://github.com/" + query.getQuery()); - return new PipeResult(this, query); + String repoName = query.getQuery(); + + query.setQuery("https://github.com/" + repoName); + + ResolveResult res = this.gitHubURLResolver.resolve(query); + + if (res instanceof SuccessResult) + return res; + + query.setQuery(repoName); // restore query + + return new ErrorResult(this, ErrorResult.ErrorCause.PLUGIN_NOT_FOUND, ResolveResult.Source.GITHUB); } @Override From 543351449ea19139654ca760b18ced6231bf2c44 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 04:28:09 +0900 Subject: [PATCH 494/745] fix(daemon): Invalid translation --- .../task/tasks/resolve/PluginResolveTask.java | 4 ++-- .../signals/PluginResolveErrorSignal.java | 6 +++++ .../lab/kpm/signal/HeadSignalHandlers.java | 23 ++++++++++++------- .../intall/ResolverSignalHandler.java | 6 ++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java index 6f48a688..4ef5b2c5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/PluginResolveTask.java @@ -61,7 +61,7 @@ public PluginResolveTask(@NotNull AbstractInstaller installer) if (queryResolveResult instanceof ErrorResult) { - this.postSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult)); + this.postSignal(new PluginResolveErrorSignal((ErrorResult) queryResolveResult, query)); return new PluginResolveResult(false, this.taskState, PluginResolveErrorCause.GOT_ERROR_RESULT, null ); @@ -81,7 +81,7 @@ else if (queryResolveResult instanceof MultiResult) if (actualResolveResult instanceof ErrorResult) { // MultiResult has been resolved, but the actual result is an error - this.postSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult)); + this.postSignal(new PluginResolveErrorSignal((ErrorResult) actualResolveResult, query)); return new PluginResolveResult(false, this.taskState, PluginResolveErrorCause.GOT_ERROR_RESULT, null); } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java index 1e93f41f..7a76d11e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java @@ -4,6 +4,7 @@ import lombok.NonNull; import net.kunmc.lab.kpm.resolver.result.ErrorResult; import net.kunmc.lab.kpm.signal.Signal; +import org.jetbrains.annotations.NotNull; /** * プラグインの解決に失敗したことを示すシグナルです。 @@ -16,4 +17,9 @@ public class PluginResolveErrorSignal implements Signal */ @NonNull private final ErrorResult error; + /** + * 解決しようとしたクエリです。 + */ + @NotNull + private final String query; } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java index d7904d65..78ca3fbb 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public class HeadSignalHandlers { @@ -38,6 +39,15 @@ private static List createHandlersList(List base, Object... hand return list; } + @SafeVarargs + private static List createHandlersList(List... lists) + { + return Arrays.stream(lists) + .flatMap(List::stream) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + private static List createHandlersList(Object... handlers) { return Arrays.asList(handlers); @@ -129,19 +139,16 @@ public static List getTokenRegistererHandlers(Terminal terminal) ); } - public static List getUpgraderHandlers(Terminal terminal, int targets) + public static List getUpgraderHandlers(Terminal terminal) { return createHandlersList( getCommonHandlers(terminal), getInstallHandlers(terminal, false), getUninstallHandlers(terminal, false), - new UpgradeSignalHandler(terminal, targets), - new UpgradeFinishedSignalHandler(terminal) + Arrays.asList( + new UpgradeSignalHandler(terminal), + new UpgradeFinishedSignalHandler(terminal) + ) ); } - - public static List getUpgraderHandlers(Terminal terminal) - { - return getUpgraderHandlers(terminal, -1); - } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java index 8c91831d..f845c987 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java @@ -34,7 +34,7 @@ public ResolverSignalHandler(Terminal terminal) @SignalHandler public void onPluginResolving(PluginResolvingSignal signal) { - this.terminal.writeLine(ChatColor.GREEN + "プラグインを解決しています ..."); + this.terminal.writeLine(ChatColor.GREEN + signal.getQuery() + " を解決しています ..."); } @SignalHandler @@ -43,7 +43,7 @@ public void onPluginResolveError(PluginResolveErrorSignal signal) ErrorResult.ErrorCause errorCause = signal.getError().getCause(); String message = signal.getError().getMessage() == null ? "": "(" + signal.getError().getMessage() + ")"; - this.terminal.writeLine(ChatColor.RED + "プラグインの解決に失敗しました: " + errorCause + message); + this.terminal.writeLine(ChatColor.RED + signal.getQuery() + " の解決に失敗しました: " + errorCause + message); } @SignalHandler @@ -76,7 +76,7 @@ public void onPluginsResolve(MultiplePluginResolvedSignal signal) if (result.test(QuestionAttribute.CANCELLABLE)) { - this.terminal.error(ChatColor.RED + "インストールをキャンセルしました。"); + this.terminal.error(ChatColor.RED + "解決をキャンセルしました。"); signal.setCancel(true); return; } From 143a45d428ef188a53897ffb56701c1897834645 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 04:29:02 +0900 Subject: [PATCH 495/745] fix(daemon): Invalid upgrade cancellation --- .../kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java index db79d7cf..6ad44211 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java @@ -266,8 +266,8 @@ private Map resolvePlugins(Map queries) ResolveResult result = this.resolveOne(plugin, query); - if (result == null) - return null; // Cancelled + if (result == null) // User(or signal) selected to skip this plugin + continue; // Skip resolvedQueries.put(plugin, (SuccessResult) result); } From b7341a5edaa9ae18619ef82c44c8852448abe76f Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 04:29:16 +0900 Subject: [PATCH 496/745] fix(daemon): Remove plugin resolving ask --- .../upgrade/UpgradeSignalHandler.java | 34 ++----------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java index 963612f8..03b071b5 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java @@ -17,31 +17,13 @@ public class UpgradeSignalHandler { // ignore UpdateQueryRetrievedSignal + // ignore PluginResolveFailedSignal private final Terminal terminal; - private final int targetPluginCount; - private int currentPluginCount = 0; - private int currentPluginResolvedCount = 0; - public UpgradeSignalHandler(Terminal terminal, int targetPlugins) + public UpgradeSignalHandler(Terminal terminal) { this.terminal = terminal; - this.targetPluginCount = targetPlugins; - } - - private boolean askCancelOrContinue(int currentCount) - { - - if (currentCount == this.targetPluginCount) // allow -1 - { - this.terminal.warn("プラグインのアップグレードを中止します。"); - return false; - } - else - { - this.terminal.info("この警告を無視してアップデートを続行できます。"); - return SignalHandlingUtils.askContinue(this.terminal); - } } @SignalHandler @@ -51,16 +33,6 @@ public void onPluginNotFound(PluginNotFoundSignal signal) return; // implemented in #onResolveFailed(ResolveFailedSignal) this.terminal.warn("プラグイン " + signal.getSpecifiedPluginName() + " が見つかりませんでした。"); - signal.setContinueUpgrade(this.askCancelOrContinue(++this.currentPluginCount)); - } - - @SignalHandler - public void onResolveFailed(ResolveFailedSignal signal) - { - this.terminal.warn("プラグイン " + signal.getPlugin().getName() + - " の解決は " + - signal.getErrorCause().name() + " で失敗しました。"); - signal.setContinueUpgrade(this.askCancelOrContinue(++this.currentPluginResolvedCount)); } @SignalHandler @@ -101,7 +73,5 @@ public void onInstallFailed(InstallFailedSignal signal) this.terminal.warn("プラグイン(不明) のアップグレードは " + result.getTaskStatus() + " で " + result.getReason() + "により失敗しました。"); - - signal.setContinueUpgrade(this.askCancelOrContinue(++this.currentPluginCount)); } } From 1a25131d268f4adf716196b734d2e030af70e2fe Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 04:44:31 +0900 Subject: [PATCH 497/745] feat(daemon): handled flag in Signal --- .../autoremove/signals/PluginEnumeratedSignal.java | 4 +++- .../signals/PluginUninstallFailedSignal.java | 4 +++- .../signals/AlreadyInstalledPluginSignal.java | 4 +++- .../signals/TokenGenerateStartingSignal.java | 4 +++- .../impls/register/signals/TokenStoredSignal.java | 4 +++- .../signals/UserDoesntCompleteVerifySignal.java | 4 +++- .../signals/UserVerificationSuccessSignal.java | 4 +++- .../register/signals/UserVerifyDeniedSignal.java | 4 +++- .../signals/VerificationCodeExpiredSignal.java | 4 +++- .../signals/VerificationCodeReceivedSignal.java | 4 +++- .../signals/VerificationCodeRequestFailedSignal.java | 4 +++- .../signals/VerificationCodeRequestingSignal.java | 2 +- .../uninstall/signals/PluginIsDependencySignal.java | 4 +++- .../uninstall/signals/SearchingPluginSignal.java | 4 +++- .../uninstall/signals/UninstallReadySignal.java | 2 +- .../impls/update/signals/UpdateFinishedSignal.java | 4 +++- .../impls/upgrade/signals/InstallFailedSignal.java | 4 +++- .../impls/upgrade/signals/PluginNotFoundSignal.java | 4 +++- .../upgrade/signals/UpdateQueryRetrievedSignal.java | 4 +++- .../impls/upgrade/signals/UpgradeReadySignal.java | 4 +++- .../kpm/installer/signals/InstallFinishedSignal.java | 4 +++- .../installer/signals/InvalidKPMInfoFileSignal.java | 4 +++- .../kpm/installer/signals/PluginModifiedSignal.java | 4 +++- .../signals/assertion/IgnoredPluginSignal.java | 4 +++- .../source/download/signals/InvalidRemoteSignal.java | 2 +- .../download/signals/SourceDownloadFailedSignal.java | 4 +++- .../alias/update/signals/AliasUpdateSignal.java | 4 +++- .../tasks/alias/update/signals/SourceSignal.java | 4 +++- ...endencyCollectDependencysDependsFailedSignal.java | 4 +++- .../signals/DependencyCollectFailedSignalBase.java | 2 +- .../signals/DependsCollectFailedSignal.java | 4 +++- .../signals/DependsDownloadFinishedSignal.java | 4 +++- .../collector/signals/DependsEnumeratedSignal.java | 4 +++- .../signals/DependsLoadOrderComputingSignal.java | 4 +++- .../signals/LoadPluginDescriptionSignal.java | 4 +++- .../task/tasks/download/signals/DownloadSignal.java | 4 +++- .../clean/signal/GarbageDeleteSkippedSignal.java | 4 +++- .../garbage/clean/signal/GarbageDeletingSignal.java | 4 +++- .../clean/signal/GarbageEnumeratedSignal.java | 4 +++- .../garbage/clean/signal/InvalidIntegritySignal.java | 2 +- .../search/signals/GarbageSearchingSignal.java | 4 +++- .../tasks/install/signals/PluginEnablingSignal.java | 4 +++- .../signals/PluginIncompatibleWithKPMSignal.java | 4 +++- .../install/signals/PluginInstallingSignal.java | 4 +++- .../task/tasks/install/signals/PluginLoadSignal.java | 4 +++- .../install/signals/PluginOnLoadRunningSignal.java | 4 +++- .../install/signals/PluginRelocatingSignal.java | 4 +++- .../signals/MultiplePluginResolvedSignal.java | 4 +++- .../resolve/signals/PluginResolveErrorSignal.java | 4 +++- .../signals/PluginResolvedSuccessfulSignal.java | 4 +++- .../tasks/resolve/signals/PluginResolvingSignal.java | 4 +++- .../uninstall/signals/PluginDisablingSignal.java | 4 +++- .../signals/PluginRegisteredRecipeSignal.java | 4 +++- .../signals/PluginUninstallErrorSignal.java | 4 +++- .../uninstall/signals/PluginUninstallingSignal.java | 4 +++- .../uninstall/signals/PluginUnloadingSignal.java | 2 +- .../tasks/uninstall/signals/StartingGCSignal.java | 2 +- .../main/java/net/kunmc/lab/kpm/signal/Signal.java | 12 +++++++++++- .../kunmc/lab/kpm/signal/SignalHandleManager.java | 4 ++++ 59 files changed, 172 insertions(+), 58 deletions(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginEnumeratedSignal.java index 9fe8ba70..a5df967c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginEnumeratedSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.impls.autoremove.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -10,7 +11,8 @@ * 自動削除するプラグインが列挙された場合に送信されるシグナルです。 */ @Data -public class PluginEnumeratedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginEnumeratedSignal extends Signal { /** * 自動削除するプラグインのリストです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java index f2a07c0f..3662c4a6 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/autoremove/signals/PluginUninstallFailedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.autoremove.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.InstallResult; import net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallTasks; @@ -9,7 +10,8 @@ * アンインストールに失敗したときに送信されるシグナルです。 */ @Value -public class PluginUninstallFailedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginUninstallFailedSignal extends Signal { /** * アンインストールに失敗したときの結果です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/signals/AlreadyInstalledPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/signals/AlreadyInstalledPluginSignal.java index 21a29209..73ec8769 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/signals/AlreadyInstalledPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/install/signals/AlreadyInstalledPluginSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.impls.install.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -10,7 +11,8 @@ * {@link AlreadyInstalledPluginSignal#setReplacePlugin(boolean)} を用いて、既存のプラグインを新規プラグインに置換するかどうかを設定できます。 */ @Data -public class AlreadyInstalledPluginSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class AlreadyInstalledPluginSignal extends Signal { /** * インストールされたプラグインの種類 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenGenerateStartingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenGenerateStartingSignal.java index ed7c794f..19e1e992 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenGenerateStartingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenGenerateStartingSignal.java @@ -1,13 +1,15 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; /** * トークンの生成の開始中であることを示すシグナルです。 */ @Data -public class TokenGenerateStartingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class TokenGenerateStartingSignal extends Signal { /** * 生成を続けるかどうかを示すフラグです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenStoredSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenStoredSignal.java index 6fc42aca..71e393ec 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenStoredSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/TokenStoredSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * トークンが登録されたことを示すシグナルです。 */ @Value -public class TokenStoredSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class TokenStoredSignal extends Signal { /** * 登録されたトークンです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java index 1d07ffb6..49a740a7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserDoesntCompleteVerifySignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * ユーザが検証コードの入力を完了していないことを示すシグナルです。 */ @Value -public class UserDoesntCompleteVerifySignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class UserDoesntCompleteVerifySignal extends Signal { /** * ユーザが入力するコードです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerificationSuccessSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerificationSuccessSignal.java index b2382d44..33439bfb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerificationSuccessSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerificationSuccessSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * ユーザ検証に成功したことを示すシグナルです。 */ @Value -public class UserVerificationSuccessSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class UserVerificationSuccessSignal extends Signal { /** * アクセストークンです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerifyDeniedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerifyDeniedSignal.java index 69a5ea9b..c406a67a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerifyDeniedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/UserVerifyDeniedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * ユーザがキャンセルをクリックしたことを示すシグナルです。 */ @Value -public class UserVerifyDeniedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class UserVerifyDeniedSignal extends Signal { @NotNull String userCode; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeExpiredSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeExpiredSignal.java index 65fa939c..ce8047bb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeExpiredSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeExpiredSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * ユーザの検証コードの有効期限が切れたことを示すシグナルです。 */ @Value -public class VerificationCodeExpiredSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class VerificationCodeExpiredSignal extends Signal { /** * ユーザが入力するべきだった検証コードです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeReceivedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeReceivedSignal.java index a01b8ed1..cfbc238d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeReceivedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeReceivedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.impls.register.pojos.UserVerificationCodeResponse; import net.kunmc.lab.kpm.signal.Signal; @@ -9,7 +10,8 @@ * ユーザ検証コードを受信したことを示すシグナルです。 */ @Value -public class VerificationCodeReceivedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class VerificationCodeReceivedSignal extends Signal { /** * ユーザが入力する検証コードです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java index 84e51bb6..d3e36e5b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestFailedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.register.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * ユーザ検証コード要求に失敗したときに発行されるシグナルです。 */ @Value -public class VerificationCodeRequestFailedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class VerificationCodeRequestFailedSignal extends Signal { /** * HTTPステータスコードです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestingSignal.java index 997cf103..44c54bbc 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/register/signals/VerificationCodeRequestingSignal.java @@ -5,6 +5,6 @@ /** * ユーザ検証コードの要求中であることを示すシグナルです。 */ -public class VerificationCodeRequestingSignal implements Signal +public class VerificationCodeRequestingSignal extends Signal { } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/PluginIsDependencySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/PluginIsDependencySignal.java index 936929f0..e831dd3c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/PluginIsDependencySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/PluginIsDependencySignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.impls.uninstall.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -12,7 +13,8 @@ * {@link PluginIsDependencySignal#setForceUninstall(boolean)} (boolean)} を用いて、強制的にアンインストールするかどうかを設定できます。 */ @Data -public class PluginIsDependencySignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginIsDependencySignal extends Signal { @NotNull private final Plugin plugin; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/SearchingPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/SearchingPluginSignal.java index 7fbe22dc..7c938f84 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/SearchingPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/SearchingPluginSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.impls.uninstall.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * プラグインを検索中であることを示すシグナルです。 */ @Data -public class SearchingPluginSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class SearchingPluginSignal extends Signal { @NotNull private String query; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/UninstallReadySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/UninstallReadySignal.java index a2a8401a..9336d1aa 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/UninstallReadySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/uninstall/signals/UninstallReadySignal.java @@ -11,7 +11,7 @@ * プラグインの列挙が完了したことを通知するシグナルです。 */ @Getter -public class UninstallReadySignal implements Signal +public class UninstallReadySignal extends Signal { /** * アンインストール対象のプラグインのリスト diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/signals/UpdateFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/signals/UpdateFinishedSignal.java index 04d1d37c..436359ef 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/signals/UpdateFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/update/signals/UpdateFinishedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.impls.update.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; @@ -9,7 +10,8 @@ * エイリアスのアップデートが完了したことを示すシグナルです。 */ @Value -public class UpdateFinishedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class UpdateFinishedSignal extends Signal { /** * エイリアスの数です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java index 1b867fc8..1d18a8e1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InstallFailedSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.impls.upgrade.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.installer.InstallResult; import net.kunmc.lab.kpm.installer.impls.install.InstallTasks; import net.kunmc.lab.kpm.signal.Signal; @@ -9,7 +10,8 @@ * インストールに失敗したことを表すシグナルです。 */ @Data -public class InstallFailedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class InstallFailedSignal extends Signal { /** * 失敗した原因の特定のためのインストール失敗結果です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java index f85db250..2425c038 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/PluginNotFoundSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.impls.upgrade.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * 指定されたプラグインが見つからなかったことを示すシグナルです。 */ @Data -public class PluginNotFoundSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginNotFoundSignal extends Signal { /** * 指定されたプラグインの名前です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java index db741cf4..afa25d88 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpdateQueryRetrievedSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.impls.upgrade.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -10,7 +11,8 @@ * アップグレードのクエリを取得したことを示すシグナルです。 */ @Data -public class UpdateQueryRetrievedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class UpdateQueryRetrievedSignal extends Signal { /** * アップグレード対象のプラグインです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java index edafb037..726fb9ad 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/UpgradeReadySignal.java @@ -2,6 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.resolver.result.SuccessResult; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; @@ -14,7 +15,8 @@ * アップグレードの準備が完了したことを示すシグナルです。 */ @Data -public class UpgradeReadySignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class UpgradeReadySignal extends Signal { private final List plugins; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InstallFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InstallFinishedSignal.java index ed17f296..28cfa62f 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InstallFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InstallFinishedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.InstallResult; import net.kunmc.lab.kpm.signal.Signal; @@ -8,7 +9,8 @@ * インストールが完了したことを表すシグナルです。 */ @Value -public class InstallFinishedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class InstallFinishedSignal extends Signal { /** * インストール結果 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InvalidKPMInfoFileSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InvalidKPMInfoFileSignal.java index 02bffe8b..bb7c6948 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InvalidKPMInfoFileSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/InvalidKPMInfoFileSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -11,7 +12,8 @@ * プラグインのKPM情報ファイルが不正な場合に投げられるシグナルです。 */ @Data -public class InvalidKPMInfoFileSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class InvalidKPMInfoFileSignal extends Signal { /** * プラグインの名前です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/PluginModifiedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/PluginModifiedSignal.java index ab627ee3..bd61bf9c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/PluginModifiedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/PluginModifiedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; @@ -10,7 +11,8 @@ * 新規にインストールされた場合、削除された場合、更新された場合にスローされます。 */ @Value -public class PluginModifiedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginModifiedSignal extends Signal { /** * 変更され他プラグインの情報です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java index 63918b79..bccc451a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/signals/assertion/IgnoredPluginSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.signals.assertion; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -10,7 +11,8 @@ * {@link IgnoredPluginSignal#setContinueInstall(boolean)} を変更することで、インストールのキャンセルを設定できます。 */ @Data -public class IgnoredPluginSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class IgnoredPluginSignal extends Signal { @NotNull private final String pluginName; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java index efc49a21..90e89e0e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/InvalidRemoteSignal.java @@ -13,7 +13,7 @@ */ @AllArgsConstructor @Getter -public abstract class InvalidRemoteSignal implements Signal +public abstract class InvalidRemoteSignal extends Signal { /** * リモートの名前です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java index 620c2de9..0d420908 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/source/download/signals/SourceDownloadFailedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.alias.source.download.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadResult; import net.kunmc.lab.kpm.signal.Signal; @@ -8,7 +9,8 @@ * ソースファイルのダウンロードに失敗したことを示すシグナルです。 */ @Value -public class SourceDownloadFailedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class SourceDownloadFailedSignal extends Signal { String remoteName; DownloadResult downloadResult; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java index 3af2f784..cded61c3 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/AliasUpdateSignal.java @@ -3,14 +3,16 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import java.net.URL; @Data +@EqualsAndHashCode(callSuper = false) @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class AliasUpdateSignal implements Signal +public class AliasUpdateSignal extends Signal { @NotNull private final String source; diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourceSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourceSignal.java index 640ba35c..384d5d25 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourceSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/alias/update/signals/SourceSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.alias.update.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -8,7 +9,8 @@ import java.nio.file.Path; @Data -abstract class SourceSignal implements Signal +@EqualsAndHashCode(callSuper = false) +abstract class SourceSignal extends Signal { /** * ソースの名前です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java index d12a2bef..96cc1d1a 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectDependencysDependsFailedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -10,7 +11,8 @@ * 依存関係の依存関係を取得する際に失敗したことを示すシグナルです。 */ @Value -public class DependencyCollectDependencysDependsFailedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class DependencyCollectDependencysDependsFailedSignal extends Signal { /** * 対象のプラグインの名前です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java index 893036b0..affff766 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependencyCollectFailedSignalBase.java @@ -10,7 +10,7 @@ */ @AllArgsConstructor @Getter -public abstract class DependencyCollectFailedSignalBase implements Signal +public abstract class DependencyCollectFailedSignalBase extends Signal { /** * 取得に失敗した依存関係の名前です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java index 467f0489..0816cb66 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsCollectFailedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; @@ -10,7 +11,8 @@ * 注意:このシグナルは {@link DependencyCollectFailedSignalBase} とは違い個別には送信されず、依存関係の解決タスク終了後に一度送信されます。 */ @Value -public class DependsCollectFailedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class DependsCollectFailedSignal extends Signal { /** * 取得に失敗した依存関係の名前です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java index b8b22df6..31247c75 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsDownloadFinishedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.task.tasks.download.DownloadResult; import net.kunmc.lab.kpm.signal.Signal; @@ -11,7 +12,8 @@ * 依存関係のダウンロードがすべて完了したことを示すシグナルです。 */ @Value -public class DependsDownloadFinishedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class DependsDownloadFinishedSignal extends Signal { /** * ダウンロード結果です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java index 2446eecc..c140b43e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/collector/signals/DependsEnumeratedSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.dependencies.collector.signals; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; @@ -11,7 +12,8 @@ */ @AllArgsConstructor @Value -public class DependsEnumeratedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class DependsEnumeratedSignal extends Signal { /** * 列挙された依存関係。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java index d51e5d55..6eb5fdf0 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/dependencies/computer/signals/DependsLoadOrderComputingSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.dependencies.computer.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -12,7 +13,8 @@ * 依存関係の読み込み順序を計算する際に発生するシグナルを表します。 */ @Data -public class DependsLoadOrderComputingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class DependsLoadOrderComputingSignal extends Signal { /** * 指定された依存関係のリストです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java index 6612ce22..44b5aac1 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/description/signals/LoadPluginDescriptionSignal.java @@ -2,6 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -12,7 +13,8 @@ */ @Data @AllArgsConstructor -public class LoadPluginDescriptionSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class LoadPluginDescriptionSignal extends Signal { /** * プラグイン情報ファイルのパスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSignal.java index 89983f84..d597ed67 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/download/signals/DownloadSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.download.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,8 @@ * ダウンロード時に発生するシグナルを表す、抽象クラスです。 */ @Data -public abstract class DownloadSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public abstract class DownloadSignal extends Signal { /** * ダウンロードごとに発行される一意のIDです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java index 1e47d7d7..442b58e5 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeleteSkippedSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -10,7 +11,8 @@ * 不要データの削除がスキップされたことを示すシグナルです。 */ @Value -public class GarbageDeleteSkippedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class GarbageDeleteSkippedSignal extends Signal { /** * スキップされた不要データのパスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java index aabbe476..63287c37 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageDeletingSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import net.kunmc.lab.kpm.signal.Signal; @@ -12,7 +13,8 @@ * 不要なデータの削除中であることを示すシグナルです。 */ @Data -public class GarbageDeletingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class GarbageDeletingSignal extends Signal { /** * 不要なデータのパスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java index c6da8f70..c865cf0d 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/GarbageEnumeratedSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.garbage.clean.signal; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import java.nio.file.Path; @@ -10,7 +11,8 @@ * 不要なデータが列挙されたことを示すシグナルです。 */ @Data -public class GarbageEnumeratedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class GarbageEnumeratedSignal extends Signal { /** * 不要なデータのパスのリストです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java index 47566554..76bc5243 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/clean/signal/InvalidIntegritySignal.java @@ -6,6 +6,6 @@ * 整合性がとれなく、システムが保護されたことを示すシグナルです。 * 不要データの削除はスキップされます。 */ -public class InvalidIntegritySignal implements Signal +public class InvalidIntegritySignal extends Signal { } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java index 00383ee1..94b2f207 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/garbage/search/signals/GarbageSearchingSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.garbage.search.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import java.nio.file.Path; @@ -9,7 +10,8 @@ * 不要データの検索を開始したことを示すシグナルです。 */ @Data -public class GarbageSearchingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class GarbageSearchingSignal extends Signal { /** * 検索対象のディレクトリです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java index cefe0ed3..95d082aa 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginEnablingSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -11,7 +12,8 @@ * このシグナルより先に {@link PluginOnLoadRunningSignal} が呼ばれます。 */ @Data -public class PluginEnablingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginEnablingSignal extends Signal { /** * 対象のプラグインです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java index 517d1cf2..ff147a80 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginIncompatibleWithKPMSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.kpminfo.KPMInformationFile; import net.kunmc.lab.kpm.signal.Signal; import net.kunmc.lab.kpm.utils.versioning.Version; @@ -11,7 +12,8 @@ * プラグインがこのKPMと互換性がない場合に投げられるシグナルです。 */ @Data -public class PluginIncompatibleWithKPMSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginIncompatibleWithKPMSignal extends Signal { /** * プラグインの説明ファイルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginInstallingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginInstallingSignal.java index 54d8c89d..8644dc10 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginInstallingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginInstallingSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.install.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.PluginDescriptionFile; @@ -11,7 +12,8 @@ * プラグインのインストール中であることを示すシグナルです。 */ @Value -public class PluginInstallingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginInstallingSignal extends Signal { /** * 対象のプラグインのパスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginLoadSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginLoadSignal.java index 59de718e..5ba0fa74 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginLoadSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginLoadSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; @@ -14,7 +15,8 @@ * {@link org.bukkit.plugin.PluginManager#loadPlugin(java.io.File)} の呼び出しの前後にスローされます。 */ @Data -public class PluginLoadSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginLoadSignal extends Signal { /** * 対象のプラグインのパスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java index 682a264c..bfed927e 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginOnLoadRunningSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -9,7 +10,8 @@ * プラグインの {@link Plugin#onLoad()} の実行の前後にスローされるシグナルです。 */ @Data -public class PluginOnLoadRunningSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginOnLoadRunningSignal extends Signal { /** * 対象のプラグインです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginRelocatingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginRelocatingSignal.java index f7248161..17a7a7dd 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginRelocatingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/install/signals/PluginRelocatingSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.install.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -10,7 +11,8 @@ * プラグインを、ダウンロードの仮ディレクトリからプラグインディレクトリに移動する際に送信されるシグナルです。 */ @Data -public class PluginRelocatingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginRelocatingSignal extends Signal { /** * プラグインのパスです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java index db72187a..be7865dd 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/MultiplePluginResolvedSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.resolve.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.resolver.result.MultiResult; import net.kunmc.lab.kpm.resolver.result.ResolveResult; import net.kunmc.lab.kpm.resolver.result.SuccessResult; @@ -12,7 +13,8 @@ * 複数のプラグインが解決されたことを示すシグナルです。 */ @Data -public class MultiplePluginResolvedSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class MultiplePluginResolvedSignal extends Signal { /** * 解決する際に使用されたクエリです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java index 7a76d11e..61a5544b 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolveErrorSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.resolve.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NonNull; import net.kunmc.lab.kpm.resolver.result.ErrorResult; import net.kunmc.lab.kpm.signal.Signal; @@ -10,7 +11,8 @@ * プラグインの解決に失敗したことを示すシグナルです。 */ @Data -public class PluginResolveErrorSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginResolveErrorSignal extends Signal { /** * 失敗したプラグインの解決結果です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java index 199f2d13..eaa99fcb 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvedSuccessfulSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.resolve.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.resolver.result.SuccessResult; import net.kunmc.lab.kpm.signal.Signal; import org.jetbrains.annotations.NotNull; @@ -9,7 +10,8 @@ * プラグインが正常に解決されたことを示すシグナルです。 */ @Data -public class PluginResolvedSuccessfulSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginResolvedSuccessfulSignal extends Signal { /** * 解決する際に使用されたクエリです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvingSignal.java index 3570090b..04733e03 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/resolve/signals/PluginResolvingSignal.java @@ -2,6 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.resolver.PluginResolver; import net.kunmc.lab.kpm.signal.Signal; @@ -10,7 +11,8 @@ */ @Data @AllArgsConstructor -public class PluginResolvingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginResolvingSignal extends Signal { /** * 解決に使用されるプラグインリゾルバです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java index 2b148e19..1fbee15c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginDisablingSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -9,7 +10,8 @@ * プラグインの無効化の前後にスローされるシグナルです。 */ @Data -public class PluginDisablingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginDisablingSignal extends Signal { /** * 無効化されるプラグインです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java index 7524fa47..931a55f7 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginRegisteredRecipeSignal.java @@ -1,6 +1,7 @@ package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import net.kunmc.lab.kpm.signal.Signal; @@ -15,7 +16,8 @@ * プラグインが登録したレシピについてのシグナルです。 */ @Data -public class PluginRegisteredRecipeSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginRegisteredRecipeSignal extends Signal { /** * レシピを登録したプラグインです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java index 61d4a33d..b56560c4 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallErrorSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.installer.task.tasks.uninstall.UnInstallErrorCause; import net.kunmc.lab.kpm.signal.Signal; @@ -9,7 +10,8 @@ * プラグインのアンインストール中にエラーが発生したことを通知するシグナルです。 */ @Value -public class PluginUninstallErrorSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginUninstallErrorSignal extends Signal { /** * エラーの原因です。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java index 6aa28e58..2555982c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUninstallingSignal.java @@ -1,5 +1,6 @@ package net.kunmc.lab.kpm.installer.task.tasks.uninstall.signals; +import lombok.EqualsAndHashCode; import lombok.Value; import net.kunmc.lab.kpm.signal.Signal; import org.bukkit.plugin.Plugin; @@ -8,7 +9,8 @@ * プラグインのアンインストールのシグナルです。 */ @Value -public class PluginUninstallingSignal implements Signal +@EqualsAndHashCode(callSuper = false) +public class PluginUninstallingSignal extends Signal { /** * アンインストールされるプラグインです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java index 7fad4af1..241f7390 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/PluginUnloadingSignal.java @@ -9,7 +9,7 @@ /** * プラグインのアンロードの前後にスローされるシグナルです。 */ -public class PluginUnloadingSignal implements Signal +public class PluginUnloadingSignal extends Signal { /** * アンロードの前にスローされるシグナルです。 diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java index 2ac57a4e..814d1996 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/task/tasks/uninstall/signals/StartingGCSignal.java @@ -5,6 +5,6 @@ /** * VMのGCを実行することを通知するシグナルです。 */ -public class StartingGCSignal implements Signal +public class StartingGCSignal extends Signal { } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/Signal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/Signal.java index d66b9daa..da97aea2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/Signal.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/Signal.java @@ -1,5 +1,8 @@ package net.kunmc.lab.kpm.signal; +import lombok.Getter; +import lombok.Setter; + /** * インストーラやタスクなどからスローされるシグナルです。 * シグナルは、主に次のことに使用されます: @@ -11,6 +14,13 @@ *

    * このシグナルは、フロントエンドとバックエンドの隔離のために作成されました。 */ -public interface Signal +@Getter +@Setter +public abstract class Signal { + /** + * シグナルがハンドルされたかどうかを示すフラグです。 + * このフラグが {@code true} の場合, ハンドルマネージャはこれ以降のハンドラを呼び出しません。 + */ + private boolean handled; } diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandleManager.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandleManager.java index 3e5af5c4..39c5360c 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandleManager.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/signal/SignalHandleManager.java @@ -76,7 +76,11 @@ public void register(Object object) public void handleSignal(@NotNull InstallProgress installProgress, Signal signal) { for (SignalHandlerList handlerList : this.handlerLists) + { invokeHandler(installProgress, handlerList, signal); + if (signal.isHandled()) + break; + } } /** From b10bfa4d235a0c3bc52f64ac4f6b1ab2185ed8a4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 06:12:47 +0900 Subject: [PATCH 498/745] fix(daemon): Invalid japanese dot --- .../java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java index d41ce771..6102e426 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/resolver/interfaces/URLResolver.java @@ -51,7 +51,7 @@ default boolean isValidResolver(QueryContext query) static String errorCodeWith(String message, int code) { - return message + "(The server responded with " + code + ")。"; + return message + "(The server responded with " + code + ")"; } default Matcher urlMatcher(Pattern pattern, String urlString) From 9ba0d0d624397fc3e626174370fc432281c3fbe6 Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 06:14:11 +0900 Subject: [PATCH 499/745] feat(daemon): Bypass plugin selecting when specifiedResult is present --- .../handlers/intall/ResolverSignalHandler.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java index f845c987..9a8b6fbf 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/intall/ResolverSignalHandler.java @@ -49,7 +49,19 @@ public void onPluginResolveError(PluginResolveErrorSignal signal) @SignalHandler public void onPluginsResolve(MultiplePluginResolvedSignal signal) { - this.terminal.warn("複数のプラグインが見つかりました。"); + this.terminal.info("複数のプラグインが見つかりました。"); + + if (signal.getSpecifiedResult() != null) + { + if (signal.getSpecifiedResult() instanceof SuccessResult) + { + SuccessResult specifiedResult = (SuccessResult) signal.getSpecifiedResult(); + this.terminal.info("プラグイン " + specifiedResult.getFileName() + "(" + + specifiedResult.getVersion() + ") が選択されました。"); + } + + return; + } AtomicLong index = new AtomicLong(0); @@ -59,7 +71,7 @@ public void onPluginsResolve(MultiplePluginResolvedSignal signal) .collect(Collectors.toMap(r -> String.valueOf(index.getAndIncrement()), r -> r, (a, b) -> a, LinkedHashMap::new)); LinkedHashMap keywordToTitle = keywordToResolveResult.entrySet().stream() .map(e -> new AbstractMap.SimpleEntry<>( - e.getKey(), + e.getKey(), e.getValue().getFileName() + "(" + e.getValue().getVersion() + ")" ) ) From ff460504929e9825b551f92f8fbb0932c635178f Mon Sep 17 00:00:00 2001 From: Peyang Date: Thu, 1 Dec 2022 06:14:33 +0900 Subject: [PATCH 500/745] feat(daemon): Upgradable plugin auto select --- .../kunmc/lab/kpm/signal/HeadSignalHandlers.java | 6 +++--- .../handlers/upgrade/UpgradeSignalHandler.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java index 78ca3fbb..87f93429 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/HeadSignalHandlers.java @@ -143,12 +143,12 @@ public static List getUpgraderHandlers(Terminal terminal) { return createHandlersList( getCommonHandlers(terminal), - getInstallHandlers(terminal, false), - getUninstallHandlers(terminal, false), Arrays.asList( new UpgradeSignalHandler(terminal), new UpgradeFinishedSignalHandler(terminal) - ) + ), + getInstallHandlers(terminal, false), + getUninstallHandlers(terminal, false) ); } } diff --git a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java index 03b071b5..04382d19 100644 --- a/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java +++ b/KPMPlugin/src/main/java/net/kunmc/lab/kpm/signal/handlers/upgrade/UpgradeSignalHandler.java @@ -6,6 +6,9 @@ import net.kunmc.lab.kpm.installer.impls.upgrade.signals.PluginNotFoundSignal; import net.kunmc.lab.kpm.installer.impls.upgrade.signals.ResolveFailedSignal; import net.kunmc.lab.kpm.installer.impls.upgrade.signals.UpgradeReadySignal; +import net.kunmc.lab.kpm.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; +import net.kunmc.lab.kpm.resolver.result.ResolveResult; +import net.kunmc.lab.kpm.resolver.result.SuccessResult; import net.kunmc.lab.kpm.signal.SignalHandler; import net.kunmc.lab.kpm.signal.SignalHandlingUtils; import net.kunmc.lab.peyangpaperutils.lib.terminal.Terminal; @@ -35,6 +38,17 @@ public void onPluginNotFound(PluginNotFoundSignal signal) this.terminal.warn("プラグイン " + signal.getSpecifiedPluginName() + " が見つかりませんでした。"); } + @SignalHandler + public void onMultiResolved(MultiplePluginResolvedSignal signal) + { + ResolveResult result = signal.getResults().getResolver().autoPickOnePlugin(signal.getResults()); + + this.terminal.info("複数のプラグインが解決されたため, 自動選択を行います。"); + + if (result instanceof SuccessResult) + signal.setSpecifiedResult(result); + } + @SignalHandler public void onUpgradeReady(UpgradeReadySignal signal) { From a855d72b2b3c20e3f83228b98865e3d20c49d7a4 Mon Sep 17 00:00:00 2001 From: Peyang Date: Fri, 2 Dec 2022 22:09:32 +0900 Subject: [PATCH 501/745] feat(daemon): Upgrade checking --- .../impls/upgrade/PluginUpgrader.java | 43 +++++++++++++ .../impls/upgrade/UpgradeErrorCause.java | 12 ++++ .../signals/InvalidPluginVersionSignal.java | 63 ++++++++++++++++++ .../lab/kpm/utils/versioning/Version.java | 13 ++++ .../net/kunmc/lab/kpm/HeadInstallers.java | 5 +- .../lab/kpm/signal/HeadSignalHandlers.java | 4 +- .../upgrade/UpgradeSignalHandler.java | 64 ++++++++++++++++++- 7 files changed, 198 insertions(+), 6 deletions(-) create mode 100644 KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InvalidPluginVersionSignal.java diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java index 6ad44211..fd0048e2 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/PluginUpgrader.java @@ -10,6 +10,7 @@ import net.kunmc.lab.kpm.installer.impls.uninstall.UnInstallTasks; import net.kunmc.lab.kpm.installer.impls.uninstall.UninstallArgument; import net.kunmc.lab.kpm.installer.impls.upgrade.signals.InstallFailedSignal; +import net.kunmc.lab.kpm.installer.impls.upgrade.signals.InvalidPluginVersionSignal; import net.kunmc.lab.kpm.installer.impls.upgrade.signals.PluginNotFoundSignal; import net.kunmc.lab.kpm.installer.impls.upgrade.signals.ResolveFailedSignal; import net.kunmc.lab.kpm.installer.impls.upgrade.signals.UpgradeReadySignal; @@ -27,6 +28,7 @@ import net.kunmc.lab.kpm.resolver.result.SuccessResult; import net.kunmc.lab.kpm.signal.SignalHandleManager; import net.kunmc.lab.kpm.utils.KPMCollectors; +import net.kunmc.lab.kpm.utils.versioning.Version; import net.kunmc.lab.peyangpaperutils.lib.utils.Pair; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -111,6 +113,16 @@ public InstallResult execute(@NotNull UpgradeArgument argument) th // endregion + // region Check plugin condition(such as version not defined or version is not higher than current version etc.) + for (Map.Entry entry : new ArrayList<>(resolveResults.entrySet())) + { + UpgradeErrorCause mayErrorCause = this.checkPluginMatch(entry.getKey(), entry.getValue()); + if (mayErrorCause == UpgradeErrorCause.PLUGIN_EXCLUDED) + resolveResults.remove(entry.getKey()); + else if (mayErrorCause != null) + return this.error(mayErrorCause); + } + // Notify upgrade is ready resolveResults = this.notifyUpgradeReady(resolveResults); if (resolveResults.isEmpty()) // Cancelled @@ -187,6 +199,37 @@ public InstallResult execute(@NotNull UpgradeArgument argument) th return this.success(); } + private UpgradeErrorCause checkPluginMatch(Plugin plugin, SuccessResult resolveResult) + { + PluginDescriptionFile description = plugin.getDescription(); + + if (resolveResult.getVersion() == null) + return this.excludeOrCancel(plugin, UpgradeErrorCause.PLUGIN_VERSION_NOT_DEFINED); + + Version currentVersion = Version.ofNullable(description.getVersion()); + Version newVersion = Version.ofNullable(resolveResult.getVersion()); + + if (currentVersion == null || newVersion == null) + return this.excludeOrCancel(plugin, UpgradeErrorCause.PLUGIN_VERSION_NOT_DEFINED, currentVersion, newVersion); + + if (currentVersion.isNewerThanOrEqualTo(newVersion)) + return this.excludeOrCancel(plugin, UpgradeErrorCause.PLUGIN_IS_OLDER_OR_EQUAL, currentVersion, newVersion); + + return null; + } + + private UpgradeErrorCause excludeOrCancel(Plugin plugin, UpgradeErrorCause cause, Version currentVersion, Version newVersion) + { + InvalidPluginVersionSignal signal = new InvalidPluginVersionSignal(plugin, cause, currentVersion, newVersion); + this.postSignal(signal); + return signal.isContinueUpgrade() ? UpgradeErrorCause.PLUGIN_EXCLUDED: cause; + } + + private UpgradeErrorCause excludeOrCancel(Plugin plugin, UpgradeErrorCause cause) + { + return this.excludeOrCancel(plugin, cause, null, null); + } + @Nullable private UpgradeErrorCause checkEnvironment(PluginDescriptionFile pluginDescription) { diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java index 5ee8819e..db05a870 100644 --- a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/UpgradeErrorCause.java @@ -13,6 +13,18 @@ public enum UpgradeErrorCause * プラグインの解決に失敗しました。 */ PLUGIN_RESOLVE_FAILED, + /** + * プラグインのバージョンが定義されていません。 + */ + PLUGIN_VERSION_NOT_DEFINED, + /** + * プラグインが定義してるバージョンの形式が不正です。 + */ + PLUGIN_VERSION_FORMAT_MALFORMED, + /** + * プラグインのバージョンがサーバのバージョンと変わらないか、古いです。 + */ + PLUGIN_IS_OLDER_OR_EQUAL, /** * アップグレードがキャンセルされました。 */ diff --git a/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InvalidPluginVersionSignal.java b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InvalidPluginVersionSignal.java new file mode 100644 index 00000000..8adb5c3b --- /dev/null +++ b/KPMDaemon/src/main/java/net/kunmc/lab/kpm/installer/impls/upgrade/signals/InvalidPluginVersionSignal.java @@ -0,0 +1,63 @@ +package net.kunmc.lab.kpm.installer.impls.upgrade.signals; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.kunmc.lab.kpm.installer.impls.upgrade.UpgradeErrorCause; +import net.kunmc.lab.kpm.signal.Signal; +import net.kunmc.lab.kpm.utils.versioning.Version; +import org.bukkit.plugin.Plugin; + +import javax.annotation.Nullable; + +/** + * プラグインのバージョンが不正であることを示すシグナルです。 + * 不正とされる理由は以下の通りです: + *

    of(@NotNull SignalHandleManager signalHandler, @Nullable String id) throws IOException, SecurityException { if (id == null) diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java deleted file mode 100644 index 70002395..00000000 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/InstallerSignalHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.kunmc.lab.teamkunpluginmanager.plugin.installer; - -import org.jetbrains.annotations.NotNull; - -/** - * {@link InstallerSignal} を受け取るハンドラーです。 - */ -@FunctionalInterface -public interface InstallerSignalHandler -{ - /** - * シグナルを受け取ります。 - * - * @param installProgress シグナルを受け取ったインストールの進捗状況 - * @param signal 受け取ったシグナル - * @param シグナルの型 - */ - void handleSignal(@NotNull InstallProgress installProgress, @NotNull T signal); -} diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java index 5b739695..d4cf5c19 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/install/PluginInstaller.java @@ -3,7 +3,6 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.install.signals.AlreadyInstalledPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.TaskResult; @@ -23,6 +22,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.PluginResolveTask; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.PluginLoader; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -49,7 +49,7 @@ */ public class PluginInstaller extends AbstractInstaller { - public PluginInstaller(@NotNull InstallerSignalHandler signalHandler) throws IOException + public PluginInstaller(@NotNull SignalHandleManager signalHandler) throws IOException { super(signalHandler); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java index 7d06a939..3632ef81 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/impls/uninstall/PluginUninstaller.java @@ -3,7 +3,6 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.AbstractInstaller; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallResult; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.PluginIsDependencySignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.impls.uninstall.signals.SearchingPluginSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.signals.assertion.IgnoredPluginSignal; @@ -13,6 +12,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallArgument; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallResult; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.UnInstallTask; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import net.kunmc.lab.teamkunpluginmanager.utils.ReversedCollector; import org.bukkit.Bukkit; @@ -40,7 +40,7 @@ */ public class PluginUninstaller extends AbstractInstaller { - public PluginUninstaller(InstallerSignalHandler signalHandler) throws IOException + public PluginUninstaller(SignalHandleManager signalHandler) throws IOException { super(signalHandler); } diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java index 312718cc..25ca8494 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/InstallTask.java @@ -3,7 +3,7 @@ import lombok.AllArgsConstructor; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; /** @@ -24,7 +24,7 @@ public abstract class InstallTask { // TODO: きれいに - private final InstallerSignalHandler signalHandler; + private final SignalHandleManager signalHandler; private final DependsCollectStatus status; private DependsCollectState taskState; - public DependsCollectTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + public DependsCollectTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java index e05b84e7..43be1dd3 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/dependencies/computer/DependsComputeOrderTask.java @@ -1,10 +1,10 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.computer.signals.DependsLoadOrderComputingSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.jetbrains.annotations.NotNull; @@ -27,7 +27,7 @@ public class DependsComputeOrderTask extends InstallTask progress, @NotNull InstallerSignalHandler signalHandler) + public DependsComputeOrderTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java index f5a56f7e..77ccff69 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/description/DescriptionLoadTask.java @@ -1,9 +1,9 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.description.signals.LoadPluginDescriptionSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; @@ -19,7 +19,7 @@ public class DescriptionLoadTask extends InstallTask progress, @NotNull InstallerSignalHandler signalHandler) + public DescriptionLoadTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); this.taskState = DescriptionLoadState.INITIALIZED; diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java index bd79aedd..9930a512 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/download/DownloadTask.java @@ -1,12 +1,12 @@ package net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadErrorSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadProgressSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadStartingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.download.signals.DownloadSucceedSignal; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.http.DownloadProgress; import net.kunmc.lab.teamkunpluginmanager.utils.http.RequestMethod; import net.kunmc.lab.teamkunpluginmanager.utils.http.Requests; @@ -26,7 +26,7 @@ public class DownloadTask extends InstallTask private DownloadState taskState; - public DownloadTask(@NotNull InstallProgress progress, @NotNull InstallerSignalHandler signalHandler) + public DownloadTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java index b4b36c4b..be51e362 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/install/PluginsInstallTask.java @@ -3,7 +3,6 @@ import net.kunmc.lab.peyangpaperutils.lib.utils.Runner; import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.dependencies.DependencyElement; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginEnablingSignal; @@ -12,6 +11,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginOnLoadRunningSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.install.signals.PluginRelocatingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; import org.bukkit.entity.Player; @@ -51,7 +51,7 @@ public class PluginsInstallTask extends InstallTask progress, @NotNull InstallerSignalHandler signalHandler) + public PluginsInstallTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java index 52315368..c9338138 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/resolve/PluginResolveTask.java @@ -2,7 +2,6 @@ import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.MultiplePluginResolvedSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.resolve.signals.PluginResolveErrorSignal; @@ -12,6 +11,7 @@ import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.MultiResult; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.ResolveResult; import net.kunmc.lab.teamkunpluginmanager.plugin.resolver.result.SuccessResult; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,7 +29,7 @@ public class PluginResolveTask extends InstallTask progress, @NotNull InstallerSignalHandler signalHandler) + public PluginResolveTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java index 5b879291..5a65179d 100644 --- a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/installer/task/tasks/uninstall/UnInstallTask.java @@ -4,12 +4,12 @@ import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager; import net.kunmc.lab.teamkunpluginmanager.plugin.DependencyTree; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; -import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignalHandler; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.InstallTask; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginDisablingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginRegisteredRecipeSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.installer.task.tasks.uninstall.signals.PluginUnloadingSignal; import net.kunmc.lab.teamkunpluginmanager.plugin.loader.CommandsPatcher; +import net.kunmc.lab.teamkunpluginmanager.plugin.signal.SignalHandleManager; import net.kunmc.lab.teamkunpluginmanager.utils.PluginUtil; import org.bukkit.Bukkit; import org.bukkit.Keyed; @@ -78,7 +78,7 @@ public class UnInstallTask extends InstallTask progress, @NotNull InstallerSignalHandler signalHandler) + public UnInstallTask(@NotNull InstallProgress progress, @NotNull SignalHandleManager signalHandler) { super(progress, signalHandler); diff --git a/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java new file mode 100644 index 00000000..982215f4 --- /dev/null +++ b/src/main/java/net/kunmc/lab/teamkunpluginmanager/plugin/signal/SignalHandleManager.java @@ -0,0 +1,82 @@ +package net.kunmc.lab.teamkunpluginmanager.plugin.signal; + +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallProgress; +import net.kunmc.lab.teamkunpluginmanager.plugin.installer.InstallerSignal; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * シグナルを受け取り、処理を行うクラスです。 + * シグナルは、{@link SignalHandler}アノテーションを付与したメソッドによって処理され、以下のシグニチャを持つ必要があります。 + *