From 6afcf8d0d7a4922f777660c22cca11c7fa630394 Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Mon, 3 Jul 2017 19:43:36 +0800 Subject: [PATCH] Support liteloader snapshots --- .../install/liteloader/LiteLoaderBranch.java | 35 ++++++++++++++++ .../LiteLoaderInstallerVersion.java | 2 +- .../liteloader/LiteLoaderMCVersions.java | 9 +++- .../install/liteloader/LiteLoaderRepo.java | 35 ++++++++++++++++ .../install/liteloader/LiteLoaderVersion.java | 5 ++- .../liteloader/LiteLoaderVersionList.java | 41 ++++++++++++------- 6 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderBranch.java create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderRepo.java diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderBranch.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderBranch.java new file mode 100644 index 000000000..b896ae349 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderBranch.java @@ -0,0 +1,35 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2013 huangyuhui + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hmcl.core.install.liteloader; + +import com.google.gson.annotations.SerializedName; +import java.util.List; +import java.util.Map; +import org.jackhuang.hmcl.core.version.MinecraftLibrary; + +/** + * + * @author huang + */ +public class LiteLoaderBranch { + @SerializedName("libraries") + public List libraries; + + @SerializedName("com.mumfrey:liteloader") + public Map liteLoader; +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderInstallerVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderInstallerVersion.java index ffd96af8c..c973b5655 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderInstallerVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderInstallerVersion.java @@ -30,7 +30,7 @@ public class LiteLoaderInstallerVersion extends InstallerVersionList.InstallerVe public MinecraftLibrary[] libraries; public String tweakClass; - + public LiteLoaderInstallerVersion(String selfVersion, String mcVersion) { super(selfVersion, mcVersion); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderMCVersions.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderMCVersions.java index 7926c0ca4..a4bdd90ca 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderMCVersions.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderMCVersions.java @@ -18,14 +18,19 @@ package org.jackhuang.hmcl.core.install.liteloader; import com.google.gson.annotations.SerializedName; -import java.util.Map; /** * * @author huangyuhui */ public class LiteLoaderMCVersions { + + @SerializedName("repo") + public LiteLoaderRepo repo; @SerializedName("artefacts") - public Map> artefacts; + public LiteLoaderBranch artefacts; + + @SerializedName("snapshots") + public LiteLoaderBranch snapshots; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderRepo.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderRepo.java new file mode 100644 index 000000000..a8d94d7e2 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderRepo.java @@ -0,0 +1,35 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2013 huangyuhui + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hmcl.core.install.liteloader; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author huang + */ +public class LiteLoaderRepo { + @SerializedName("stream") + public String stream; + @SerializedName("type") + public String type; + @SerializedName("url") + public String url; + @SerializedName("classifier") + public String classifier; +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersion.java index 7cbc66dea..4925e52f9 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersion.java @@ -18,6 +18,7 @@ package org.jackhuang.hmcl.core.install.liteloader; import com.google.gson.annotations.SerializedName; +import java.util.List; import org.jackhuang.hmcl.core.version.MinecraftLibrary; /** @@ -36,6 +37,8 @@ public class LiteLoaderVersion { public String md5; @SerializedName("timestamp") public String timestamp; + @SerializedName("lastSuccessfulBuild") + public int lastSuccessfulBuild; @SerializedName("libraries") - public MinecraftLibrary[] libraries; + public List libraries; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersionList.java index 00656f7cd..46ed08b23 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/core/install/liteloader/LiteLoaderVersionList.java @@ -22,11 +22,14 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map; import org.jackhuang.hmcl.core.download.DownloadType; import org.jackhuang.hmcl.util.C; import org.jackhuang.hmcl.core.install.InstallerVersionList; import org.jackhuang.hmcl.core.install.InstallerVersionNewerComparator; +import org.jackhuang.hmcl.core.version.MinecraftLibrary; import org.jackhuang.hmcl.util.StrUtils; import org.jackhuang.hmcl.util.task.Task; import org.jackhuang.hmcl.util.task.TaskInfo; @@ -60,6 +63,27 @@ public class LiteLoaderVersionList extends InstallerVersionList { return Arrays.asList(task.setTag("Official Liteloader Download Site")); } + private void doBranch(String version, LiteLoaderRepo repo, LiteLoaderBranch branch, List result, boolean snapshot) { + if (branch == null || branch.liteLoader == null) + return; + for (Map.Entry entry : branch.liteLoader.entrySet()) { + if ("latest".equals(entry.getKey())) + continue; + LiteLoaderVersion v = entry.getValue(); + LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version.replace("SNAPSHOT", "SNAPSHOT-" + v.lastSuccessfulBuild), StrUtils.formatVersion(version)); + if (snapshot) + iv.universal = String.format("http://jenkins.liteloader.com/view/%s/job/LiteLoader %s/lastSuccessfulBuild/artifact/build/libs/liteloader-%s-release.jar", version, version, v.version); + else + iv.universal = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(repo.url + "com/mumfrey/liteloader/" + version + "/" + v.file); + iv.tweakClass = v.tweakClass; + HashSet set = new HashSet<>(); + if (v.libraries != null) + set.addAll(v.libraries); + iv.libraries = set.toArray(new MinecraftLibrary[set.size()]); + result.add(iv); + } + } + @Override public void executeTask(boolean areDependTasksSucceeded) throws Exception { if (!areDependTasksSucceeded) @@ -74,21 +98,10 @@ public class LiteLoaderVersionList extends InstallerVersionList { for (Map.Entry arr : root.versions.entrySet()) { ArrayList al = new ArrayList<>(); LiteLoaderMCVersions mcv = arr.getValue(); - if (mcv == null || mcv.artefacts == null || mcv.artefacts.get("com.mumfrey:liteloader") == null) - continue; - for (Map.Entry entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) { - if ("latest".equals(entry.getKey())) - continue; - LiteLoaderVersion v = entry.getValue(); - LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey())); - iv.universal = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL("http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file); - iv.tweakClass = v.tweakClass; - iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length); - iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar"; - al.add(iv); - versions.add(iv); - } + doBranch(arr.getKey(), mcv.repo, mcv.artefacts, al, false); + doBranch(arr.getKey(), mcv.repo, mcv.snapshots, al, true); Collections.sort(al, new InstallerVersionNewerComparator()); + versions.addAll(al); versionMap.put(StrUtils.formatVersion(arr.getKey()), al); }