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