重构 Java 管理 (#2988)

* update

* update

* Update task name

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* Update logo
This commit is contained in:
Glavo
2024-10-05 23:50:14 +08:00
committed by GitHub
parent 37d6857b82
commit 7e4d437a1d
74 changed files with 5232 additions and 1343 deletions

View File

@@ -1,37 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
*
* 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 <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.game;
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
import org.jackhuang.hmcl.util.versioning.VersionNumber;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class JavaVersionConstraintTest {
@Test
public void vanillaJava16() {
JavaVersionConstraint.VersionRanges range = JavaVersionConstraint.findSuitableJavaVersionRange(
GameVersionNumber.asGameVersion("1.17"),
null
);
assertEquals(VersionNumber.atLeast("16"), range.getMandatory());
}
}

View File

@@ -0,0 +1,31 @@
package org.jackhuang.hmcl.util;
import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import static org.jackhuang.hmcl.util.Pair.pair;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Glavo
*/
public final class KeyValuePairPropertiesTest {
@Test
public void test() throws IOException {
String content = "#test: key0=value0\n \n" +
"key1=value1\n" +
"key2=\"value2\"\n" +
"key3=\"\\\" \\n\"\n";
KeyValuePairProperties properties = KeyValuePairProperties.load(new BufferedReader(new StringReader(content)));
assertEquals(Lang.mapOf(
pair("key1", "value1"),
pair("key2", "value2"),
pair("key3", "\" \n")
), properties);
}
}

View File

@@ -20,7 +20,6 @@ package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.util.platform.JavaVersion;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
@@ -79,10 +78,11 @@ public class TaskTest {
@EnabledIf("org.jackhuang.hmcl.JavaFXLauncher#isStarted")
public void testThenAccept() {
AtomicBoolean flag = new AtomicBoolean();
boolean result = Task.supplyAsync(JavaVersion::fromCurrentEnvironment)
.thenAcceptAsync(Schedulers.io(), javaVersion -> {
Object obj = new Object();
boolean result = Task.supplyAsync(() -> obj)
.thenAcceptAsync(Schedulers.io(), o -> {
flag.set(true);
assertEquals(javaVersion, JavaVersion.fromCurrentEnvironment());
assertSame(obj, o);
})
.test();

View File

@@ -0,0 +1,18 @@
package org.jackhuang.hmcl.util.platform;
import org.junit.jupiter.api.Test;
import static org.jackhuang.hmcl.java.JavaInfo.parseVersion;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author Glavo
*/
public final class JavaRuntimeTest {
@Test
public void testParseVersion() {
assertEquals(8, parseVersion("1.8.0_302"));
assertEquals(11, parseVersion("11"));
assertEquals(11, parseVersion("11.0.12"));
}
}