Attempt to enable JVM forward compatibility

This commit is contained in:
Johannes Frohnmeyer 2021-12-11 13:53:46 +01:00
parent 95c6990b5e
commit 4f546014d1
Signed by: Johannes
GPG Key ID: E76429612C2929F4
15 changed files with 117 additions and 34 deletions

View File

@ -26,6 +26,7 @@ build_test:
- cp wrapper/build/libs/*-all.jar wrapper.jar
- for f in *-*-*.jar; do mv "$f" "latest-${f##*-}";done
- mv latest-fat.jar latest.jar
- unzip -p latest.jar version.json > version.json
artifacts:
paths:
- build/libs
@ -35,6 +36,7 @@ build_test:
- latest-linux.jar
- latest-macos.jar
- latest-windows.jar
- version.json
expire_in: 2 days
only:
- master
@ -52,7 +54,7 @@ portable:
- dir="portable/run/libraries/io/gitlab/jfronny/inceptum/Inceptum/${dir%%-windows*}"
- mkdir -p "$dir"
- mv "$main" "$dir/${main##*/}"
- curl -L "$(curl https://api.github.com/repos/pal1000/mesa-dist-win/releases/latest | jq -r ".assets[] | select(.name | test(\"release-msvc.7z\")) | .browser_download_url")" --output mesa.7z
- curl -L "$(curl https://api.github.com/repos/pal1000/mesa-dist-win/releases | jq -r "[.[] | .assets[] | select(.name | test(\"release-msvc.7z\")) | .browser_download_url][0]")" --output mesa.7z
- 7z e mesa.7z -oportable/run/natives/forceload x64/dxil.dll x64/libglapi.dll x64/opengl32.dll
- curl -L "https://api.adoptium.net/v3/binary/latest/17/ga/windows/x64/jdk/hotspot/normal/eclipse?project=jdk" --output jvm.zip
- 7z x jvm.zip -oportable/

View File

@ -75,6 +75,7 @@ processResources {
expand "version": project.version
filter { line -> line.replace("@flavor@", project.ext.flavorProp) }
filter { line -> line.replace("@public@", "$project.ext.isPublic") }
filter { line -> line.replace("@jvm@", "$project.sourceCompatibility") }
}
}

View File

@ -1,5 +1,6 @@
{
"version": "${version}",
"flavor": "@flavor@",
"isPublic": @public@
"isPublic": @public@,
"jvm": @jvm@
}

View File

@ -15,7 +15,7 @@ repositories {
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.google.code.gson:gson:2.8.9'
}
processResources {
@ -25,6 +25,7 @@ processResources {
expand "version": project.version
filter { line -> line.replace("@flavor@", rootProject.ext.flavorProp) }
filter { line -> line.replace("@public@", "$rootProject.ext.isPublic") }
filter { line -> line.replace("@jvm@", "$rootProject.sourceCompatibility") }
}
}
@ -32,7 +33,7 @@ class FileOutput extends DefaultTask {
@OutputFile
File output
}
def bootstrapVersion = "0.1.6"
def bootstrapVersion = "0.2.1"
def bootstrapArch = "i686"
task downloadBootstrap(type: Download) {

View File

@ -0,0 +1,8 @@
package io.gitlab.jfronny.inceptum.model.gitlab;
public class GitlabArtifact {
public String file_type;
public Long size;
public String filename;
public String file_format;
}

View File

@ -0,0 +1,20 @@
package io.gitlab.jfronny.inceptum.model.gitlab;
import java.util.Date;
import java.util.List;
public class GitlabCommit {
public String id;
public String short_id;
public Date created_at;
public List<String> parent_ids;
public String title;
public String message;
public String author_name;
public String author_email;
public Date authored_date;
public String committer_name;
public String committer_email;
public Date committed_date;
public String web_url;
}

View File

@ -0,0 +1,26 @@
package io.gitlab.jfronny.inceptum.model.gitlab;
import java.util.Date;
import java.util.List;
public class GitlabJob {
public Long id;
public String status;
public String stage;
public String name;
public String ref;
public Boolean tag;
public Boolean allow_failure;
public Date created_at;
public Date started_at;
public Date finished_at;
public Double duration;
public Double queued_duration;
public GitlabUser user;
public GitlabCommit commit;
public GitlabPipeline pipeline;
public String web_url;
public List<GitlabArtifact> artifacts;
public GitlabRunner runner;
public Date artifacts_expire_at;
}

View File

@ -3,12 +3,12 @@ package io.gitlab.jfronny.inceptum.model.gitlab;
import java.util.Date;
import java.util.List;
public class PackageInfo {
public class GitlabPackage {
public Long id;
public String name;
public String version;
public String package_type;
public String status;
public Date created_at;
public List<Pipeline> pipelines;
public List<GitlabPipeline> pipelines;
}

View File

@ -3,7 +3,7 @@ package io.gitlab.jfronny.inceptum.model.gitlab;
import java.util.Date;
import java.util.List;
public class PackageFileInfo {
public class GitlabPackageFile {
public Long id;
public Long package_id;
public Date created_at;
@ -12,5 +12,5 @@ public class PackageFileInfo {
public String file_md5;
public String file_sha1;
public String file_sha256;
public List<Pipeline> pipelines;
public List<GitlabPipeline> pipelines;
}

View File

@ -2,7 +2,7 @@ package io.gitlab.jfronny.inceptum.model.gitlab;
import java.util.Date;
public class Pipeline {
public class GitlabPipeline {
public long id;
public long project_id;
public String sha;

View File

@ -0,0 +1,13 @@
package io.gitlab.jfronny.inceptum.model.gitlab;
public class GitlabRunner {
public Long id;
public String description;
public String ip_address;
public Boolean active;
public Boolean is_shared;
public String runner_type;
public String name;
public Boolean online;
public String deprecated_rest_status;
}

View File

@ -6,4 +6,5 @@ public class InceptumVersion {
public ComparableVersion version;
public String flavor;
public Boolean isPublic;
public Integer jvm;
}

View File

@ -1,10 +1,8 @@
package io.gitlab.jfronny.inceptum.util;
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
import io.gitlab.jfronny.inceptum.model.gitlab.GitlabProject;
import io.gitlab.jfronny.inceptum.model.gitlab.PackageFileInfo;
import io.gitlab.jfronny.inceptum.model.gitlab.PackageInfo;
import io.gitlab.jfronny.inceptum.model.gitlab.Pipeline;
import io.gitlab.jfronny.inceptum.model.gitlab.*;
import io.gitlab.jfronny.inceptum.model.inceptum.InceptumVersion;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateChannel;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo;
import io.gitlab.jfronny.inceptum.util.api.GitlabApi;
@ -18,18 +16,27 @@ public class UpdateChecker {
public static UpdateInfo check(UpdateChannel channel, ComparableVersion current, String flavor, Consumer<UpdateChannel> channelInvalid, Consumer<String> out, Consumer<String> error, BiConsumer<String, Exception> showError) {
try {
int jvm = Runtime.version().feature();
if (flavor.equals("custom")) {
out.accept("Custom build, skipping update check");
return null;
}
GitlabProject project = GitlabApi.getProject(PROJECT_ID);
PackageInfo experimental = null;
GitlabPackage experimental = null;
ComparableVersion experimentalVersion = null;
PackageInfo stable = null;
GitlabPackage stable = null;
ComparableVersion stableVersion = null;
for (PackageInfo info : GitlabApi.getPackages(project)) {
packageLoop: for (GitlabPackage info : GitlabApi.getPackages(project)) {
if (info.status.equals("default")) {
for (Pipeline pipeline : info.pipelines) {
for (GitlabPipeline pipeline : info.pipelines) {
for (GitlabJob job : GitlabApi.getJobs(project, pipeline.id)) {
if (!job.name.equals("build_test")) continue;
InceptumVersion iv = GitlabApi.downloadObject("projects/" + project.id + "/jobs/" + job.id + "/artifacts/version.json", InceptumVersion.class);
if (iv.jvm > jvm) {
error.accept("A newer JVM is required to use the latest inceptum version. Please update!");
continue packageLoop;
}
}
if (pipeline.ref.equals("master") && pipeline.status.equals("success")) {
ComparableVersion cvNew = new ComparableVersion(info.version);
if (experimentalVersion == null || experimentalVersion.compareTo(cvNew) < 0) {
@ -51,7 +58,7 @@ public class UpdateChecker {
channel = UpdateChannel.CI;
channelInvalid.accept(channel);
}
PackageInfo info = switch (channel) {
GitlabPackage info = switch (channel) {
case CI -> experimental;
case Stable -> stable;
};
@ -60,7 +67,7 @@ public class UpdateChecker {
out.accept("Up-to-date");
return null;
}
PackageFileInfo file = GitlabApi.getFile(project, info, f -> f.file_name.endsWith('-' + flavor + ".jar"));
GitlabPackageFile file = GitlabApi.getFile(project, info, f -> f.file_name.endsWith('-' + flavor + ".jar"));
if (file == null)
error.accept("No valid package was discovered");
else return new UpdateInfo("https://gitlab.com/" + project.path_with_namespace + "/-/package_files/" + file.id + "/download", file.file_sha1, new ComparableVersion(info.version));

View File

@ -2,9 +2,7 @@ package io.gitlab.jfronny.inceptum.util.api;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.gitlab.jfronny.inceptum.model.gitlab.GitlabProject;
import io.gitlab.jfronny.inceptum.model.gitlab.PackageFileInfo;
import io.gitlab.jfronny.inceptum.model.gitlab.PackageInfo;
import io.gitlab.jfronny.inceptum.model.gitlab.*;
import java.io.IOException;
import java.io.InputStream;
@ -16,32 +14,36 @@ import java.util.function.Predicate;
public class GitlabApi {
private static final Gson GSON = new Gson();
private static final Type packageInfoListType = new TypeToken<List<PackageInfo>>() {}.getType();
private static final Type packageFileInfoListType = new TypeToken<List<PackageFileInfo>>() {}.getType();
private static final Type gitlabProjectType = new TypeToken<GitlabProject>() {}.getType();
private static final Type packageInfoListType = new TypeToken<List<GitlabPackage>>() {}.getType();
private static final Type jobListType = new TypeToken<List<GitlabJob>>() {}.getType();
private static final Type packageFileInfoListType = new TypeToken<List<GitlabPackageFile>>() {}.getType();
public static GitlabProject getProject(Long projectId) throws IOException {
return downloadObject("https://gitlab.com/api/v4/projects/" + projectId, gitlabProjectType);
return downloadObject("projects/" + projectId, GitlabProject.class);
}
public static List<PackageInfo> getPackages(GitlabProject project) throws IOException {
return downloadObject("https://gitlab.com/api/v4/projects/" + project.id + "/packages", packageInfoListType);
public static List<GitlabPackage> getPackages(GitlabProject project) throws IOException {
return downloadObject("projects/" + project.id + "/packages", packageInfoListType);
}
public static PackageFileInfo getFile(GitlabProject project, PackageInfo packageInfo, Predicate<PackageFileInfo> isValid) throws IOException {
public static List<GitlabJob> getJobs(GitlabProject project, Long pipelineId) throws IOException {
return downloadObject("projects/" + project.id + "/pipelines/" + pipelineId + "/jobs", jobListType);
}
public static GitlabPackageFile getFile(GitlabProject project, GitlabPackage packageInfo, Predicate<GitlabPackageFile> isValid) throws IOException {
int page = 0;
while (true) {
List<PackageFileInfo> files = downloadObject("https://gitlab.com/api/v4/projects/" + project.id + "/packages/" + packageInfo.id + "/package_files?per_page=100&page=" + ++page, packageFileInfoListType);
List<GitlabPackageFile> files = downloadObject("projects/" + project.id + "/packages/" + packageInfo.id + "/package_files?per_page=100&page=" + ++page, packageFileInfoListType);
if (files.isEmpty()) return null;
for (PackageFileInfo file : files) {
for (GitlabPackageFile file : files) {
if (isValid.test(file))
return file;
}
}
}
private static <T> T downloadObject(String source, Type type) throws IOException {
try (InputStream is = new URL(source).openStream(); InputStreamReader isr = new InputStreamReader(is)) {
public static <T> T downloadObject(String source, Type type) throws IOException {
try (InputStream is = new URL("https://gitlab.com/api/v4/" + source).openStream(); InputStreamReader isr = new InputStreamReader(is)) {
return GSON.fromJson(isr, type);
}
}

View File

@ -1,5 +1,6 @@
{
"version": "${version}",
"flavor": "@flavor@",
"isPublic": @public@
"isPublic": @public@,
"jvm": @jvm@
}