feat(java): download java 8/16 when auto selected java not found.

This commit is contained in:
huanghongxun
2021-10-18 23:38:57 +08:00
parent 71c23df971
commit a4f22671c6
11 changed files with 114 additions and 78 deletions

View File

@@ -101,7 +101,7 @@ public class JavaDownloadTask extends Task<Void> {
try (LZMAInputStream input = new LZMAInputStream(new FileInputStream(tempFile))) {
Files.copy(input, dest);
} catch (IOException e) {
throw new ArtifactMalformedException("File " + entry.getKey() + " is malformed");
throw new ArtifactMalformedException("File " + entry.getKey() + " is malformed", e);
}
}));
} else if (file.getDownloads().containsKey("raw")) {

View File

@@ -21,23 +21,25 @@ public final class JavaRepository {
private JavaRepository() {
}
public static Task<?> downloadJava(GameJavaVersion javaVersion, DownloadProvider downloadProvider) {
public static Task<JavaVersion> downloadJava(GameJavaVersion javaVersion, DownloadProvider downloadProvider) {
return new JavaDownloadTask(javaVersion, getJavaStoragePath(), downloadProvider)
.thenRunAsync(() -> {
Optional<String> platform = getSystemJavaPlatform();
if (platform.isPresent()) {
addJava(getJavaHome(javaVersion, platform.get()));
}
.thenSupplyAsync(() -> {
String platform = getSystemJavaPlatform().orElseThrow(JavaDownloadTask.UnsupportedPlatformException::new);
return addJava(getJavaHome(javaVersion, platform));
});
}
public static void addJava(Path javaHome) throws InterruptedException, IOException {
public static JavaVersion addJava(Path javaHome) throws InterruptedException, IOException {
if (Files.isDirectory(javaHome)) {
Path executable = JavaVersion.getExecutable(javaHome);
if (Files.isRegularFile(executable)) {
JavaVersion.getJavas().add(JavaVersion.fromExecutable(executable));
JavaVersion javaVersion = JavaVersion.fromExecutable(executable);
JavaVersion.getJavas().add(javaVersion);
return javaVersion;
}
}
throw new IOException("Incorrect java home " + javaHome);
}
public static void initialize() throws IOException, InterruptedException {

View File

@@ -37,4 +37,7 @@ public class GameJavaVersion {
public int getMajorVersion() {
return majorVersion;
}
public static final GameJavaVersion JAVA_16 = new GameJavaVersion("java-runtime-alpha", 16);
public static final GameJavaVersion JAVA_8 = new GameJavaVersion("jre-legacy", 8);
}

View File

@@ -17,9 +17,9 @@
*/
package org.jackhuang.hmcl.util.io;
import java.io.IOException;
import org.jackhuang.hmcl.download.ArtifactMalformedException;
public class ChecksumMismatchException extends IOException {
public class ChecksumMismatchException extends ArtifactMalformedException {
private final String algorithm;
private final String expectedChecksum;

View File

@@ -25,6 +25,8 @@ import java.util.*;
/**
* Copied from org.apache.maven.artifact.versioning.ComparableVersion
* Apache License 2.0
*
* Maybe we can migrate to org.jenkins-ci:version-number:1.7?
* @see <a href="http://maven.apache.org/pom.html#Version_Order_Specification">Specification</a>
*/
public class VersionNumber implements Comparable<VersionNumber> {