Fix HMCL import
This commit is contained in:
@@ -101,12 +101,12 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
|
||||
public Task<Version> installLibraryAsync(Version baseVersion, RemoteVersion libraryVersion) {
|
||||
if (baseVersion.isResolved()) throw new IllegalArgumentException("Version should not be resolved");
|
||||
|
||||
return libraryVersion.getInstallTask(this, baseVersion)
|
||||
return removeLibraryAsync(baseVersion.resolvePreservingPatches(repository), libraryVersion.getLibraryId())
|
||||
.thenComposeAsync(version -> libraryVersion.getInstallTask(this, version))
|
||||
.thenApplyAsync(baseVersion::addPatch)
|
||||
.thenComposeAsync(repository::save);
|
||||
}
|
||||
|
||||
|
||||
public ExceptionalFunction<Version, Task<Version>, ?> installLibraryAsync(RemoteVersion libraryVersion) {
|
||||
return version -> installLibraryAsync(version, libraryVersion);
|
||||
}
|
||||
@@ -139,28 +139,19 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
|
||||
* Remove installed library.
|
||||
* Will try to remove libraries and patches.
|
||||
*
|
||||
* @param versionId version id
|
||||
* @param version not resolved version
|
||||
* @param libraryId forge/liteloader/optifine/fabric
|
||||
* @return task to remove the specified library
|
||||
*/
|
||||
public Task<Version> removeLibraryWithoutSavingAsync(String versionId, String libraryId) {
|
||||
public Task<Version> removeLibraryAsync(Version version, String libraryId) {
|
||||
// MaintainTask requires version that does not inherits from any version.
|
||||
// If we want to remove a library in dependent version, we should keep the dependents not changed
|
||||
// So resolving this game version to preserve all information in this version.json is necessary.
|
||||
Version version = repository.getResolvedPreservingPatchesVersion(versionId);
|
||||
if (version.isResolved())
|
||||
throw new IllegalArgumentException("removeLibraryWithoutSavingAsync requires non-resolved version");
|
||||
Version independentVersion = version.resolvePreservingPatches(repository);
|
||||
|
||||
return Task.supplyAsync(() -> LibraryAnalyzer.analyze(version).removeLibrary(libraryId).build());
|
||||
return Task.supplyAsync(() -> LibraryAnalyzer.analyze(independentVersion).removeLibrary(libraryId).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove installed library.
|
||||
* Will try to remove libraries and patches.
|
||||
*
|
||||
* @param versionId version id
|
||||
* @param libraryId forge/liteloader/optifine/fabric
|
||||
* @return task to remove the specified library
|
||||
*/
|
||||
public Task<Version> removeLibraryAsync(String versionId, String libraryId) {
|
||||
return removeLibraryWithoutSavingAsync(versionId, libraryId).thenComposeAsync(repository::save);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,19 +20,17 @@ package org.jackhuang.hmcl.download;
|
||||
import org.jackhuang.hmcl.game.Library;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class LibraryAnalyzer {
|
||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
||||
|
||||
public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMark> {
|
||||
private Version version;
|
||||
private final Map<String, Pair<Library, String>> libraries;
|
||||
|
||||
@@ -49,9 +47,23 @@ public final class LibraryAnalyzer {
|
||||
return Optional.ofNullable(libraries.get(type)).map(Pair::getValue);
|
||||
}
|
||||
|
||||
public void forEachLibrary(BiConsumer<String, @Nullable String> callback) {
|
||||
for (Map.Entry<String, Pair<Library, String>> entry : libraries.entrySet())
|
||||
callback.accept(entry.getKey(), entry.getValue().getValue());
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<LibraryMark> iterator() {
|
||||
return new Iterator<LibraryMark>() {
|
||||
Iterator<Map.Entry<String, Pair<Library, String>>> impl = libraries.entrySet().iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return impl.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryMark next() {
|
||||
Map.Entry<String, Pair<Library, String>> entry = impl.next();
|
||||
return new LibraryMark(entry.getKey(), entry.getValue().getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean has(LibraryType type) {
|
||||
@@ -122,7 +134,7 @@ public final class LibraryAnalyzer {
|
||||
|
||||
for (LibraryType type : LibraryType.values()) {
|
||||
if (type.group.matcher(groupId).matches() && type.artifact.matcher(artifactId).matches()) {
|
||||
libraries.put(type.getPatchId(), Pair.pair(library, library.getVersion()));
|
||||
libraries.put(type.getPatchId(), pair(library, library.getVersion()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -130,7 +142,7 @@ public final class LibraryAnalyzer {
|
||||
|
||||
for (Version patch : version.getPatches()) {
|
||||
if (patch.isHidden()) continue;
|
||||
libraries.put(patch.getId(), Pair.pair(null, patch.getVersion()));
|
||||
libraries.put(patch.getId(), pair(null, patch.getVersion()));
|
||||
}
|
||||
|
||||
return new LibraryAnalyzer(version, libraries);
|
||||
@@ -169,4 +181,24 @@ public final class LibraryAnalyzer {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LibraryMark {
|
||||
private final String libraryId;
|
||||
private final String libraryVersion;
|
||||
|
||||
public LibraryMark(@NotNull String libraryId, @Nullable String libraryVersion) {
|
||||
this.libraryId = libraryId;
|
||||
this.libraryVersion = libraryVersion;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLibraryId() {
|
||||
return libraryId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLibraryVersion() {
|
||||
return libraryVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Objects;
|
||||
*/
|
||||
public class RemoteVersion implements Comparable<RemoteVersion> {
|
||||
|
||||
private final String libraryId;
|
||||
private final String gameVersion;
|
||||
private final String selfVersion;
|
||||
private final String url;
|
||||
@@ -43,8 +44,8 @@ public class RemoteVersion implements Comparable<RemoteVersion> {
|
||||
* @param selfVersion the version string of the remote version.
|
||||
* @param url the installer or universal jar URL.
|
||||
*/
|
||||
public RemoteVersion(String gameVersion, String selfVersion, String url) {
|
||||
this(gameVersion, selfVersion, url, Type.UNCATEGORIZED);
|
||||
public RemoteVersion(String libraryId, String gameVersion, String selfVersion, String url) {
|
||||
this(libraryId, gameVersion, selfVersion, url, Type.UNCATEGORIZED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,13 +55,18 @@ public class RemoteVersion implements Comparable<RemoteVersion> {
|
||||
* @param selfVersion the version string of the remote version.
|
||||
* @param url the installer or universal jar URL.
|
||||
*/
|
||||
public RemoteVersion(String gameVersion, String selfVersion, String url, Type type) {
|
||||
public RemoteVersion(String libraryId, String gameVersion, String selfVersion, String url, Type type) {
|
||||
this.libraryId = Objects.requireNonNull(libraryId);
|
||||
this.gameVersion = Objects.requireNonNull(gameVersion);
|
||||
this.selfVersion = Objects.requireNonNull(selfVersion);
|
||||
this.url = Objects.requireNonNull(url);
|
||||
this.type = Objects.requireNonNull(type);
|
||||
}
|
||||
|
||||
public String getLibraryId() {
|
||||
return libraryId;
|
||||
}
|
||||
|
||||
public String getGameVersion() {
|
||||
return gameVersion;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.download.fabric;
|
||||
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||
import org.jackhuang.hmcl.download.LibraryAnalyzer;
|
||||
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
@@ -31,7 +32,7 @@ public class FabricRemoteVersion extends RemoteVersion {
|
||||
* @param url the installer or universal jar URL.
|
||||
*/
|
||||
FabricRemoteVersion(String gameVersion, String selfVersion, String url) {
|
||||
super(gameVersion, selfVersion, url);
|
||||
super(LibraryAnalyzer.LibraryType.FABRIC.getPatchId(), gameVersion, selfVersion, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.download.forge;
|
||||
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||
import org.jackhuang.hmcl.download.LibraryAnalyzer;
|
||||
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
@@ -31,7 +32,7 @@ public class ForgeRemoteVersion extends RemoteVersion {
|
||||
* @param url the installer or universal jar URL.
|
||||
*/
|
||||
public ForgeRemoteVersion(String gameVersion, String selfVersion, String url) {
|
||||
super(gameVersion, selfVersion, url);
|
||||
super(LibraryAnalyzer.LibraryType.FORGE.getPatchId(), gameVersion, selfVersion, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.download.game;
|
||||
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||
import org.jackhuang.hmcl.download.LibraryAnalyzer;
|
||||
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||
import org.jackhuang.hmcl.game.ReleaseType;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
@@ -37,7 +38,7 @@ public final class GameRemoteVersion extends RemoteVersion {
|
||||
private final Date time;
|
||||
|
||||
public GameRemoteVersion(String gameVersion, String selfVersion, String url, ReleaseType type, Date time) {
|
||||
super(gameVersion, selfVersion, url, getReleaseType(type));
|
||||
super(LibraryAnalyzer.LibraryType.MINECRAFT.getPatchId(), gameVersion, selfVersion, url, getReleaseType(type));
|
||||
this.type = type;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.download.liteloader;
|
||||
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||
import org.jackhuang.hmcl.download.LibraryAnalyzer;
|
||||
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||
import org.jackhuang.hmcl.game.Library;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
@@ -36,7 +37,7 @@ public class LiteLoaderRemoteVersion extends RemoteVersion {
|
||||
* @param url the installer or universal jar URL.
|
||||
*/
|
||||
LiteLoaderRemoteVersion(String gameVersion, String selfVersion, String url, String tweakClass, Collection<Library> libraries) {
|
||||
super(gameVersion, selfVersion, url);
|
||||
super(LibraryAnalyzer.LibraryType.LITELOADER.getPatchId(), gameVersion, selfVersion, url);
|
||||
|
||||
this.tweakClass = tweakClass;
|
||||
this.libraries = libraries;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.download.optifine;
|
||||
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||
import org.jackhuang.hmcl.download.LibraryAnalyzer;
|
||||
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
@@ -28,7 +29,7 @@ public class OptiFineRemoteVersion extends RemoteVersion {
|
||||
private final Supplier<String> url;
|
||||
|
||||
public OptiFineRemoteVersion(String gameVersion, String selfVersion, Supplier<String> url, boolean snapshot) {
|
||||
super(gameVersion, selfVersion, "", snapshot ? Type.SNAPSHOT : Type.RELEASE);
|
||||
super(LibraryAnalyzer.LibraryType.OPTIFINE.getPatchId(), gameVersion, selfVersion, "", snapshot ? Type.SNAPSHOT : Type.RELEASE);
|
||||
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user