Skip to content

Commit

Permalink
Merge branch 'classloader-identify-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIIL committed Dec 7, 2024
2 parents 654fd72 + 58dc450 commit 53dd4ab
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,7 @@ public boolean locateGame(QuiltLauncher launcher, String[] args) {
}
}

for (Path path : classifier.getUnmatchedOrigins()) {
if (!classpath.contains(path)) {
miscGameLibraries.add(path);
}
}
miscGameLibraries.addAll(classifier.getUnmatchedOrigins());
} catch (IOException e) {
throw ExceptionUtil.wrap(e);
}
Expand Down
57 changes: 55 additions & 2 deletions src/main/java/org/quiltmc/loader/impl/game/LibClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -28,11 +29,13 @@
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
Expand All @@ -44,6 +47,7 @@
import org.quiltmc.loader.impl.util.LoaderUtil;
import org.quiltmc.loader.impl.util.ManifestUtil;
import org.quiltmc.loader.impl.util.SystemProperties;
import org.quiltmc.loader.impl.util.UrlConversionException;
import org.quiltmc.loader.impl.util.UrlUtil;
import org.quiltmc.loader.impl.util.log.Log;
import org.quiltmc.loader.impl.util.log.LogCategory;
Expand Down Expand Up @@ -101,8 +105,57 @@ public LibClassifier(Class<L> cls, EnvType env, GameProvider gameProvider) throw
for (LoaderLibrary lib : LoaderLibrary.values()) {
if (!lib.isApplicable(env, junitRun)) continue;

if (lib.path != null) {
Path path = LoaderUtil.normalizeExistingPath(lib.path);
Path path = lib.path;

if (path == null && lib == LoaderLibrary.SERVER_LAUNCH) {

// Newer versions of the server launcher only contain a manifest file
// So we have to search for a manifest file which contains a Main-Class entry
// with a value of "org.quiltmc.loader.impl.launch.server.QuiltServerLauncher"
// or a Class-Path which references loader itself

if (DEBUG) {
Log.info(LogCategory.LIB_CLASSIFICATION, "Starting Quilt Server Launcher classification checking...");
}

Enumeration<URL> manifests = LibClassifier.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (manifests.hasMoreElements()) {
URL url = manifests.nextElement();
try (InputStream is = url.openStream()) {
Manifest manifest = new Manifest(is);
Attributes attrs = manifest.getMainAttributes();
String mainClass = attrs.getValue(Attributes.Name.MAIN_CLASS);
String classPath = attrs.getValue(Attributes.Name.CLASS_PATH);
if (mainClass == null || classPath == null) {
continue;
}

Path source = LoaderUtil.normalizeExistingPath(UrlUtil.getCodeSource(url, "META-INF/MANIFEST.MF"));
if (DEBUG) {
Log.info(LogCategory.LIB_CLASSIFICATION, "Manifest for " + source + ": " + mainClass + "; " + classPath);
}

Path loaderSource = UrlUtil.LOADER_CODE_SOURCE;
Path relative = source.getParent().relativize(loaderSource);
if (DEBUG) {
Log.info(LogCategory.LIB_CLASSIFICATION, " loader relative = " + relative);
}

String expectedStr = relative.toString().replace(relative.getFileSystem().getSeparator(), "/");

if (classPath.contains(expectedStr)) {
path = source;
break;
}

} catch (UrlConversionException e) {
throw new RuntimeException(e);
}
}
}

if (path != null) {
path = LoaderUtil.normalizeExistingPath(path);
systemLibraries.add(path);

if (DEBUG) sb.append(String.format("✅ %s %s%n", lib.name(), path));
Expand Down

0 comments on commit 53dd4ab

Please sign in to comment.