mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-20 00:39:37 +00:00
Add: detail.json with detailed downloading information
This commit is contained in:
1 parent
187be47e88
commit
e1e5319bdb
7 files changed
+112
-18
No files matched your search
+1
-1
@@ -95,7 +95,7 @@ subprojects {
|
||||
|
||||
// For real subprojects
|
||||
if (!config.is_real_project || Boolean.parseBoolean(config.is_real_project.toString())) {
|
||||
archivesBaseName = "CustomSkinLoader_${-> project.name.contains("Vanilla") ? config.minecraft_version : project.name.replace('/', '') }"
|
||||
archivesBaseName = "CustomSkinLoader_${-> VersionUtil.getEdition(project)}"
|
||||
|
||||
apply from: rootProject.file("BuildScripts/sources.gradle")
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package customskinloader.gradle.entity;
|
||||
|
||||
import org.gradle.util.VersionNumber;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CslDetail {
|
||||
public String version;
|
||||
public long timestamp;
|
||||
|
||||
Map<String, Map<String, String>> details = new LinkedHashMap<>();
|
||||
|
||||
public CslDetail(String version) {
|
||||
this.version = version;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void addDetail(String mcMajorVersion, String edition, String url) {
|
||||
String e = edition
|
||||
.replace("ForgeLegacy", "Forge")
|
||||
.replace("ForgeActive", "Forge");
|
||||
details.computeIfAbsent(mcMajorVersion, (key) -> new LinkedHashMap<>())
|
||||
.put(e, url);
|
||||
}
|
||||
|
||||
public void sortDetails() {
|
||||
details = details.entrySet().stream()
|
||||
.sorted(Comparator.comparing(a -> VersionNumber.parse(a.getKey())))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (x, y) -> y, LinkedHashMap::new));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package customskinloader.gradle.entity;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CslLatest {
|
||||
public String version;
|
||||
public Map<String, String> downloads = new LinkedHashMap<>();
|
||||
public Map<String, String> launchermeta = new LinkedHashMap<>();
|
||||
|
||||
public CslLatest(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getUrl(String edition) {
|
||||
String e = edition.replace("ForgeLegacy", "Forge");
|
||||
return Optional.ofNullable(downloads.get(e))
|
||||
.orElseGet(() -> launchermeta.get(e));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@ package customskinloader.gradle.task;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import customskinloader.gradle.entity.CslDetail;
|
||||
import customskinloader.gradle.entity.CslLatest;
|
||||
import customskinloader.gradle.util.ConfigUtil;
|
||||
import customskinloader.gradle.util.CosUtil;
|
||||
import customskinloader.gradle.util.VersionUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -12,6 +15,7 @@ import org.gradle.api.tasks.TaskAction;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class UploadTask extends DefaultTask {
|
||||
@@ -19,24 +23,19 @@ public class UploadTask extends DefaultTask {
|
||||
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private void uploadArtifacts() throws IOException {
|
||||
private CslLatest uploadArtifacts() throws IOException {
|
||||
String shortVersion = VersionUtil.getShortVersion(rootProject);
|
||||
File dir = rootProject.file("build/libs");
|
||||
if (!dir.isDirectory()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
String cslversion = shortVersion.replace(".", "");
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, String> map2 = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, String> map3 = new LinkedHashMap<>();
|
||||
map.put("version", shortVersion);
|
||||
map.put("downloads", map2);
|
||||
map.put("launchermeta", map3);
|
||||
CslLatest latest = new CslLatest(shortVersion);
|
||||
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
for (File file : files) {
|
||||
String key = CosUtil.getKey(file.getName());
|
||||
@@ -53,21 +52,40 @@ public class UploadTask extends DefaultTask {
|
||||
mcversion.replace(".", "").toLowerCase(), cslversion, url);
|
||||
|
||||
if (key.startsWith("mods/") && key.endsWith(".jar") && !key.endsWith("-sources.jar")) {
|
||||
map2.put(mcversion, url);
|
||||
latest.downloads.put(mcversion, url);
|
||||
} else if (key.endsWith(".json")) {
|
||||
map3.put(mcversion, url);
|
||||
latest.launchermeta.put(mcversion, url);
|
||||
}
|
||||
}
|
||||
|
||||
File latest = new File("build/libs/latest.json");
|
||||
FileUtils.write(latest, gson.toJson(map), StandardCharsets.UTF_8);
|
||||
CosUtil.uploadFile("latest.json", latest);
|
||||
CosUtil.writeAndUploadObject("latest.json", latest);
|
||||
return latest;
|
||||
}
|
||||
|
||||
public void uploadDetail(CslLatest latest) throws IOException {
|
||||
CslDetail detail = new CslDetail(latest.version);
|
||||
|
||||
rootProject.getAllprojects().stream()
|
||||
.filter(it -> !"false".equals(ConfigUtil.getConfigString(it, "is_real_project")))
|
||||
.forEach(project -> {
|
||||
String edition = VersionUtil.getEdition(project);
|
||||
String url = latest.getUrl(edition);
|
||||
VersionUtil.getMcMajorVersions(
|
||||
ConfigUtil.getConfigString(project, "minecraft_full_versions"))
|
||||
.forEach(mcMajorVersion -> detail.addDetail(mcMajorVersion, edition, url));
|
||||
});
|
||||
|
||||
detail.sortDetails();
|
||||
CosUtil.writeAndUploadObject("detail.json", detail);
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void upload() throws IOException {
|
||||
if (System.getenv("COS_SECRET_KEY") != null) {
|
||||
uploadArtifacts();
|
||||
CslLatest latest = uploadArtifacts();
|
||||
if (latest != null) {
|
||||
uploadDetail(latest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package customskinloader.gradle.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
@@ -7,8 +9,11 @@ import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.model.GetObjectRequest;
|
||||
import com.qcloud.cos.model.PutObjectRequest;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class CosUtil {
|
||||
public static String getKey(String filename) {
|
||||
@@ -39,9 +44,11 @@ public class CosUtil {
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
private static final String bucketName = System.getenv("COS_BUCKET");
|
||||
public static final String cosUrl = "https://csl.littleservice.cn/";
|
||||
private static COSClient cosClient0 = null;
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private static COSClient getCosClient() {
|
||||
if (cosClient0 != null) {
|
||||
@@ -61,6 +68,12 @@ public class CosUtil {
|
||||
getCosClient().putObject(putObjectRequest);
|
||||
}
|
||||
|
||||
public static void writeAndUploadObject(String filename, Object obj) throws IOException {
|
||||
File file = new File("build/libs/" + filename);
|
||||
FileUtils.write(file, gson.toJson(obj), StandardCharsets.UTF_8);
|
||||
CosUtil.uploadFile(filename, file);
|
||||
}
|
||||
|
||||
public static void downloadFile(String key, File file) {
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
|
||||
getCosClient().getObject(getObjectRequest, file);
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.gradle.util.VersionNumber;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class VersionUtil {
|
||||
@@ -45,9 +46,18 @@ public class VersionUtil {
|
||||
}
|
||||
|
||||
public static Collection<String> getMcMajorVersions(String version) {
|
||||
if (version == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.stream(version.split(","))
|
||||
.map(VersionNumber::parse)
|
||||
.map(it -> String.format("%s.%s", it.getMajor(), it.getMinor()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static String getEdition(Project project) {
|
||||
return project.getName().contains("Vanilla") ?
|
||||
ConfigUtil.getConfigString(project, "minecraft_version") :
|
||||
project.getName().replace("/", "");
|
||||
}
|
||||
}
|
||||
@@ -21,5 +21,3 @@ include "Forge/Active"
|
||||
|
||||
//Fabric Edition for [1.14,)
|
||||
include "Fabric"
|
||||
include 'buildSrc'
|
||||
|
||||
Reference in new issue
Block a user