mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-25 15:58:46 +00:00
add check repo url null...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
734ba2ae46
commit
0b3105297a
@ -27,10 +27,5 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
@ -1,69 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<artifactId>Yum</artifactId>
|
||||
<name>Yum</name>
|
||||
<version>1.3.2</version>
|
||||
<description>Minecraft 服务器插件管理系统</description>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>${project.name}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>cn.citycraft:PluginUtils</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>citycraft-repo</id>
|
||||
<url>http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.8.3-R0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
|
@ -15,16 +15,16 @@ import java.util.Map.Entry;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import cn.citycraft.Yum.repository.Package;
|
||||
import cn.citycraft.Yum.repository.Plugin;
|
||||
import cn.citycraft.Yum.repository.PluginInfo;
|
||||
import cn.citycraft.Yum.repository.Repository;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import cn.citycraft.Yum.repository.Package;
|
||||
import cn.citycraft.Yum.repository.Plugin;
|
||||
import cn.citycraft.Yum.repository.PluginInfo;
|
||||
import cn.citycraft.Yum.repository.Repository;
|
||||
|
||||
/**
|
||||
* 仓库管理类
|
||||
*
|
||||
@ -44,18 +44,22 @@ public class RepositoryManager {
|
||||
repos = new ArrayList<String>();
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
plugins.clear();
|
||||
public boolean addPackage(String urlstring) {
|
||||
String json = getHtml(urlstring);
|
||||
if (json == "")
|
||||
return false;
|
||||
Package pkg = jsonToPackage(json);
|
||||
if (pkg == null)
|
||||
return false;
|
||||
updatePackage(pkg);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updatePackage(Package pkg) {
|
||||
for (Plugin plugin : pkg.plugins) {
|
||||
PluginInfo pi = new PluginInfo();
|
||||
pi.plugin = plugin;
|
||||
pi.url = pkg.url;
|
||||
pi.repo = pkg.name;
|
||||
plugins.put(plugin.groupId + "." + plugin.artifactId, pi);
|
||||
}
|
||||
public boolean addRepositories(String urlstring) {
|
||||
if (urlstring == null || urlstring.isEmpty())
|
||||
return false;
|
||||
repos.add(urlstring);
|
||||
return updateRepositories(urlstring);
|
||||
}
|
||||
|
||||
public void cacheToJson(FileConfiguration config) {
|
||||
@ -63,6 +67,66 @@ public class RepositoryManager {
|
||||
config.set("plugincache", gson.toJson(plugins));
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
plugins.clear();
|
||||
}
|
||||
|
||||
public List<PluginInfo> getAllPlugin() {
|
||||
List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet())
|
||||
li.add(plugin.getValue());
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<String> getAllPluginName() {
|
||||
List<String> li = new ArrayList<String>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet())
|
||||
li.add(plugin.getValue().plugin.artifactId);
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<String> getAllPluginsInfo() {
|
||||
List<String> li = new ArrayList<String>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
|
||||
Plugin pl = plugin.getValue().plugin;
|
||||
li.add(String.format("§d%s §a%s(%s) §6- §e%s", plugin.getValue().repo, pl.artifactId, pl.version, pl.description));
|
||||
}
|
||||
return li;
|
||||
}
|
||||
|
||||
public String getHtml(String urlstring) {
|
||||
String html = "";
|
||||
try {
|
||||
URL url = new URL(urlstring);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
html += line;
|
||||
return html;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public PluginInfo getPlugin(String name) {
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet())
|
||||
if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name))
|
||||
return plugin.getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<PluginInfo> getPluginInfo(String name) {
|
||||
List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet())
|
||||
if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name))
|
||||
li.add(plugin.getValue());
|
||||
return li;
|
||||
}
|
||||
|
||||
public PluginInfo getPluginInfo(String groupId, String artifactId) {
|
||||
return plugins.get(groupId + "." + artifactId);
|
||||
}
|
||||
|
||||
public boolean jsonToCache(FileConfiguration config) {
|
||||
String repocache = config.getString("repocache");
|
||||
String plugincache = config.getString("plugincache");
|
||||
@ -79,112 +143,14 @@ public class RepositoryManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateRepositories(CommandSender sender) {
|
||||
plugins.clear();
|
||||
for (String string : repos) {
|
||||
if (updateRepositories(string)) {
|
||||
sender.sendMessage("§6源: §e" + string + " §a更新成功!");
|
||||
} else {
|
||||
sender.sendMessage("§6源: §e" + string + " §c更新失败!");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addRepositories(String urlstring) {
|
||||
repos.add(urlstring);
|
||||
return updateRepositories(urlstring);
|
||||
}
|
||||
|
||||
public boolean updateRepositories(String urlstring) {
|
||||
String json = getHtml(urlstring);
|
||||
if (json == "") {
|
||||
return false;
|
||||
}
|
||||
List<Repository> lrepo = jsonToRepositories(json);
|
||||
if (lrepo == null) {
|
||||
return false;
|
||||
}
|
||||
for (Repository repository : lrepo) {
|
||||
addPackage(repository.url);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addPackage(String urlstring) {
|
||||
String json = getHtml(urlstring);
|
||||
if (json == "") {
|
||||
return false;
|
||||
}
|
||||
Package pkg = jsonToPackage(json);
|
||||
if (pkg == null) {
|
||||
return false;
|
||||
}
|
||||
updatePackage(pkg);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getHtml(String urlstring) {
|
||||
String html = "";
|
||||
public Package jsonToPackage(String json) {
|
||||
try {
|
||||
URL url = new URL(urlstring);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
html += line;
|
||||
}
|
||||
return html;
|
||||
} catch (IOException e) {
|
||||
return gson.fromJson(json, Package.class);
|
||||
} catch (JsonSyntaxException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public PluginInfo getPluginInfo(String groupId, String artifactId) {
|
||||
return plugins.get(groupId + "." + artifactId);
|
||||
}
|
||||
|
||||
public PluginInfo getPlugin(String name) {
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
|
||||
if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name))
|
||||
return plugin.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<PluginInfo> getAllPlugin() {
|
||||
List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
|
||||
li.add(plugin.getValue());
|
||||
}
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<String> getAllPluginName() {
|
||||
List<String> li = new ArrayList<String>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
|
||||
li.add(plugin.getValue().plugin.artifactId);
|
||||
}
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<String> getAllPluginsInfo() {
|
||||
List<String> li = new ArrayList<String>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
|
||||
Plugin pl = plugin.getValue().plugin;
|
||||
li.add(String.format("§d%s §a%s(%s) §6- §e%s", plugin.getValue().repo, pl.artifactId, pl.version, pl.description));
|
||||
}
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<PluginInfo> getPluginInfo(String name) {
|
||||
List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
|
||||
if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name))
|
||||
li.add(plugin.getValue());
|
||||
}
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<Repository> jsonToRepositories(String json) {
|
||||
try {
|
||||
return gson.fromJson(json, new TypeToken<List<Repository>>() {
|
||||
@ -194,11 +160,37 @@ public class RepositoryManager {
|
||||
}
|
||||
}
|
||||
|
||||
public Package jsonToPackage(String json) {
|
||||
try {
|
||||
return gson.fromJson(json, Package.class);
|
||||
} catch (JsonSyntaxException e) {
|
||||
return null;
|
||||
public void updatePackage(Package pkg) {
|
||||
for (Plugin plugin : pkg.plugins) {
|
||||
PluginInfo pi = new PluginInfo();
|
||||
pi.plugin = plugin;
|
||||
pi.url = pkg.url;
|
||||
pi.repo = pkg.name;
|
||||
plugins.put(plugin.groupId + "." + plugin.artifactId, pi);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateRepositories(CommandSender sender) {
|
||||
plugins.clear();
|
||||
for (String string : repos)
|
||||
if (updateRepositories(string))
|
||||
sender.sendMessage("§6源: §e" + string + " §a更新成功!");
|
||||
else
|
||||
sender.sendMessage("§6源: §e" + string + " §c更新失败!");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateRepositories(String urlstring) {
|
||||
if (!urlstring.endsWith("repo.info"))
|
||||
urlstring = urlstring + "/repo.info";
|
||||
String json = getHtml(urlstring);
|
||||
if (json == "")
|
||||
return false;
|
||||
List<Repository> lrepo = jsonToRepositories(json);
|
||||
if (lrepo == null)
|
||||
return false;
|
||||
for (Repository repository : lrepo)
|
||||
addPackage(repository.url);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user