Skip to content

Commit

Permalink
mcl: release 2.0.0-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Apr 11, 2022
1 parent dcdcc58 commit a566665
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

欢迎阅读命令行参数的[说明](cli.md),它将教会你如何`安装插件``禁用和启用脚本``修改包的更新频道`等基本操作。

开发者请参见 [MCL 开发文档](docs/README.md)
开发者请参见 [MCL 开发文档](docs/README.md)

## 简介

Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'org.itxtech'
version '2.0.0-beta.2'
version '2.0.0-beta.3'
description '模块化、轻量级且支持完全自定义的 mirai 加载器。'

repositories {
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ usage: mcl
-b,--show-boot-props Show Mirai Console boot properties
-c,--log-level <level> Set log level
-d,--disable-module <ModuleName> Disable module
--disable-auto-clear Disable Repo With Cache auto clear
-e,--enable-module <ModuleName> Enable module
--enable-auto-clear Enable Repo With Cache auto clear
-f,--set-boot-entry <EntryClass> Set Mirai Console boot entry
-g,--set-boot-args <Arguments> Set Mirai Console boot arguments
-i,--package-info <PackageName> Fetch info for specified package
Expand All @@ -69,7 +71,7 @@ usage: mcl
-n,--channel <Channel> Set update channel of package
-o,--show-repos Show Mirai Repo and Maven Repo
-p,--proxy <address> Set HTTP proxy
-q,--delete Delete old plugin and mirai files
-q,--delete Remove outdated files while updating
-r,--remove-package <PackageName> Remove package
-s,--list-packages List configured packages
-t,--type <Type> Set type of package
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/itxtech/mcl/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,4 @@ public static void appendJarFile(JarFile file) throws IOException {
instrumentation.appendToSystemClassLoaderSearch(file);
}
}

public static Class[] getLoadedClasses() {
return instrumentation.getAllLoadedClasses();
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/itxtech/mcl/component/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MclPackageIndex>() {
}.getType());
}
Expand Down Expand Up @@ -216,7 +216,7 @@ private String httpGet(String url, String server) throws Exception {

public static class MclPackageIndex {
public MclPackageIndexMetadata metadata;
public Map<String, PackageIndex> packages;
public Map<String, MclPackageIndexInfo> packages;
}

public static class MclPackageIndexMetadata {
Expand All @@ -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;
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/org/itxtech/mcl/module/builtin/Conf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/itxtech/mcl/module/builtin/PkgAnn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\"");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/itxtech/mcl/module/builtin/Repo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/org/itxtech/mcl/module/builtin/RepoCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, PackageInfo> 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;
}
}
}

0 comments on commit a566665

Please sign in to comment.