mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-12-23 05:08:47 +00:00
新增自动获取最新版本功能...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
bf61d4125a
commit
31cb47578f
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<artifactId>Yum</artifactId>
|
||||
<version>1.8</version>
|
||||
<version>1.8.1</version>
|
||||
<name>Yum</name>
|
||||
<description>Minecraft 服务器插件管理系统</description>
|
||||
<build>
|
||||
@ -55,7 +55,7 @@
|
||||
</build>
|
||||
<properties>
|
||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||
<update.description>&c大版本更新 &a全版本兼容...</update.description>
|
||||
<update.description>&b新增自动获取最新版本功能...</update.description>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
|
@ -2,33 +2,56 @@ package cn.citycraft.Yum.manager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import cn.citycraft.PluginHelper.utils.IOUtil;
|
||||
import cn.citycraft.Yum.manager.RepoSerialization.Plugin;
|
||||
import cn.citycraft.Yum.manager.RepoSerialization.TagInfo;
|
||||
|
||||
public class PluginInfo {
|
||||
public String branch;
|
||||
public String name;
|
||||
public Plugin plugin;
|
||||
public String pom;
|
||||
public String repo;
|
||||
public List<TagInfo> tags;
|
||||
public String url;
|
||||
|
||||
public String getFileName() {
|
||||
return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version);
|
||||
return getFileName(plugin.version);
|
||||
}
|
||||
|
||||
public String getMavenUrl() {
|
||||
return getMavenUrl(null);
|
||||
public String getFileName(final String version) {
|
||||
return String.format("%1$s-%2$s.jar", plugin.artifactId, version);
|
||||
}
|
||||
|
||||
public String getMavenUrl(final String version) {
|
||||
public String getMavenUrl(final CommandSender sender, final String version) {
|
||||
String ver = version;
|
||||
if (ver == null && tags != null) {
|
||||
if (ver == null) {
|
||||
if (tags != null) {
|
||||
for (final TagInfo tagInfo : tags) {
|
||||
if (tagInfo.tag.equalsIgnoreCase("1.7.10")) {
|
||||
sender.sendMessage("§6版本: §b从Tag标签中获取最新版本...");
|
||||
ver = tagInfo.version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", plugin.groupId.replace(".", "/"), plugin.artifactId, ver == null ? plugin.version : ver);
|
||||
} else if (pom != null && !pom.isEmpty()) {
|
||||
pom = pom.replace("[name]", plugin.name).replace("[branch]", branch);
|
||||
sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本...");
|
||||
ver = IOUtil.getXMLTag(pom, "version", plugin.version);
|
||||
if (ver != null) {
|
||||
sender.sendMessage("§6版本: §a成功获取到最新版本 " + ver + " ...");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ver == null) {
|
||||
ver = plugin.version;
|
||||
sender.sendMessage("§6版本: §a使用缓存的版本 " + ver + " ...");
|
||||
}
|
||||
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar",
|
||||
plugin.groupId.replace(".", "/"),
|
||||
plugin.artifactId,
|
||||
(ver == null || ver.isEmpty()) ? plugin.version : ver);
|
||||
}
|
||||
}
|
@ -320,8 +320,8 @@ public class PluginsManager {
|
||||
sender.sendMessage("§c文件: " + name + " 不是一个可载入的插件!");
|
||||
return false;
|
||||
} catch (final UnknownDependencyException e) {
|
||||
sender.sendMessage("§4异常: §c" + e.getMessage());
|
||||
sender.sendMessage("§c插件: " + name + " 缺少部分依赖项目!");
|
||||
sender.sendMessage("§4异常: §c服务器未安装必须依赖: " + e.getMessage());
|
||||
sender.sendMessage("§c插件: " + name + " 载入失败 缺少部分依赖项目!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -16,14 +16,17 @@ public class RepoSerialization {
|
||||
public class PackageInfo {
|
||||
public String name;
|
||||
public List<Plugin> plugins = new ArrayList<>();
|
||||
public String pom;
|
||||
public String url;
|
||||
}
|
||||
|
||||
public class Plugin {
|
||||
public String artifactId;
|
||||
public String branch;
|
||||
public String description;
|
||||
public String groupId;
|
||||
public String name;
|
||||
public String pom;
|
||||
public List<TagInfo> tags;
|
||||
public String version;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class RepositoryManager {
|
||||
public List<String> getAllPluginName() {
|
||||
final List<String> li = new ArrayList<String>();
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
li.add(plugin.getValue().plugin.name);
|
||||
li.add(plugin.getValue().name);
|
||||
}
|
||||
return li;
|
||||
}
|
||||
@ -105,7 +105,7 @@ public class RepositoryManager {
|
||||
|
||||
public PluginInfo getPlugin(final String name) {
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
if (plugin.getValue().plugin.name.equalsIgnoreCase(name)) {
|
||||
if (plugin.getValue().name.equalsIgnoreCase(name)) {
|
||||
return plugin.getValue();
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ public class RepositoryManager {
|
||||
public List<PluginInfo> getPluginInfo(final String name) {
|
||||
final List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
if (plugin.getValue().plugin.name.equalsIgnoreCase(name)) {
|
||||
if (plugin.getValue().name.equalsIgnoreCase(name)) {
|
||||
li.add(plugin.getValue());
|
||||
}
|
||||
}
|
||||
@ -161,6 +161,9 @@ public class RepositoryManager {
|
||||
public void updatePackage(final CommandSender sender, final PackageInfo pkg) {
|
||||
for (final Plugin plugin : pkg.plugins) {
|
||||
final PluginInfo pi = new PluginInfo();
|
||||
pi.name = plugin.name == null ? plugin.artifactId : plugin.name;
|
||||
pi.branch = plugin.branch == null ? "master" : plugin.branch;
|
||||
pi.pom = plugin.pom == null ? pkg.pom : plugin.pom;
|
||||
pi.plugin = plugin;
|
||||
pi.url = pkg.url;
|
||||
pi.repo = pkg.name;
|
||||
|
@ -34,7 +34,7 @@ public class YumManager {
|
||||
public static boolean install(final CommandSender sender, final String pluginname, final String version) {
|
||||
final PluginInfo pi = repo.getPlugin(pluginname);
|
||||
if (pi != null) {
|
||||
if (download.run(sender, pi.getMavenUrl(version), new File("plugins", pi.plugin.name + ".jar"))) {
|
||||
if (download.run(sender, pi.getMavenUrl(sender, version), new File("plugins", pi.plugin.name + ".jar"))) {
|
||||
return plugman.load(sender, pluginname);
|
||||
}
|
||||
}
|
||||
@ -48,7 +48,7 @@ public class YumManager {
|
||||
public static boolean update(final CommandSender sender, final Plugin plugin, final String version) {
|
||||
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||
if (pi != null) {
|
||||
if (download.run(sender, pi.getMavenUrl(version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
||||
if (download.run(sender, pi.getMavenUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
||||
sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!");
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user