1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-21 01:38:51 +00:00

feat: 调整订阅类 添加单元测试

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-06-07 00:37:33 +08:00
parent 4f7b4c9c0f
commit 791366f5f0
4 changed files with 217 additions and 12 deletions

View File

@ -23,10 +23,22 @@ import pw.yumc.YumCore.annotation.NotProguard;
public class Log {
private static boolean fullDebug = new File(String.format("plugins%1$sYumCore%1$sfulldebug", File.separatorChar)).exists();
private static boolean globalDebug = new File(String.format("plugins%1$sYumCore%1$sdebug", File.separatorChar)).exists();
private static boolean debug = globalDebug || P.getDescription().getVersion().contains("DEV");
private static Logger logger = P.instance.getLogger();
private static CommandSender console = Bukkit.getConsoleSender();
private static String prefix = String.format("§6[§b%s§6]§r ", P.instance.getName());
private static boolean debug;
private static Logger logger;
private static CommandSender console;
private static String prefix;
static {
try {
debug = globalDebug || P.getDescription().getVersion().contains("DEV");
logger = P.instance.getLogger();
console = Bukkit.getConsoleSender();
prefix = String.format("§6[§b%s§6]§r ", P.instance.getName());
} catch (Throwable ex) {
logger = Logger.getLogger("YumCore");
debug = true;
d(ex);
}
}
private Log() {
}

View File

@ -44,7 +44,6 @@ public class SubscribeTask implements Runnable, Listener {
* 插件实例
*/
private static JavaPlugin instance;
private static String version;
static {
try {
@ -52,7 +51,6 @@ public class SubscribeTask implements Runnable, Listener {
Field field = pluginClassLoader.getClass().getDeclaredField("plugin");
field.setAccessible(true);
instance = (JavaPlugin) field.get(pluginClassLoader);
version = instance.getDescription().getVersion();
} catch (Exception e) {
Log.d(e);
}
@ -114,7 +112,7 @@ public class SubscribeTask implements Runnable, Listener {
*/
public SubscribeTask(String branch, boolean isSecret, UpdateType type) {
updateFile = new UpdateFile(instance);
versionInfo = new VersionInfo(branch, isSecret);
versionInfo = new VersionInfo(instance, branch, isSecret);
updateType = type;
if (instance.isEnabled()) {
Bukkit.getPluginManager().registerEvents(this, instance);
@ -150,7 +148,7 @@ public class SubscribeTask implements Runnable, Listener {
}
}
updateFile.update(updateType.getDownloadUrl(instance, result));
Log.d(Encrypt.decode("嘊⚲哀嘖⚶哅嘣⚩咖嗕♧哏嗕⚸咁嘨♢咰嘤♢哒嗚⚵呼嗣♰咊"), instance.getName(), version.split("-")[0], result);
Log.d(Encrypt.decode("嘊⚲哀嘖⚶哅嘣⚩咖嗕♧哏嗕⚸咁嘨♢咰嘤♢哒嗚⚵呼嗣♰咊"), instance.getName(), versionInfo.getVersion(), result);
versionInfo.notify(Bukkit.getConsoleSender());
}
} catch (Exception e) {
@ -245,6 +243,7 @@ public class SubscribeTask implements Runnable, Listener {
}
public static class VersionInfo {
/**
* 直链POM
*/
@ -256,18 +255,34 @@ public class SubscribeTask implements Runnable, Listener {
private String pom = Encrypt.decode("嘝⚶哐嘥♼咋嗤⚥哅嗣⚻哑嘢⚥咊嘥⚹咋嘟⚱咾嗤♧哏嗤⚮咽嘨⚶咯嘪⚥咿嘚⚵哏嘛⚷哈嗷⚷哅嘡⚦咋嘖⚴哐嘞⚨咽嘘⚶咋嘥⚱哉嗣⚺哉嘡");
// private static String pom = "http://ci.yumc.pw/job/%s/lastSuccessfulBuild/artifact/pom.xml";
/**
* 插件名称
*/
private final String name;
/**
* 插件版本
*/
private final String version;
/**
* 插件信息地址
*/
private String info;
/**
* POM文件文档
*/
private Document document;
public VersionInfo(String branch, boolean isSecret) {
info = String.format(isSecret ? pom : url, instance.getName(), branch);
public VersionInfo(Plugin plugin, String branch, boolean isSecret) {
this.name = plugin.getName();
this.version = plugin.getDescription().getVersion().split("-")[0];
this.info = String.format(isSecret ? pom : url, name, branch);
}
/**
* @return 插件版本
*/
public String getVersion() {
return version;
}
/**
@ -331,7 +346,7 @@ public class SubscribeTask implements Runnable, Listener {
* 命令接受者
*/
public void notify(CommandSender sender) {
Log.sender(sender, "§a插件更新: §b" + instance.getName() + " §a已更新到最新版本 §bv" + getLastestVersion());
Log.sender(sender, "§a插件更新: §b" + name + " §a已更新到最新版本 §bv" + getLastestVersion());
Log.sender(sender, "§e版本简介: §a" + getUpdateDescription());
final String[] changes = getUpdateChanges();
if (changes.length != 0) {

View File

@ -0,0 +1,146 @@
package pw.yumc.YumCore.plugin;
import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import com.avaje.ebean.EbeanServer;
/**
* @author
* @since 2017/6/2
*/
public class FakePlugin implements Plugin {
private String name;
private String version;
private String mainclass;
private PluginDescriptionFile descriptionFile;
public FakePlugin(String name, String version) {
super();
this.name = name;
this.version = version;
this.mainclass = getClass().getName();
this.descriptionFile = new PluginDescriptionFile(name, version, mainclass);
}
@Override
public File getDataFolder() {
return new File(name);
}
@Override
public PluginDescriptionFile getDescription() {
return descriptionFile;
}
@Override
public FileConfiguration getConfig() {
return null;
}
@Override
public InputStream getResource(String s) {
return null;
}
@Override
public void saveConfig() {
}
@Override
public void saveDefaultConfig() {
}
@Override
public void saveResource(String s, boolean b) {
}
@Override
public void reloadConfig() {
}
@Override
public PluginLoader getPluginLoader() {
return null;
}
@Override
public Server getServer() {
return null;
}
@Override
public boolean isEnabled() {
return false;
}
@Override
public void onDisable() {
}
@Override
public void onLoad() {
}
@Override
public void onEnable() {
}
@Override
public boolean isNaggable() {
return false;
}
@Override
public void setNaggable(boolean b) {
}
@Override
public EbeanServer getDatabase() {
return null;
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String s, String s1) {
return null;
}
@Override
public Logger getLogger() {
return null;
}
@Override
public String getName() {
return name;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
return false;
}
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
return null;
}
}

View File

@ -0,0 +1,32 @@
package pw.yumc.YumCore.update;
import java.io.IOException;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import org.bukkit.plugin.Plugin;
import org.junit.Test;
import org.xml.sax.SAXException;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.plugin.FakePlugin;
/**
* @author
* @since 2017/6/1
*/
public class SubscribeTaskTest {
private Plugin plugin = new FakePlugin("YumCore", "1.0");
@Test
public void test() throws IOException, SAXException, ParserConfigurationException {
SubscribeTask.VersionInfo info = new SubscribeTask.VersionInfo(plugin, "master", true);
info.update();
Log.d("Currect Version: %s", info.getVersion());
Log.d("New Version: %s", info.getNewVersion());
boolean nu = info.needUpdate(info.getNewVersion(), plugin.getDescription().getVersion());
Log.d("Need Update: %s", nu);
Log.d("File URL: %s", SubscribeTask.UpdateType.WS.getDownloadUrl(plugin, info.getNewVersion()));
}
}