mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-12-23 13:18:46 +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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cn.citycraft</groupId>
|
<groupId>cn.citycraft</groupId>
|
||||||
<artifactId>Yum</artifactId>
|
<artifactId>Yum</artifactId>
|
||||||
<version>1.8</version>
|
<version>1.8.1</version>
|
||||||
<name>Yum</name>
|
<name>Yum</name>
|
||||||
<description>Minecraft 服务器插件管理系统</description>
|
<description>Minecraft 服务器插件管理系统</description>
|
||||||
<build>
|
<build>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</build>
|
</build>
|
||||||
<properties>
|
<properties>
|
||||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
<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>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -2,33 +2,56 @@ package cn.citycraft.Yum.manager;
|
|||||||
|
|
||||||
import java.util.List;
|
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.Plugin;
|
||||||
import cn.citycraft.Yum.manager.RepoSerialization.TagInfo;
|
import cn.citycraft.Yum.manager.RepoSerialization.TagInfo;
|
||||||
|
|
||||||
public class PluginInfo {
|
public class PluginInfo {
|
||||||
|
public String branch;
|
||||||
|
public String name;
|
||||||
public Plugin plugin;
|
public Plugin plugin;
|
||||||
|
public String pom;
|
||||||
public String repo;
|
public String repo;
|
||||||
public List<TagInfo> tags;
|
public List<TagInfo> tags;
|
||||||
public String url;
|
public String url;
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version);
|
return getFileName(plugin.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMavenUrl() {
|
public String getFileName(final String version) {
|
||||||
return getMavenUrl(null);
|
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;
|
String ver = version;
|
||||||
if (ver == null && tags != null) {
|
if (ver == null) {
|
||||||
|
if (tags != null) {
|
||||||
for (final TagInfo tagInfo : tags) {
|
for (final TagInfo tagInfo : tags) {
|
||||||
if (tagInfo.tag.equalsIgnoreCase("1.7.10")) {
|
if (tagInfo.tag.equalsIgnoreCase("1.7.10")) {
|
||||||
|
sender.sendMessage("§6版本: §b从Tag标签中获取最新版本...");
|
||||||
ver = tagInfo.version;
|
ver = tagInfo.version;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (pom != null && !pom.isEmpty()) {
|
||||||
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);
|
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 + " 不是一个可载入的插件!");
|
sender.sendMessage("§c文件: " + name + " 不是一个可载入的插件!");
|
||||||
return false;
|
return false;
|
||||||
} catch (final UnknownDependencyException e) {
|
} catch (final UnknownDependencyException e) {
|
||||||
sender.sendMessage("§4异常: §c" + e.getMessage());
|
sender.sendMessage("§4异常: §c服务器未安装必须依赖: " + e.getMessage());
|
||||||
sender.sendMessage("§c插件: " + name + " 缺少部分依赖项目!");
|
sender.sendMessage("§c插件: " + name + " 载入失败 缺少部分依赖项目!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,17 @@ public class RepoSerialization {
|
|||||||
public class PackageInfo {
|
public class PackageInfo {
|
||||||
public String name;
|
public String name;
|
||||||
public List<Plugin> plugins = new ArrayList<>();
|
public List<Plugin> plugins = new ArrayList<>();
|
||||||
|
public String pom;
|
||||||
public String url;
|
public String url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Plugin {
|
public class Plugin {
|
||||||
public String artifactId;
|
public String artifactId;
|
||||||
|
public String branch;
|
||||||
public String description;
|
public String description;
|
||||||
public String groupId;
|
public String groupId;
|
||||||
public String name;
|
public String name;
|
||||||
|
public String pom;
|
||||||
public List<TagInfo> tags;
|
public List<TagInfo> tags;
|
||||||
public String version;
|
public String version;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class RepositoryManager {
|
|||||||
public List<String> getAllPluginName() {
|
public List<String> getAllPluginName() {
|
||||||
final List<String> li = new ArrayList<String>();
|
final List<String> li = new ArrayList<String>();
|
||||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||||
li.add(plugin.getValue().plugin.name);
|
li.add(plugin.getValue().name);
|
||||||
}
|
}
|
||||||
return li;
|
return li;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ public class RepositoryManager {
|
|||||||
|
|
||||||
public PluginInfo getPlugin(final String name) {
|
public PluginInfo getPlugin(final String name) {
|
||||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
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();
|
return plugin.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public class RepositoryManager {
|
|||||||
public List<PluginInfo> getPluginInfo(final String name) {
|
public List<PluginInfo> getPluginInfo(final String name) {
|
||||||
final List<PluginInfo> li = new ArrayList<PluginInfo>();
|
final List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
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());
|
li.add(plugin.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,6 +161,9 @@ public class RepositoryManager {
|
|||||||
public void updatePackage(final CommandSender sender, final PackageInfo pkg) {
|
public void updatePackage(final CommandSender sender, final PackageInfo pkg) {
|
||||||
for (final Plugin plugin : pkg.plugins) {
|
for (final Plugin plugin : pkg.plugins) {
|
||||||
final PluginInfo pi = new PluginInfo();
|
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.plugin = plugin;
|
||||||
pi.url = pkg.url;
|
pi.url = pkg.url;
|
||||||
pi.repo = pkg.name;
|
pi.repo = pkg.name;
|
||||||
|
@ -34,7 +34,7 @@ public class YumManager {
|
|||||||
public static boolean install(final CommandSender sender, final String pluginname, final String version) {
|
public static boolean install(final CommandSender sender, final String pluginname, final String version) {
|
||||||
final PluginInfo pi = repo.getPlugin(pluginname);
|
final PluginInfo pi = repo.getPlugin(pluginname);
|
||||||
if (pi != null) {
|
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);
|
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) {
|
public static boolean update(final CommandSender sender, final Plugin plugin, final String version) {
|
||||||
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||||
if (pi != null) {
|
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直接升级)!");
|
sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user