name task async
This commit is contained in:
@@ -46,7 +46,7 @@ public final class Main {
|
||||
checkDirectoryPath();
|
||||
|
||||
// This environment check will take ~300ms
|
||||
thread(() -> checkDSTRootCAX3(), "CA Certificate Check", true);
|
||||
thread(Main::checkDSTRootCAX3, "CA Certificate Check", true);
|
||||
|
||||
Logging.start(Metadata.HMCL_DIRECTORY.resolve("logs"));
|
||||
|
||||
|
||||
@@ -123,14 +123,14 @@ public final class LauncherHelper {
|
||||
Optional<String> gameVersion = GameVersion.minecraftVersion(repository.getVersionJar(version));
|
||||
|
||||
TaskExecutor executor = Task.runAsync(Schedulers.javafx(), () -> emitStatus(LoadingState.DEPENDENCIES))
|
||||
.thenCompose(() -> {
|
||||
.thenComposeAsync(() -> {
|
||||
if (setting.isNotCheckGame())
|
||||
return null;
|
||||
else
|
||||
return dependencyManager.checkGameCompletionAsync(version);
|
||||
})
|
||||
.thenRun(Schedulers.javafx(), () -> emitStatus(LoadingState.MODS))
|
||||
.thenCompose(() -> {
|
||||
.thenRunAsync(Schedulers.javafx(), () -> emitStatus(LoadingState.MODS))
|
||||
.thenComposeAsync(() -> {
|
||||
try {
|
||||
ModpackConfiguration<?> configuration = ModpackHelper.readModpackConfiguration(repository.getModpackConfiguration(selectedVersion));
|
||||
if ("Curse".equals(configuration.getType()))
|
||||
@@ -141,8 +141,8 @@ public final class LauncherHelper {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.thenRun(Schedulers.javafx(), () -> emitStatus(LoadingState.LOGGING_IN))
|
||||
.thenSupply(i18n("account.methods"), () -> {
|
||||
.thenRunAsync(Schedulers.javafx(), () -> emitStatus(LoadingState.LOGGING_IN))
|
||||
.thenSupplyAsync(i18n("account.methods"), () -> {
|
||||
try {
|
||||
return account.logIn();
|
||||
} catch (CredentialExpiredException e) {
|
||||
@@ -153,11 +153,11 @@ public final class LauncherHelper {
|
||||
return account.playOffline().orElseThrow(() -> e);
|
||||
}
|
||||
})
|
||||
.thenApply(Schedulers.javafx(), authInfo -> {
|
||||
.thenApplyAsync(Schedulers.javafx(), authInfo -> {
|
||||
emitStatus(LoadingState.LAUNCHING);
|
||||
return authInfo;
|
||||
})
|
||||
.thenApply(authInfo -> new HMCLGameLauncher(
|
||||
.thenApplyAsync(authInfo -> new HMCLGameLauncher(
|
||||
repository,
|
||||
selectedVersion,
|
||||
authInfo,
|
||||
@@ -166,7 +166,7 @@ public final class LauncherHelper {
|
||||
? null // Unnecessary to start listening to game process output when close launcher immediately after game launched.
|
||||
: new HMCLProcessListener(authInfo, gameVersion.isPresent())
|
||||
))
|
||||
.thenCompose(launcher -> { // launcher is prev task's result
|
||||
.thenComposeAsync(launcher -> { // launcher is prev task's result
|
||||
if (scriptFile == null) {
|
||||
return new LaunchTask<>(launcher::launch).setName(i18n("version.launch"));
|
||||
} else {
|
||||
@@ -176,7 +176,7 @@ public final class LauncherHelper {
|
||||
}).setName(i18n("version.launch_script"));
|
||||
}
|
||||
})
|
||||
.thenAccept(process -> { // process is LaunchTask's result
|
||||
.thenAcceptAsync(process -> { // process is LaunchTask's result
|
||||
if (scriptFile == null) {
|
||||
PROCESSES.add(process);
|
||||
if (launcherVisibility == LauncherVisibility.CLOSE)
|
||||
|
||||
@@ -117,7 +117,7 @@ public final class ModpackHelper {
|
||||
else if (modpack.getManifest() instanceof MultiMCInstanceConfiguration)
|
||||
return new MultiMCModpackInstallTask(profile.getDependency(), zipFile, modpack, ((MultiMCInstanceConfiguration) modpack.getManifest()), name)
|
||||
.whenComplete(Schedulers.defaultScheduler(), success, failure)
|
||||
.thenCompose(new MultiMCInstallVersionSettingTask(profile, ((MultiMCInstanceConfiguration) modpack.getManifest()), name));
|
||||
.thenComposeAsync(new MultiMCInstallVersionSettingTask(profile, ((MultiMCInstanceConfiguration) modpack.getManifest()), name));
|
||||
else throw new IllegalStateException("Unrecognized modpack: " + modpack);
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ public final class Profile implements Observable {
|
||||
|
||||
@Override
|
||||
public Profile deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json == null || json == JsonNull.INSTANCE || !(json instanceof JsonObject)) return null;
|
||||
if (json == JsonNull.INSTANCE || !(json instanceof JsonObject)) return null;
|
||||
JsonObject obj = (JsonObject) json;
|
||||
String gameDir = Optional.ofNullable(obj.get("gameDir")).map(JsonElement::getAsString).orElse("");
|
||||
|
||||
|
||||
@@ -595,7 +595,7 @@ public final class VersionSetting {
|
||||
|
||||
@Override
|
||||
public VersionSetting deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json == null || json == JsonNull.INSTANCE || !(json instanceof JsonObject))
|
||||
if (json == JsonNull.INSTANCE || !(json instanceof JsonObject))
|
||||
return null;
|
||||
JsonObject obj = (JsonObject) json;
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.jackhuang.hmcl.ui;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.layout.Region;
|
||||
import org.jackhuang.hmcl.event.EventBus;
|
||||
import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
|
||||
import org.jackhuang.hmcl.game.HMCLGameRepository;
|
||||
@@ -28,7 +27,6 @@ import org.jackhuang.hmcl.setting.Profile;
|
||||
import org.jackhuang.hmcl.setting.Profiles;
|
||||
import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.task.TaskExecutor;
|
||||
import org.jackhuang.hmcl.ui.account.AccountAdvancedListItem;
|
||||
import org.jackhuang.hmcl.ui.account.AddAccountPane;
|
||||
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
||||
@@ -39,7 +37,6 @@ import org.jackhuang.hmcl.ui.versions.Versions;
|
||||
import org.jackhuang.hmcl.util.io.CompressingUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
|
||||
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
|
||||
@@ -119,10 +116,10 @@ public final class LeftPaneController extends AdvancedListBox {
|
||||
File modpackFile = new File("modpack.zip").getAbsoluteFile();
|
||||
if (modpackFile.exists()) {
|
||||
Task.supplyAsync(() -> CompressingUtils.findSuitableEncoding(modpackFile.toPath()))
|
||||
.thenApply(encoding -> ModpackHelper.readModpackManifest(modpackFile.toPath(), encoding))
|
||||
.thenApply(modpack -> ModpackHelper.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack)
|
||||
.withRun(Schedulers.javafx(), this::checkAccount).executor())
|
||||
.thenAccept(Schedulers.javafx(), executor -> {
|
||||
.thenApplyAsync(encoding -> ModpackHelper.readModpackManifest(modpackFile.toPath(), encoding))
|
||||
.thenApplyAsync(modpack -> ModpackHelper.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack)
|
||||
.withRunAsync(Schedulers.javafx(), this::checkAccount).executor())
|
||||
.thenAcceptAsync(Schedulers.javafx(), executor -> {
|
||||
Controllers.taskDialog(executor, i18n("modpack.installing"));
|
||||
executor.start();
|
||||
}).start();
|
||||
|
||||
@@ -50,7 +50,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
@@ -118,7 +117,7 @@ public final class SettingsPage extends SettingsView implements DecoratorPage {
|
||||
selectedItemPropertyFor(proxyConfigurationGroup, Proxy.Type.class).bindBidirectional(config().proxyTypeProperty());
|
||||
// ====
|
||||
|
||||
fileCommonLocation.loadChildren(Arrays.asList(
|
||||
fileCommonLocation.loadChildren(Collections.singletonList(
|
||||
fileCommonLocation.createChildren(i18n("launcher.cache_directory.default"), EnumCommonDirectory.DEFAULT)
|
||||
), EnumCommonDirectory.CUSTOM);
|
||||
fileCommonLocation.selectedDataProperty().bindBidirectional(config().commonDirTypeProperty());
|
||||
|
||||
@@ -77,7 +77,7 @@ public class AddAccountPane extends StackPane {
|
||||
@FXML private SpinnerPane acceptPane;
|
||||
@FXML private HBox linksContainer;
|
||||
|
||||
private ListProperty<Hyperlink> links = new SimpleListProperty<>();;
|
||||
private ListProperty<Hyperlink> links = new SimpleListProperty<>();
|
||||
|
||||
public AddAccountPane() {
|
||||
FXUtils.loadFXML(this, "/assets/fxml/account-add.fxml");
|
||||
|
||||
@@ -21,10 +21,6 @@ import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.ReadOnlyStringProperty;
|
||||
import javafx.beans.property.ReadOnlyStringWrapper;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
||||
import org.jackhuang.hmcl.ui.Controllers;
|
||||
import org.jackhuang.hmcl.ui.ListPage;
|
||||
@@ -32,8 +28,6 @@ import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
||||
import org.jackhuang.hmcl.util.javafx.MappedObservableList;
|
||||
|
||||
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
||||
import static org.jackhuang.hmcl.ui.FXUtils.loadFXML;
|
||||
import static org.jackhuang.hmcl.ui.FXUtils.smoothScrolling;
|
||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
|
||||
public class AuthlibInjectorServersPage extends ListPage<AuthlibInjectorServerItem> implements DecoratorPage {
|
||||
|
||||
@@ -75,9 +75,7 @@ public class JFXCheckBoxTreeTableCell<S,T> extends TreeTableCell<S,T> {
|
||||
}
|
||||
|
||||
private ObjectProperty<Callback<Integer, ObservableValue<Boolean>>>
|
||||
selectedStateCallback =
|
||||
new SimpleObjectProperty<Callback<Integer, ObservableValue<Boolean>>>(
|
||||
this, "selectedStateCallback");
|
||||
selectedStateCallback = new SimpleObjectProperty<>(this, "selectedStateCallback");
|
||||
|
||||
public final ObjectProperty<Callback<Integer, ObservableValue<Boolean>>> selectedStateCallbackProperty() {
|
||||
return selectedStateCallback;
|
||||
|
||||
@@ -32,7 +32,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
|
||||
public final class MessageDialogPane extends StackPane {
|
||||
|
||||
public static enum MessageType {
|
||||
public enum MessageType {
|
||||
ERROR,
|
||||
INFORMATION,
|
||||
WARNING,
|
||||
|
||||
@@ -123,16 +123,13 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
||||
{
|
||||
StackPane container = new StackPane();
|
||||
Bindings.bindContent(container.getChildren(), skinnable.containerProperty());
|
||||
ListChangeListener<Node> listener = new ListChangeListener<Node>() {
|
||||
@Override
|
||||
public void onChanged(Change<? extends Node> c) {
|
||||
if (skinnable.getContainer().isEmpty()) {
|
||||
container.setMouseTransparent(true);
|
||||
container.setVisible(false);
|
||||
} else {
|
||||
container.setMouseTransparent(false);
|
||||
container.setVisible(true);
|
||||
}
|
||||
ListChangeListener<Node> listener = c -> {
|
||||
if (skinnable.getContainer().isEmpty()) {
|
||||
container.setMouseTransparent(true);
|
||||
container.setVisible(false);
|
||||
} else {
|
||||
container.setMouseTransparent(false);
|
||||
container.setVisible(true);
|
||||
}
|
||||
};
|
||||
skinnable.containerProperty().addListener(listener);
|
||||
|
||||
@@ -98,15 +98,15 @@ public final class InstallerWizardProvider implements WizardProvider {
|
||||
Task<Version> ret = Task.supplyAsync(() -> version);
|
||||
|
||||
if (settings.containsKey("forge"))
|
||||
ret = ret.thenCompose(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get("forge")));
|
||||
ret = ret.thenComposeAsync(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get("forge")));
|
||||
|
||||
if (settings.containsKey("liteloader"))
|
||||
ret = ret.thenCompose(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get("liteloader")));
|
||||
ret = ret.thenComposeAsync(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get("liteloader")));
|
||||
|
||||
if (settings.containsKey("optifine"))
|
||||
ret = ret.thenCompose(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get("optifine")));
|
||||
ret = ret.thenComposeAsync(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get("optifine")));
|
||||
|
||||
return ret.thenCompose(profile.getRepository().refreshVersionsAsync());
|
||||
return ret.thenComposeAsync(profile.getRepository().refreshVersionsAsync());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ModpackInstallWizardProvider implements WizardProvider {
|
||||
return null;
|
||||
} else {
|
||||
return ModpackHelper.getInstallTask(profile, selected, name, modpack)
|
||||
.thenRun(Schedulers.javafx(), () -> profile.setSelectedVersion(name));
|
||||
.thenRunAsync(Schedulers.javafx(), () -> profile.setSelectedVersion(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ public final class ModpackPage extends StackPane implements WizardPage {
|
||||
|
||||
spinnerPane.showSpinner();
|
||||
Task.supplyAsync(() -> CompressingUtils.findSuitableEncoding(selectedFile.toPath()))
|
||||
.thenApply(encoding -> manifest = ModpackHelper.readModpackManifest(selectedFile.toPath(), encoding))
|
||||
.thenApplyAsync(encoding -> manifest = ModpackHelper.readModpackManifest(selectedFile.toPath(), encoding))
|
||||
.whenComplete(Schedulers.javafx(), manifest -> {
|
||||
spinnerPane.hideSpinner();
|
||||
controller.getSettings().put(MODPACK_MANIFEST, manifest);
|
||||
|
||||
@@ -63,8 +63,8 @@ public final class UpdateInstallerWizardProvider implements WizardProvider {
|
||||
LinkedList<Library> newList = new LinkedList<>(version.getLibraries());
|
||||
newList.remove(oldLibrary);
|
||||
return new MaintainTask(version.setLibraries(newList))
|
||||
.thenCompose(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get(libraryId)))
|
||||
.then(profile.getRepository().refreshVersionsAsync());
|
||||
.thenComposeAsync(profile.getDependency().installLibraryAsync((RemoteVersion) settings.get(libraryId)))
|
||||
.thenComposeAsync(profile.getRepository().refreshVersionsAsync());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class VanillaInstallWizardProvider implements WizardProvider {
|
||||
builder.version((RemoteVersion) settings.get("optifine"));
|
||||
|
||||
return builder.buildAsync().whenComplete(any -> profile.getRepository().refreshVersions())
|
||||
.thenRun(Schedulers.javafx(), () -> profile.setSelectedVersion(name));
|
||||
.thenRunAsync(Schedulers.javafx(), () -> profile.setSelectedVersion(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,7 +80,7 @@ public final class ExportWizardProvider implements WizardProvider {
|
||||
), tempModpack);
|
||||
|
||||
if (includeLauncher) {
|
||||
dependency = dependency.thenRun(() -> {
|
||||
dependency = dependency.thenRunAsync(() -> {
|
||||
try (Zipper zip = new Zipper(modpackFile.toPath())) {
|
||||
Config exported = new Config();
|
||||
|
||||
|
||||
@@ -60,17 +60,18 @@ public class DatapackListPage extends ListPageBase<DatapackListPageSkin.Datapack
|
||||
|
||||
setItems(items = MappedObservableList.create(datapack.getInfo(), DatapackListPageSkin.DatapackInfoObject::new));
|
||||
|
||||
FXUtils.applyDragListener(this, it -> Objects.equals("zip", FileUtils.getExtension(it)), mods -> {
|
||||
mods.forEach(it -> {
|
||||
try {
|
||||
Datapack zip = new Datapack(it.toPath());
|
||||
zip.loadFromZip();
|
||||
zip.installTo(worldDir);
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Logging.LOG.log(Level.WARNING, "Unable to parse datapack file " + it, e);
|
||||
}
|
||||
});
|
||||
}, this::refresh);
|
||||
FXUtils.applyDragListener(this, it -> Objects.equals("zip", FileUtils.getExtension(it)),
|
||||
mods -> mods.forEach(this::installSingleDatapack), this::refresh);
|
||||
}
|
||||
|
||||
private void installSingleDatapack(File datapack) {
|
||||
try {
|
||||
Datapack zip = new Datapack(datapack.toPath());
|
||||
zip.loadFromZip();
|
||||
zip.installTo(worldDir);
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Logging.LOG.log(Level.WARNING, "Unable to parse datapack file " + datapack, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,8 +81,8 @@ public class DatapackListPage extends ListPageBase<DatapackListPageSkin.Datapack
|
||||
|
||||
public void refresh() {
|
||||
setLoading(true);
|
||||
Task.of(datapack::loadFromDir)
|
||||
.with(Task.of(Schedulers.javafx(), () -> setLoading(false)))
|
||||
Task.runAsync(datapack::loadFromDir)
|
||||
.withRunAsync(Schedulers.javafx(), () -> setLoading(false))
|
||||
.start();
|
||||
}
|
||||
|
||||
@@ -97,15 +98,7 @@ public class DatapackListPage extends ListPageBase<DatapackListPageSkin.Datapack
|
||||
List<File> res = chooser.showOpenMultipleDialog(Controllers.getStage());
|
||||
|
||||
if (res != null)
|
||||
res.forEach(it -> {
|
||||
try {
|
||||
Datapack zip = new Datapack(it.toPath());
|
||||
zip.loadFromZip();
|
||||
zip.installTo(worldDir);
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Logging.LOG.log(Level.WARNING, "Unable to parse datapack file " + it, e);
|
||||
}
|
||||
});
|
||||
res.forEach(this::installSingleDatapack);
|
||||
|
||||
datapack.loadFromDir();
|
||||
}
|
||||
|
||||
@@ -71,18 +71,18 @@ public class InstallerListPage extends ListPageBase<InstallerItem> {
|
||||
this.version = profile.getRepository().getResolvedVersion(versionId);
|
||||
this.gameVersion = null;
|
||||
|
||||
Task.ofResult(() -> {
|
||||
Task.supplyAsync(() -> {
|
||||
gameVersion = GameVersion.minecraftVersion(profile.getRepository().getVersionJar(version)).orElse(null);
|
||||
|
||||
return LibraryAnalyzer.analyze(version);
|
||||
}).thenAccept(Schedulers.javafx(), analyzer -> {
|
||||
}).thenAcceptAsync(Schedulers.javafx(), analyzer -> {
|
||||
Function<Library, Consumer<InstallerItem>> removeAction = library -> x -> {
|
||||
LinkedList<Library> newList = new LinkedList<>(version.getLibraries());
|
||||
newList.remove(library);
|
||||
new MaintainTask(version.setLibraries(newList))
|
||||
.thenCompose(maintainedVersion -> new VersionJsonSaveTask(profile.getRepository(), maintainedVersion))
|
||||
.withCompose(profile.getRepository().refreshVersionsAsync())
|
||||
.withRun(Schedulers.javafx(), () -> loadVersion(this.profile, this.versionId))
|
||||
.thenComposeAsync(maintainedVersion -> new VersionJsonSaveTask(profile.getRepository(), maintainedVersion))
|
||||
.withComposeAsync(profile.getRepository().refreshVersionsAsync())
|
||||
.withRunAsync(Schedulers.javafx(), () -> loadVersion(this.profile, this.versionId))
|
||||
.start();
|
||||
};
|
||||
|
||||
@@ -118,8 +118,8 @@ public class InstallerListPage extends ListPageBase<InstallerItem> {
|
||||
}
|
||||
|
||||
private void doInstallOffline(File file) {
|
||||
Task task = profile.getDependency().installLibraryAsync(version, file.toPath())
|
||||
.then(profile.getRepository().refreshVersionsAsync());
|
||||
Task<?> task = profile.getDependency().installLibraryAsync(version, file.toPath())
|
||||
.thenComposeAsync(profile.getRepository().refreshVersionsAsync());
|
||||
task.setName(i18n("install.installer.install_offline"));
|
||||
TaskExecutor executor = task.executor(new TaskListener() {
|
||||
@Override
|
||||
@@ -129,9 +129,9 @@ public class InstallerListPage extends ListPageBase<InstallerItem> {
|
||||
loadVersion(profile, versionId);
|
||||
Controllers.dialog(i18n("install.success"));
|
||||
} else {
|
||||
if (executor.getLastException() == null)
|
||||
if (executor.getException() == null)
|
||||
return;
|
||||
InstallerWizardProvider.alertFailureMessage(executor.getLastException(), null);
|
||||
InstallerWizardProvider.alertFailureMessage(executor.getException(), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public final class ModListPage extends ListPageBase<ModListPageSkin.ModInfoObjec
|
||||
// Actually addMod will not throw exceptions because FileChooser has already filtered files.
|
||||
}
|
||||
}
|
||||
}).withRun(Schedulers.javafx(), () -> {
|
||||
}).withRunAsync(Schedulers.javafx(), () -> {
|
||||
List<String> prompt = new LinkedList<>();
|
||||
if (!succeeded.isEmpty())
|
||||
prompt.add(i18n("mods.add.success", String.join(", ", succeeded)));
|
||||
|
||||
@@ -115,7 +115,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
||||
|
||||
FXUtils.smoothScrolling(scroll);
|
||||
|
||||
Task.supplyAsync(JavaVersion::getJavas).thenAccept(Schedulers.javafx(), list -> {
|
||||
Task.supplyAsync(JavaVersion::getJavas).thenAcceptAsync(Schedulers.javafx(), list -> {
|
||||
javaItem.loadChildren(list.stream()
|
||||
.map(javaVersion -> javaItem.createChildren(javaVersion.getVersion() + i18n("settings.game.java_directory.bit",
|
||||
javaVersion.getPlatform().getBit()), javaVersion.getBinary().toString(), javaVersion))
|
||||
@@ -271,7 +271,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
||||
if (versionSetting == null)
|
||||
return;
|
||||
Task.supplyAsync(versionSetting::getJavaVersion)
|
||||
.thenAccept(Schedulers.javafx(), javaVersion -> javaItem.setSubtitle(Optional.ofNullable(javaVersion)
|
||||
.thenAcceptAsync(Schedulers.javafx(), javaVersion -> javaItem.setSubtitle(Optional.ofNullable(javaVersion)
|
||||
.map(JavaVersion::getBinary).map(Path::toString).orElse("Invalid Java Path")))
|
||||
.start();
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class WorldListPage extends ListPageBase<WorldListItem> {
|
||||
setLoading(true);
|
||||
Task
|
||||
.runAsync(() -> gameVersion = GameVersion.minecraftVersion(profile.getRepository().getVersionJar(id)).orElse(null))
|
||||
.thenSupply(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
|
||||
.thenSupplyAsync(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
|
||||
.whenComplete(Schedulers.javafx(), (result, exception) -> {
|
||||
worlds = result;
|
||||
setLoading(false);
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface AbstractWizardDisplayer extends WizardDisplayer {
|
||||
|
||||
@Override
|
||||
default void handleTask(Map<String, Object> settings, Task<?> task) {
|
||||
TaskExecutor executor = task.withRun(Schedulers.javafx(), this::navigateToSuccess).executor();
|
||||
TaskExecutor executor = task.withRunAsync(Schedulers.javafx(), this::navigateToSuccess).executor();
|
||||
TaskListPane pane = new TaskListPane();
|
||||
pane.setExecutor(executor);
|
||||
navigateTo(pane, Navigation.NavigationDirection.FINISH);
|
||||
|
||||
@@ -38,10 +38,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -161,9 +158,7 @@ public final class UpdateHandler {
|
||||
commandline.add(JavaVersion.fromCurrentEnvironment().getBinary().toString());
|
||||
commandline.add("-jar");
|
||||
commandline.add(jar.toAbsolutePath().toString());
|
||||
for (String arg : appArgs) {
|
||||
commandline.add(arg);
|
||||
}
|
||||
commandline.addAll(Arrays.asList(appArgs));
|
||||
LOG.info("Starting process: " + commandline);
|
||||
new ProcessBuilder(commandline)
|
||||
.directory(Paths.get("").toAbsolutePath().toFile())
|
||||
@@ -206,11 +201,7 @@ public final class UpdateHandler {
|
||||
StackTraceElement element = stacktrace[i];
|
||||
if (Main.class.getName().equals(element.getClassName())) {
|
||||
// we've reached the main method
|
||||
if (i + 1 == stacktrace.length) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return i + 1 != stacktrace.length;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.String?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import com.jfoenix.controls.*?>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import com.jfoenix.controls.*?>
|
||||
<?import javafx.collections.FXCollections?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
|
||||
@@ -268,7 +268,6 @@ mods.add.success=Successfully added mods %s.
|
||||
mods.choose_mod=Choose your mods
|
||||
mods.enable=Enable
|
||||
mods.disable=Disable
|
||||
mods.name=Name
|
||||
mods.remove=Remove
|
||||
mods.not_modded=You should install a mod loader first (Forge, or LiteLoader)
|
||||
|
||||
@@ -321,7 +320,7 @@ settings=Game Settings
|
||||
|
||||
settings.advanced=Advanced Settings
|
||||
settings.advanced.dont_check_game_completeness=Don't check game completeness
|
||||
settings.advanced.dont_check_jvm_validity=Don't check whether JVM can launch the game or not
|
||||
settings.advanced.dont_check_jvm_validity=Don't check whether JVM can launch the game or not
|
||||
settings.advanced.game_dir.default=Default (.minecraft/)
|
||||
settings.advanced.game_dir.independent=Independent (.minecraft/versions/<version name>/, except assets,libraries)
|
||||
settings.advanced.java_args_default=Default java args: -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -XX:MaxPermSize=???m -Xmx???m -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true
|
||||
|
||||
@@ -205,7 +205,7 @@ main_page=主页
|
||||
|
||||
message.confirm=提示
|
||||
message.doing=请耐心等待
|
||||
message.downloading=正在下载...
|
||||
message.downloading=正在下载
|
||||
message.error=错误
|
||||
message.info=提示
|
||||
message.success=已完成
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
.trace { background-color: blue; }
|
||||
</style>
|
||||
<script>
|
||||
var colors = ["fatal", "error", "warn", "info", "debug", "trace"]
|
||||
var colors = ["fatal", "error", "warn", "info", "debug", "trace"];
|
||||
var limitedLogs = 100;
|
||||
function appendLog(log, level) {
|
||||
var e = document.createElement("div");
|
||||
@@ -78,13 +78,13 @@
|
||||
redisplay(c[i]);
|
||||
}
|
||||
function redisplay(div) {
|
||||
var flag = false
|
||||
var flag = false;
|
||||
for (var j = 0; j < colors.length; ++j) {
|
||||
if (div.className == colors[j]) {
|
||||
if (div.className === colors[j]) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
div.hidden = div.className != colors[j];
|
||||
div.hidden = div.className !== colors[j];
|
||||
}
|
||||
div.hidden = !flag;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public class AuthlibInjectorDownloader implements AuthlibInjectorArtifactProvide
|
||||
|
||||
private static final String LATEST_BUILD_URL = "https://authlib-injector.yushi.moe/artifact/latest.json";
|
||||
|
||||
private Path artifactLocation;
|
||||
private Supplier<DownloadProvider> downloadProvider;
|
||||
private final Path artifactLocation;
|
||||
private final Supplier<DownloadProvider> downloadProvider;
|
||||
|
||||
/**
|
||||
* The flag will be reset after application restart.
|
||||
|
||||
@@ -25,7 +25,7 @@ public enum TextureModel {
|
||||
|
||||
public final String modelName;
|
||||
|
||||
private TextureModel(String modelName) {
|
||||
TextureModel(String modelName) {
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
|
||||
public Task<Version> installLibraryAsync(String gameVersion, Version version, String libraryId, String libraryVersion) {
|
||||
VersionList<?> versionList = getVersionList(libraryId);
|
||||
return versionList.loadAsync(gameVersion, getDownloadProvider())
|
||||
.thenCompose(() -> installLibraryAsync(version, versionList.getVersion(gameVersion, libraryVersion)
|
||||
.thenComposeAsync(() -> installLibraryAsync(version, versionList.getVersion(gameVersion, libraryVersion)
|
||||
.orElseThrow(() -> new IllegalStateException("Remote library " + libraryId + " has no version " + libraryVersion))));
|
||||
}
|
||||
|
||||
@@ -108,9 +108,9 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
|
||||
else
|
||||
throw new IllegalArgumentException("Remote library " + libraryVersion + " is unrecognized.");
|
||||
return task
|
||||
.thenCompose(LibrariesUniqueTask::new)
|
||||
.thenCompose(MaintainTask::new)
|
||||
.thenCompose(newVersion -> new VersionJsonSaveTask(repository, newVersion));
|
||||
.thenComposeAsync(LibrariesUniqueTask::new)
|
||||
.thenComposeAsync(MaintainTask::new)
|
||||
.thenComposeAsync(newVersion -> new VersionJsonSaveTask(repository, newVersion));
|
||||
}
|
||||
|
||||
|
||||
@@ -120,9 +120,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
|
||||
|
||||
public Task installLibraryAsync(Version oldVersion, Path installer) {
|
||||
return Task
|
||||
.of(() -> {
|
||||
})
|
||||
.thenCompose(() -> {
|
||||
.composeAsync(() -> {
|
||||
try {
|
||||
return ForgeInstallTask.install(this, oldVersion, installer);
|
||||
} catch (IOException ignore) {
|
||||
@@ -135,8 +133,8 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
|
||||
|
||||
throw new UnsupportedOperationException("Library cannot be recognized");
|
||||
})
|
||||
.thenCompose(LibrariesUniqueTask::new)
|
||||
.thenCompose(MaintainTask::new)
|
||||
.thenCompose(newVersion -> new VersionJsonSaveTask(repository, newVersion));
|
||||
.thenComposeAsync(LibrariesUniqueTask::new)
|
||||
.thenComposeAsync(MaintainTask::new)
|
||||
.thenComposeAsync(newVersion -> new VersionJsonSaveTask(repository, newVersion));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,25 +47,25 @@ public class DefaultGameBuilder extends GameBuilder {
|
||||
|
||||
@Override
|
||||
public Task<?> buildAsync() {
|
||||
return new VersionJsonDownloadTask(gameVersion, dependencyManager).thenCompose(rawJson -> {
|
||||
return new VersionJsonDownloadTask(gameVersion, dependencyManager).thenComposeAsync(rawJson -> {
|
||||
Version original = JsonUtils.GSON.fromJson(rawJson, Version.class);
|
||||
Version version = original.setId(name).setJar(null);
|
||||
Task<?> vanillaTask = downloadGameAsync(gameVersion, version).thenCompose(Task.allOf(
|
||||
Task<?> vanillaTask = downloadGameAsync(gameVersion, version).thenComposeAsync(Task.allOf(
|
||||
new GameAssetDownloadTask(dependencyManager, version, GameAssetDownloadTask.DOWNLOAD_INDEX_FORCIBLY),
|
||||
new GameLibrariesTask(dependencyManager, version) // Game libraries will be downloaded for multiple times partly, this time is for vanilla libraries.
|
||||
).withCompose(new VersionJsonSaveTask(dependencyManager.getGameRepository(), version))); // using [with] because download failure here are tolerant.
|
||||
).withComposeAsync(new VersionJsonSaveTask(dependencyManager.getGameRepository(), version))); // using [with] because download failure here are tolerant.
|
||||
|
||||
Task<Version> libraryTask = vanillaTask.thenSupply(() -> version);
|
||||
Task<Version> libraryTask = vanillaTask.thenSupplyAsync(() -> version);
|
||||
|
||||
if (toolVersions.containsKey("forge"))
|
||||
libraryTask = libraryTask.thenCompose(libraryTaskHelper(gameVersion, "forge"));
|
||||
libraryTask = libraryTask.thenComposeAsync(libraryTaskHelper(gameVersion, "forge"));
|
||||
if (toolVersions.containsKey("liteloader"))
|
||||
libraryTask = libraryTask.thenCompose(libraryTaskHelper(gameVersion, "liteloader"));
|
||||
libraryTask = libraryTask.thenComposeAsync(libraryTaskHelper(gameVersion, "liteloader"));
|
||||
if (toolVersions.containsKey("optifine"))
|
||||
libraryTask = libraryTask.thenCompose(libraryTaskHelper(gameVersion, "optifine"));
|
||||
libraryTask = libraryTask.thenComposeAsync(libraryTaskHelper(gameVersion, "optifine"));
|
||||
|
||||
for (RemoteVersion remoteVersion : remoteVersions)
|
||||
libraryTask = libraryTask.thenCompose(dependencyManager.installLibraryAsync(remoteVersion));
|
||||
libraryTask = libraryTask.thenComposeAsync(dependencyManager.installLibraryAsync(remoteVersion));
|
||||
|
||||
return libraryTask;
|
||||
}).whenComplete(exception -> {
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class CurseCompletionTask extends Task<Void> {
|
||||
private final DefaultGameRepository repository;
|
||||
private final ModManager modManager;
|
||||
private final String version;
|
||||
private CurseManifest manifest = null;
|
||||
private CurseManifest manifest;
|
||||
private final List<Task<?>> dependents = new LinkedList<>();
|
||||
private final List<Task<?>> dependencies = new LinkedList<>();
|
||||
|
||||
|
||||
@@ -174,10 +174,8 @@ public class Datapack {
|
||||
continue;
|
||||
|
||||
String name = FileUtils.getName(subDir);
|
||||
boolean enabled = true;
|
||||
if (name.endsWith(".disabled")) {
|
||||
name = name.substring(0, name.length() - ".disabled".length());
|
||||
enabled = false;
|
||||
}
|
||||
if (!name.endsWith(".zip"))
|
||||
continue;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.jackhuang.hmcl.mod;
|
||||
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
import org.jackhuang.hmcl.util.io.CompressingUtils;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
|
||||
|
||||
@@ -20,12 +20,9 @@ package org.jackhuang.hmcl.mod;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hmcl.util.Immutable;
|
||||
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||
import org.jackhuang.hmcl.util.io.CompressingUtils;
|
||||
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
@@ -155,7 +155,7 @@ public final class MultiMCModpackInstallTask extends Task<Void> {
|
||||
}
|
||||
}
|
||||
|
||||
dependencies.add(new MaintainTask(version).thenCompose(maintainedVersion -> new VersionJsonSaveTask(repository, maintainedVersion)));
|
||||
dependencies.add(new MaintainTask(version).thenComposeAsync(maintainedVersion -> new VersionJsonSaveTask(repository, maintainedVersion)));
|
||||
dependencies.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), "/" + manifest.getName() + "/minecraft", manifest, MODPACK_TYPE, repository.getModpackConfiguration(name)));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.jackhuang.hmcl.mod;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hmcl.util.Immutable;
|
||||
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||
@@ -28,14 +27,9 @@ import org.jackhuang.hmcl.util.io.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Immutable
|
||||
public class PackMcMeta implements Validation {
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
@@ -200,13 +200,13 @@ public abstract class Task<T> {
|
||||
|
||||
/**
|
||||
* @throws InterruptedException if current thread is interrupted
|
||||
* @see Thread#isInterrupted
|
||||
* @see Thread#interrupted
|
||||
*/
|
||||
public void preExecute() throws Exception {}
|
||||
|
||||
/**
|
||||
* @throws InterruptedException if current thread is interrupted
|
||||
* @see Thread#isInterrupted
|
||||
* @see Thread#interrupted
|
||||
*/
|
||||
public abstract void execute() throws Exception;
|
||||
|
||||
@@ -222,7 +222,7 @@ public abstract class Task<T> {
|
||||
* {@link Task#isRelyingOnDependencies()} returns true or false.
|
||||
*
|
||||
* @throws InterruptedException if current thread is interrupted
|
||||
* @see Thread#isInterrupted
|
||||
* @see Thread#interrupted
|
||||
* @see Task#isDependenciesSucceeded()
|
||||
*/
|
||||
public void postExecute() throws Exception {}
|
||||
@@ -342,8 +342,8 @@ public abstract class Task<T> {
|
||||
* @param <U> the function's return type
|
||||
* @return the new Task
|
||||
*/
|
||||
public <U, E extends Exception> Task<U> thenApply(ExceptionalFunction<T, U, E> fn) {
|
||||
return thenApply(Schedulers.defaultScheduler(), fn);
|
||||
public <U, E extends Exception> Task<U> thenApplyAsync(ExceptionalFunction<T, U, E> fn) {
|
||||
return thenApplyAsync(Schedulers.defaultScheduler(), fn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,8 +356,8 @@ public abstract class Task<T> {
|
||||
* @param <U> the function's return type
|
||||
* @return the new Task
|
||||
*/
|
||||
public <U, E extends Exception> Task<U> thenApply(Executor executor, ExceptionalFunction<T, U, E> fn) {
|
||||
return thenApply(getCaller(), executor, fn);
|
||||
public <U, E extends Exception> Task<U> thenApplyAsync(Executor executor, ExceptionalFunction<T, U, E> fn) {
|
||||
return thenApplyAsync(getCaller(), executor, fn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,7 +371,7 @@ public abstract class Task<T> {
|
||||
* @param <U> the function's return type
|
||||
* @return the new Task
|
||||
*/
|
||||
public <U, E extends Exception> Task<U> thenApply(String name, Executor executor, ExceptionalFunction<T, U, E> fn) {
|
||||
public <U, E extends Exception> Task<U> thenApplyAsync(String name, Executor executor, ExceptionalFunction<T, U, E> fn) {
|
||||
return new UniApply<>(fn).setExecutor(executor).setName(name);
|
||||
}
|
||||
|
||||
@@ -384,8 +384,8 @@ public abstract class Task<T> {
|
||||
* returned Task
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> thenAccept(ExceptionalConsumer<T, E> action) {
|
||||
return thenAccept(Schedulers.defaultScheduler(), action);
|
||||
public <E extends Exception> Task<Void> thenAcceptAsync(ExceptionalConsumer<T, E> action) {
|
||||
return thenAcceptAsync(Schedulers.defaultScheduler(), action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,8 +397,8 @@ public abstract class Task<T> {
|
||||
* @param executor the executor to use for asynchronous execution
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> thenAccept(Executor executor, ExceptionalConsumer<T, E> action) {
|
||||
return thenAccept(getCaller(), executor, action);
|
||||
public <E extends Exception> Task<Void> thenAcceptAsync(Executor executor, ExceptionalConsumer<T, E> action) {
|
||||
return thenAcceptAsync(getCaller(), executor, action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,8 +411,8 @@ public abstract class Task<T> {
|
||||
* @param executor the executor to use for asynchronous execution
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> thenAccept(String name, Executor executor, ExceptionalConsumer<T, E> action) {
|
||||
return thenApply(name, executor, result -> {
|
||||
public <E extends Exception> Task<Void> thenAcceptAsync(String name, Executor executor, ExceptionalConsumer<T, E> action) {
|
||||
return thenApplyAsync(name, executor, result -> {
|
||||
action.accept(result);
|
||||
return null;
|
||||
});
|
||||
@@ -426,8 +426,8 @@ public abstract class Task<T> {
|
||||
* returned Task
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> thenRun(ExceptionalRunnable<E> action) {
|
||||
return thenRun(Schedulers.defaultScheduler(), action);
|
||||
public <E extends Exception> Task<Void> thenRunAsync(ExceptionalRunnable<E> action) {
|
||||
return thenRunAsync(Schedulers.defaultScheduler(), action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -439,8 +439,8 @@ public abstract class Task<T> {
|
||||
* @param executor the executor to use for asynchronous execution
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> thenRun(Executor executor, ExceptionalRunnable<E> action) {
|
||||
return thenRun(getCaller(), executor, action);
|
||||
public <E extends Exception> Task<Void> thenRunAsync(Executor executor, ExceptionalRunnable<E> action) {
|
||||
return thenRunAsync(getCaller(), executor, action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -453,8 +453,8 @@ public abstract class Task<T> {
|
||||
* @param executor the executor to use for asynchronous execution
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> thenRun(String name, Executor executor, ExceptionalRunnable<E> action) {
|
||||
return thenApply(name, executor, ignore -> {
|
||||
public <E extends Exception> Task<Void> thenRunAsync(String name, Executor executor, ExceptionalRunnable<E> action) {
|
||||
return thenApplyAsync(name, executor, ignore -> {
|
||||
action.run();
|
||||
return null;
|
||||
});
|
||||
@@ -468,8 +468,8 @@ public abstract class Task<T> {
|
||||
* @param <U> the function's return type
|
||||
* @return the new Task
|
||||
*/
|
||||
public final <U> Task<U> thenSupply(Callable<U> fn) {
|
||||
return thenCompose(() -> Task.supplyAsync(fn));
|
||||
public final <U> Task<U> thenSupplyAsync(Callable<U> fn) {
|
||||
return thenComposeAsync(() -> Task.supplyAsync(fn));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -481,8 +481,8 @@ public abstract class Task<T> {
|
||||
* @param <U> the function's return type
|
||||
* @return the new Task
|
||||
*/
|
||||
public final <U> Task<U> thenSupply(String name, Callable<U> fn) {
|
||||
return thenCompose(() -> Task.supplyAsync(name, fn));
|
||||
public final <U> Task<U> thenSupplyAsync(String name, Callable<U> fn) {
|
||||
return thenComposeAsync(() -> Task.supplyAsync(name, fn));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,8 +493,8 @@ public abstract class Task<T> {
|
||||
* @param <U> the type of the returned Task's result
|
||||
* @return the Task
|
||||
*/
|
||||
public final <U> Task<U> thenCompose(Task<U> other) {
|
||||
return thenCompose(() -> other);
|
||||
public final <U> Task<U> thenComposeAsync(Task<U> other) {
|
||||
return thenComposeAsync(() -> other);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,7 +505,7 @@ public abstract class Task<T> {
|
||||
* @param <U> the type of the returned Task's result
|
||||
* @return the Task
|
||||
*/
|
||||
public final <U> Task<U> thenCompose(ExceptionalSupplier<Task<U>, ?> fn) {
|
||||
public final <U> Task<U> thenComposeAsync(ExceptionalSupplier<Task<U>, ?> fn) {
|
||||
return new UniCompose<>(fn, true);
|
||||
}
|
||||
|
||||
@@ -518,15 +518,15 @@ public abstract class Task<T> {
|
||||
* @param <U> the type of the returned Task's result
|
||||
* @return the Task
|
||||
*/
|
||||
public <U, E extends Exception> Task<U> thenCompose(ExceptionalFunction<T, Task<U>, E> fn) {
|
||||
public <U, E extends Exception> Task<U> thenComposeAsync(ExceptionalFunction<T, Task<U>, E> fn) {
|
||||
return new UniCompose<>(fn, true);
|
||||
}
|
||||
|
||||
public final <U> Task<U> withCompose(Task<U> other) {
|
||||
return withCompose(() -> other);
|
||||
public final <U> Task<U> withComposeAsync(Task<U> other) {
|
||||
return withComposeAsync(() -> other);
|
||||
}
|
||||
|
||||
public final <U, E extends Exception> Task<U> withCompose(ExceptionalSupplier<Task<U>, E> fn) {
|
||||
public final <U, E extends Exception> Task<U> withComposeAsync(ExceptionalSupplier<Task<U>, E> fn) {
|
||||
return new UniCompose<>(fn, false);
|
||||
}
|
||||
|
||||
@@ -538,8 +538,8 @@ public abstract class Task<T> {
|
||||
* returned Task
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> withRun(ExceptionalRunnable<E> action) {
|
||||
return withRun(Schedulers.defaultScheduler(), action);
|
||||
public <E extends Exception> Task<Void> withRunAsync(ExceptionalRunnable<E> action) {
|
||||
return withRunAsync(Schedulers.defaultScheduler(), action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -551,8 +551,8 @@ public abstract class Task<T> {
|
||||
* @param executor the executor to use for asynchronous execution
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> withRun(Executor executor, ExceptionalRunnable<E> action) {
|
||||
return withRun(getCaller(), executor, action);
|
||||
public <E extends Exception> Task<Void> withRunAsync(Executor executor, ExceptionalRunnable<E> action) {
|
||||
return withRunAsync(getCaller(), executor, action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -565,7 +565,7 @@ public abstract class Task<T> {
|
||||
* @param executor the executor to use for asynchronous execution
|
||||
* @return the new Task
|
||||
*/
|
||||
public <E extends Exception> Task<Void> withRun(String name, Executor executor, ExceptionalRunnable<E> action) {
|
||||
public <E extends Exception> Task<Void> withRunAsync(String name, Executor executor, ExceptionalRunnable<E> action) {
|
||||
return new UniCompose<>(() -> Task.runAsync(name, executor, action), false);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ public class Pair<K, V> implements Map.Entry<K, V> {
|
||||
private K key;
|
||||
private V value;
|
||||
|
||||
@Deprecated
|
||||
public Pair(K key, V value) {
|
||||
private Pair(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ public final class NetworkUtils {
|
||||
|
||||
/**
|
||||
* @see <a href="https://github.com/curl/curl/blob/3f7b1bb89f92c13e69ee51b710ac54f775aab320/lib/transfer.c#L1427-L1461">Curl</a>
|
||||
* @param location
|
||||
* @return
|
||||
* @param location the url to be URL encoded
|
||||
* @return encoded URL
|
||||
*/
|
||||
public static String encodeLocation(String location) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -93,11 +93,11 @@ public final class NetworkUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method aims to solve problem when "Location" in stupid server's response is not encoded.
|
||||
* This method is a work-around that aims to solve problem when "Location" in stupid server's response is not encoded.
|
||||
* @see <a href="https://github.com/curl/curl/issues/473">Issue with libcurl</a>
|
||||
* @param conn
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @param conn the stupid http connection.
|
||||
* @return manually redirected http connection.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public static HttpURLConnection resolveConnection(HttpURLConnection conn) throws IOException {
|
||||
int redirect = 0;
|
||||
|
||||
@@ -37,7 +37,6 @@ import javafx.beans.value.ObservableValue;
|
||||
*/
|
||||
public abstract class BindingMapping<T, U> extends ObjectBinding<U> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> BindingMapping<?, T> of(ObservableValue<T> property) {
|
||||
if (property instanceof BindingMapping) {
|
||||
return (BindingMapping<?, T>) property;
|
||||
|
||||
@@ -130,7 +130,7 @@ public final class ExtendedProperties {
|
||||
return (ObjectProperty<Boolean>) checkbox.getProperties().computeIfAbsent(
|
||||
PROP_PREFIX + ".checkbox.reservedSelected",
|
||||
any -> new MappedProperty<>(checkbox, "ext.reservedSelected",
|
||||
checkbox.selectedProperty(), it -> !(boolean) it, it -> !(boolean) it));
|
||||
checkbox.selectedProperty(), it -> !it, it -> !it));
|
||||
}
|
||||
// ====
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public enum OperatingSystem {
|
||||
return Paths.get(home, "." + folder);
|
||||
case WINDOWS:
|
||||
String appdata = System.getenv("APPDATA");
|
||||
return Paths.get(Lang.nonNull(appdata, home), "." + folder);
|
||||
return Paths.get(appdata == null ? home : appdata, "." + folder);
|
||||
case OSX:
|
||||
return Paths.get(home, "Library", "Application Support", folder);
|
||||
default:
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -50,12 +49,12 @@ public class TaskTest {
|
||||
AtomicBoolean bool = new AtomicBoolean();
|
||||
boolean success = Task.supplyAsync(() -> {
|
||||
throw new IllegalStateException();
|
||||
}).withRun(() -> {
|
||||
}).withRunAsync(() -> {
|
||||
bool.set(true);
|
||||
}).test();
|
||||
|
||||
Assert.assertTrue("Task should success because withRun will ignore previous exception", success);
|
||||
Assert.assertTrue("withRun should be executed", bool.get());
|
||||
Assert.assertTrue("Task should success because withRunAsync will ignore previous exception", success);
|
||||
Assert.assertTrue("withRunAsync should be executed", bool.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,7 +62,7 @@ public class TaskTest {
|
||||
new JFXPanel(); // init JavaFX Toolkit
|
||||
AtomicBoolean flag = new AtomicBoolean();
|
||||
boolean result = Task.supplyAsync(JavaVersion::fromCurrentEnvironment)
|
||||
.thenAccept(Schedulers.javafx(), javaVersion -> {
|
||||
.thenAcceptAsync(Schedulers.javafx(), javaVersion -> {
|
||||
flag.set(true);
|
||||
Assert.assertEquals(javaVersion, JavaVersion.fromCurrentEnvironment());
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user