forked from xjboss/KCauldronX
Fix updater
This commit is contained in:
parent
f27a9310b6
commit
997543753e
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -1,6 +1,6 @@
|
||||
[submodule "bukkit"]
|
||||
path = bukkit
|
||||
url = https://prok.pw/gitlab/Prototik/KCauldron-Bukkit.git
|
||||
url = https://gitlab.prok.pw/Prototik/KCauldron-Bukkit.git
|
||||
[submodule "forge"]
|
||||
path = forge
|
||||
url = https://github.com/MinecraftForge/MinecraftForge.git
|
||||
|
10
build.gradle
10
build.gradle
@ -21,7 +21,7 @@ buildscript {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url 'https://prok.pw/repo' }
|
||||
maven { url 'https://repo.prok.pw/' }
|
||||
jcenter()
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ ext.buildInfoCached = null;
|
||||
def buildInfo(String key) {
|
||||
if (!buildInfoCached) {
|
||||
if (project.hasProperty('officialBuild')) {
|
||||
buildInfoCached = new JsonSlurper().parse(new URL("https://prok.pw/version/${group}/${name}"))
|
||||
buildInfoCached = new JsonSlurper().parse(new URL("https://api.prok.pw/repo/version/${group}/${name}"))
|
||||
} else {
|
||||
buildInfoCached = [
|
||||
nextBuildNumber: 'UNOFFICIAL',
|
||||
@ -194,7 +194,7 @@ task packageChangelog(type: CreateChangelog) {
|
||||
onlyIf { project.hasProperty('officialBuild') }
|
||||
classifier = 'changelog'
|
||||
extension = 'txt'
|
||||
oldChangelogUrl = "https://prok.pw/repo/${project.group.replace('.', '/')}/${project.name}/${buildInfo('version')}/${project.name}-${buildInfo('version')}-changelog.txt"
|
||||
oldChangelogUrl = "https://repo.prok.pw/${project.group.replace('.', '/')}/${project.name}/${buildInfo('version')}/${project.name}-${buildInfo('version')}-changelog.txt"
|
||||
hash = gitInfo('hash')
|
||||
message = gitInfo('message')
|
||||
version = project.version
|
||||
@ -239,7 +239,7 @@ def getSignatureFiles = {
|
||||
return [
|
||||
[archive: signedServer, classifier: 'server', extension: 'jar.asc'],
|
||||
[archive: signedChangelog, classifier: 'changelog', extension: 'txt.asc'],
|
||||
[archive: signedBundle, classifier: 'bundle', extension: 'jar.asc'],
|
||||
[archive: signedBundle, classifier: 'bundle', extension: 'zip.asc'],
|
||||
[archive: signedJar, classifier: null, extension: 'jar.asc']
|
||||
]
|
||||
}
|
||||
@ -248,7 +248,7 @@ publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name 'ProK'
|
||||
url 'https://prok.pw/repo/'
|
||||
url 'https://repo.prok.pw/'
|
||||
credentials {
|
||||
username project.hasProperty('prokRepoUsername') ? prokRepoUsername : null
|
||||
password project.hasProperty('prokRepoPassword') ? prokRepoPassword : null
|
||||
|
@ -32,6 +32,7 @@ public class KCauldron {
|
||||
sServerLocation = new File(jarFilePath);
|
||||
|
||||
sCurrentVersion = version;
|
||||
sGroup = manifest.getProperty("KCauldron-Group");
|
||||
sBranch = manifest.getProperty("KCauldron-Branch");
|
||||
sChannel = manifest.getProperty("KCauldron-Channel");
|
||||
break;
|
||||
@ -41,10 +42,6 @@ public class KCauldron {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String home = System.getenv("KCAULDRON_HOME");
|
||||
if (home != null) {
|
||||
sServerLocation = new File(home);
|
||||
}
|
||||
}
|
||||
|
||||
private static String sCurrentVersion;
|
||||
@ -61,6 +58,28 @@ public class KCauldron {
|
||||
return sServerLocation;
|
||||
}
|
||||
|
||||
private static File sServerHome;
|
||||
|
||||
public static File getServerHome() {
|
||||
if (sServerHome == null) {
|
||||
String home = System.getenv("KCAULDRON_HOME");
|
||||
if (home != null) {
|
||||
sServerHome = new File(home);
|
||||
} else {
|
||||
parseManifest();
|
||||
sServerHome = sServerLocation.getParentFile();
|
||||
}
|
||||
}
|
||||
return sServerHome;
|
||||
}
|
||||
|
||||
private static String sGroup;
|
||||
|
||||
public static String getGroup() {
|
||||
parseManifest();
|
||||
return sGroup;
|
||||
}
|
||||
|
||||
private static String sBranch;
|
||||
|
||||
public static String getBranch() {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package kcauldron.updater;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -11,10 +12,13 @@ import kcauldron.KCauldron;
|
||||
import kcauldron.updater.KVersionRetriever.IVersionCheckCallback;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.methods.RequestBuilder;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.LaxRedirectStrategy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -113,9 +117,9 @@ public class KCauldronUpdater implements Runnable, IVersionCheckCallback {
|
||||
}
|
||||
File kbootstrap = File.createTempFile("kbootstrap",
|
||||
String.valueOf(System.currentTimeMillis()));
|
||||
download("https://prok.pw/repo/pw/prok/KBootstrap/"
|
||||
+ kbootstrapVersion + "/KBootstrap-" + kbootstrapVersion
|
||||
+ "-app.jar", kbootstrap);
|
||||
download(
|
||||
"https://api.prok.pw/repo/blob/pw.prok/KBootstrap/latest/app",
|
||||
kbootstrap);
|
||||
if (!quite) {
|
||||
mSender.sendMessage(ChatColor.DARK_PURPLE
|
||||
+ "Installing KCauldron " + mVersion
|
||||
@ -130,12 +134,15 @@ public class KCauldronUpdater implements Runnable, IVersionCheckCallback {
|
||||
command.add("-jar");
|
||||
command.add(kbootstrap.getCanonicalPath());
|
||||
command.add("--serverDir");
|
||||
command.add(KCauldron.getServerLocation().getCanonicalPath());
|
||||
command.add(KCauldron.getServerHome().getCanonicalPath());
|
||||
command.add("--installKCauldron");
|
||||
command.add(mVersion);
|
||||
command.add("--serverSymlinks");
|
||||
command.add(MinecraftServer.kcauldronConfig.updatecheckerSymlinks
|
||||
.getValue());
|
||||
command.add(String.format("%s:%s:%s", KCauldron.getGroup(), KCauldron.getChannel(), mVersion));
|
||||
final String[] symlinks = MinecraftServer.kcauldronConfig.updatecheckerSymlinks
|
||||
.getValue().trim().split(File.pathSeparator);
|
||||
for (String symlink : symlinks) {
|
||||
command.add("--serverSymlinks");
|
||||
command.add(symlink);
|
||||
}
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
"Starting command: " + Joiner.on(' ').join(command));
|
||||
@ -180,13 +187,20 @@ public class KCauldronUpdater implements Runnable, IVersionCheckCallback {
|
||||
.addParameter("port",
|
||||
String.valueOf(MinecraftServer.getServer().getPort()))
|
||||
.build();
|
||||
HttpResponse response = HttpClientBuilder.create()
|
||||
.setUserAgent("KCauldron Updater").build().execute(request);
|
||||
CloseableHttpClient client = HttpClientBuilder.create()
|
||||
.setRedirectStrategy(new LaxRedirectStrategy())
|
||||
.setUserAgent("KCauldron Updater").build();
|
||||
|
||||
HttpResponse response = client.execute(request);
|
||||
if (response.getStatusLine().getStatusCode() != 200) {
|
||||
client.close();
|
||||
throw new IllegalStateException("Could not download " + url);
|
||||
}
|
||||
InputStream is = response.getEntity().getContent();
|
||||
Files.copy(is, destination.toPath());
|
||||
OutputStream os = new FileOutputStream(destination);
|
||||
IOUtils.copy(is, os);
|
||||
is.close();
|
||||
os.close();
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.methods.RequestBuilder;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.LaxRedirectStrategy;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
@ -35,7 +36,8 @@ public class KVersionRetriever implements Runnable, UncaughtExceptionHandler {
|
||||
}
|
||||
|
||||
public static void startServer(IVersionCheckCallback callback, boolean loop) {
|
||||
new KVersionRetriever(callback, loop, true, "pw.prok",KCauldron.getChannel());
|
||||
new KVersionRetriever(callback, loop, true, KCauldron.getGroup(),
|
||||
KCauldron.getChannel());
|
||||
}
|
||||
|
||||
private final IVersionCheckCallback mCallback;
|
||||
@ -78,18 +80,26 @@ public class KVersionRetriever implements Runnable, UncaughtExceptionHandler {
|
||||
|
||||
private void check() {
|
||||
try {
|
||||
HttpUriRequest request = RequestBuilder.get()
|
||||
.setUri("https://prok.pw/version/" + mGroup + "/" + mName)
|
||||
HttpUriRequest request = RequestBuilder
|
||||
.get()
|
||||
.setUri("https://api.prok.pw/repo/version/" + mGroup + "/"
|
||||
+ mName)
|
||||
.addParameter("hostname", sServer.getHostname())
|
||||
.addParameter("port", "" + sServer.getPort()).build();
|
||||
HttpResponse response = HttpClientBuilder.create()
|
||||
.setUserAgent("KCauldron Version Retriever").build()
|
||||
.setUserAgent("KCauldron Version Retriever")
|
||||
.setRedirectStrategy(new LaxRedirectStrategy()).build()
|
||||
.execute(request);
|
||||
if (response.getStatusLine().getStatusCode() != 200) {
|
||||
uncaughtException(mThread, new IllegalStateException(
|
||||
"Status code isn't OK"));
|
||||
return;
|
||||
}
|
||||
JSONObject json = (JSONObject) sParser.parse(new InputStreamReader(
|
||||
response.getEntity().getContent()));
|
||||
String version = (String) json.get("version");
|
||||
if (!mUpToDateSupport
|
||||
|| !KCauldron.getCurrentVersion().equals(version)) {
|
||||
if (!mUpToDateSupport || KCauldron.getCurrentVersion() == null
|
||||
|| !version.equals(KCauldron.getCurrentVersion())) {
|
||||
mCallback.newVersion(version);
|
||||
} else {
|
||||
mCallback.upToDate();
|
||||
|
Loading…
Reference in New Issue
Block a user