diff --git a/README.md b/README.md index 4a7a6c7..c30c2ed 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 欢迎阅读命令行参数的[说明](cli.md),它将教会你如何`安装插件`,`禁用和启用脚本`,`修改包的更新频道`等基本操作。 -开发者请参见 [MCL 开发文档](docs/README.md) +开发者请参见 [MCL 开发文档](docs/README.md)。 ## 简介 diff --git a/build.gradle b/build.gradle index ec4652d..54eafe2 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'org.itxtech' -version '2.0.0-beta.2' +version '2.0.0-beta.3' description '模块化、轻量级且支持完全自定义的 mirai 加载器。' repositories { @@ -62,6 +62,8 @@ task launchTest(type: JavaExec) { } task zipAll(type: Zip) { + dependsOn(fatJar) + from fileTree(dir: ".", includes: ["README.md", "LICENSE", "mcl", "mcl.cmd"]) from("$buildDir/libs") { include "mcl.jar" diff --git a/cli.md b/cli.md index 362a6c0..e40cc1f 100644 --- a/cli.md +++ b/cli.md @@ -56,7 +56,9 @@ usage: mcl -b,--show-boot-props Show Mirai Console boot properties -c,--log-level Set log level -d,--disable-module Disable module + --disable-auto-clear Disable Repo With Cache auto clear -e,--enable-module Enable module + --enable-auto-clear Enable Repo With Cache auto clear -f,--set-boot-entry Set Mirai Console boot entry -g,--set-boot-args Set Mirai Console boot arguments -i,--package-info Fetch info for specified package @@ -69,7 +71,7 @@ usage: mcl -n,--channel Set update channel of package -o,--show-repos Show Mirai Repo and Maven Repo -p,--proxy
Set HTTP proxy - -q,--delete Delete old plugin and mirai files + -q,--delete Remove outdated files while updating -r,--remove-package Remove package -s,--list-packages List configured packages -t,--type Set type of package diff --git a/src/main/java/org/itxtech/mcl/Agent.java b/src/main/java/org/itxtech/mcl/Agent.java index 86680dc..e546dd3 100644 --- a/src/main/java/org/itxtech/mcl/Agent.java +++ b/src/main/java/org/itxtech/mcl/Agent.java @@ -43,8 +43,4 @@ public static void appendJarFile(JarFile file) throws IOException { instrumentation.appendToSystemClassLoaderSearch(file); } } - - public static Class[] getLoadedClasses() { - return instrumentation.getAllLoadedClasses(); - } } diff --git a/src/main/java/org/itxtech/mcl/component/Repository.java b/src/main/java/org/itxtech/mcl/component/Repository.java index 0929286..ba6f6d7 100644 --- a/src/main/java/org/itxtech/mcl/component/Repository.java +++ b/src/main/java/org/itxtech/mcl/component/Repository.java @@ -64,7 +64,7 @@ public Repository(Loader loader) { } } - public MclPackageIndex fetchPackages() throws Exception { + public MclPackageIndex fetchPackageIndex() throws Exception { return new Gson().fromJson(httpGet("/packages.json"), new TypeToken() { }.getType()); } @@ -216,7 +216,7 @@ private String httpGet(String url, String server) throws Exception { public static class MclPackageIndex { public MclPackageIndexMetadata metadata; - public Map packages; + public Map packages; } public static class MclPackageIndexMetadata { @@ -225,7 +225,7 @@ public static class MclPackageIndexMetadata { public String commit; } - public static class PackageIndex { + public static class MclPackageIndexInfo { public String name; public String description; public String website; diff --git a/src/main/java/org/itxtech/mcl/module/builtin/Conf.java b/src/main/java/org/itxtech/mcl/module/builtin/Conf.java index f434f47..974407c 100644 --- a/src/main/java/org/itxtech/mcl/module/builtin/Conf.java +++ b/src/main/java/org/itxtech/mcl/module/builtin/Conf.java @@ -113,19 +113,23 @@ public void cli() { } if (loader.cli.hasOption("a")) { var name = loader.cli.getOptionValue("a"); - var pkg = loader.packageManager.getPackage(name); - if (pkg != null) { + if (!name.contains(":")) { + loader.logger.error("Invalid package \"" + name + "\""); + } else { + var pkg = loader.packageManager.getPackage(name); + if (pkg != null) { + updatePackage(pkg); + loader.logger.info("Package \"" + pkg.id + "\" has been updated."); + loader.saveConfig(); + loader.exit(0); + return; + } + pkg = new MclPackage(name); updatePackage(pkg); - loader.logger.info("Package \"" + pkg.id + "\" has been updated."); + loader.packageManager.addPackage(pkg); + loader.logger.info("Package \"" + pkg.id + "\" has been added."); loader.saveConfig(); - loader.exit(0); - return; } - pkg = new MclPackage(name); - updatePackage(pkg); - loader.packageManager.addPackage(pkg); - loader.logger.info("Package \"" + pkg.id + "\" has been added."); - loader.saveConfig(); loader.exit(0); } } diff --git a/src/main/java/org/itxtech/mcl/module/builtin/PkgAnn.java b/src/main/java/org/itxtech/mcl/module/builtin/PkgAnn.java index 176e09f..22f52e2 100644 --- a/src/main/java/org/itxtech/mcl/module/builtin/PkgAnn.java +++ b/src/main/java/org/itxtech/mcl/module/builtin/PkgAnn.java @@ -36,10 +36,12 @@ public String getName() { public void boot() { for (var pkg : loader.packageManager.getPackages()) { try { - var info = loader.repo.fetchPackage(pkg.id); - if (info.announcement != null) { - loader.logger.info(Ansi.ansi().fgBrightYellow().a(info.getName(pkg.id)).reset().a(" Announcement:")); - loader.logger.println(info.announcement); + if (!pkg.channel.startsWith("maven")) { + var info = loader.repo.fetchPackage(pkg.id); + if (info.announcement != null) { + loader.logger.info(Ansi.ansi().fgBrightYellow().a(info.getName(pkg.id)).reset().a(" Announcement:")); + loader.logger.println(info.announcement); + } } } catch (Exception e) { loader.logger.error("Failed to fetch announcement for \"" + pkg.id + "\""); diff --git a/src/main/java/org/itxtech/mcl/module/builtin/Repo.java b/src/main/java/org/itxtech/mcl/module/builtin/Repo.java index a112325..0449268 100644 --- a/src/main/java/org/itxtech/mcl/module/builtin/Repo.java +++ b/src/main/java/org/itxtech/mcl/module/builtin/Repo.java @@ -52,7 +52,7 @@ public void cli() { try { if (loader.cli.hasOption("j")) { loader.logger.info("Fetching packages from " + loader.config.miraiRepo); - var index = loader.repo.fetchPackages(); + var index = loader.repo.fetchPackageIndex(); loader.logger.info("---------- Mirai Repo Index Metadata ----------"); loader.logger.info("Name: " + index.metadata.name); diff --git a/src/main/java/org/itxtech/mcl/module/builtin/RepoCache.java b/src/main/java/org/itxtech/mcl/module/builtin/RepoCache.java index 29478cf..e1d8be2 100644 --- a/src/main/java/org/itxtech/mcl/module/builtin/RepoCache.java +++ b/src/main/java/org/itxtech/mcl/module/builtin/RepoCache.java @@ -35,20 +35,20 @@ public class RepoCache extends MclModule { @Override public String getName() { - return "repowithcache"; + return "repocache"; } @Override public void prepare() { var clearGroup = new OptionGroup(); - clearGroup.addOption(Option.builder().desc("Disable Repo With Cache auto clear") + clearGroup.addOption(Option.builder().desc("Disable Repo Cache auto clear") .longOpt("disable-auto-clear").build()); - clearGroup.addOption(Option.builder().desc("Enable Repo With Cache auto clear") + clearGroup.addOption(Option.builder().desc("Enable Repo Cache auto clear") .longOpt("enable-auto-clear").build()); loader.options.addOptionGroup(clearGroup); loader.repo = new RepoWithCache(loader.repo); - loader.logger.debug("RepoWithCache has been initialized. Run \"./mcl --disable-module repowithcache\" to disable."); + loader.logger.debug("RepoCache has been initialized. Run \"./mcl --disable-module repocache\" to disable."); } @Override @@ -63,26 +63,40 @@ public void cli() { @Override public void boot() { - if (loader.config.moduleProps.getOrDefault(AUTO_CLEAR_KEY, "true").equals("true")) { + if (loader.config.moduleProps.getOrDefault(AUTO_CLEAR_KEY, "true").equals("true") && + loader.repo instanceof RepoWithCache) { + ((RepoWithCache) loader.repo).clearCache(); loader.logger.debug("RepoWithCache has been cleared"); } } public static class RepoWithCache extends Repository { private final HashMap packageInfoCache = new HashMap<>(); + private MclPackageIndex indexCache = null; public RepoWithCache(Repository base) { super(base.loader); } + public void clearCache() { + indexCache = null; + packageInfoCache.clear(); + } + @Override public PackageInfo fetchPackage(String id) throws Exception { - if (packageInfoCache.containsKey(id)) { - return packageInfoCache.get(id); + if (!packageInfoCache.containsKey(id)) { + packageInfoCache.put(id, super.fetchPackage(id)); + } + return packageInfoCache.get(id); + } + + @Override + public MclPackageIndex fetchPackageIndex() throws Exception { + if (indexCache == null) { + indexCache = super.fetchPackageIndex(); } - var info = super.fetchPackage(id); - packageInfoCache.put(id, info); - return info; + return indexCache; } } }