diff --git a/build.gradle b/build.gradle index 7e86a2fd6..443730501 100644 --- a/build.gradle +++ b/build.gradle @@ -88,7 +88,7 @@ java { jar { manifest { attributes ( - 'Main-Class': 'net.fabricmc.loader.launch.server.FabricServerLauncher' + 'Main-Class': 'net.fabricmc.loader.impl.launch.server.FabricServerLauncher' ) } diff --git a/checkstyle.xml b/checkstyle.xml index 93c4236ee..a01666479 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -166,7 +166,7 @@ - + diff --git a/src/main/java/net/fabricmc/loader/FabricLoader.java b/src/main/java/net/fabricmc/loader/FabricLoader.java index 7b296355b..639dff4b6 100644 --- a/src/main/java/net/fabricmc/loader/FabricLoader.java +++ b/src/main/java/net/fabricmc/loader/FabricLoader.java @@ -16,504 +16,40 @@ package net.fabricmc.loader; -import java.io.BufferedReader; import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.objectweb.asm.Opcodes; - -import net.fabricmc.accesswidener.AccessWidener; -import net.fabricmc.accesswidener.AccessWidenerReader; -import net.fabricmc.api.EnvType; -import net.fabricmc.loader.api.LanguageAdapter; -import net.fabricmc.loader.api.MappingResolver; -import net.fabricmc.loader.api.SemanticVersion; -import net.fabricmc.loader.api.entrypoint.EntrypointContainer; -import net.fabricmc.loader.discovery.ClasspathModCandidateFinder; -import net.fabricmc.loader.discovery.DirectoryModCandidateFinder; -import net.fabricmc.loader.discovery.ModCandidate; -import net.fabricmc.loader.discovery.ModResolutionException; -import net.fabricmc.loader.discovery.ModResolver; -import net.fabricmc.loader.discovery.RuntimeModRemapper; -import net.fabricmc.loader.game.GameProvider; -import net.fabricmc.loader.gui.FabricGuiEntry; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.launch.knot.Knot; -import net.fabricmc.loader.metadata.DependencyOverrides; -import net.fabricmc.loader.metadata.EntrypointMetadata; -import net.fabricmc.loader.metadata.LoaderModMetadata; -import net.fabricmc.loader.util.DefaultLanguageAdapter; -import net.fabricmc.loader.util.SystemProperties; +import net.fabricmc.loader.impl.FabricLoaderImpl; /** * The main class for mod loading operations. + * + * @deprecated Use {@link net.fabricmc.loader.api.FabricLoader} */ -public class FabricLoader implements net.fabricmc.loader.api.FabricLoader { +@Deprecated +public abstract class FabricLoader implements net.fabricmc.loader.api.FabricLoader { /** * @deprecated Use {@link net.fabricmc.loader.api.FabricLoader#getInstance()} where possible, * report missing areas as an issue. */ @Deprecated - public static final FabricLoader INSTANCE = new FabricLoader(); - - public static final int ASM_VERSION = Opcodes.ASM9; - - protected static Logger LOGGER = LogManager.getFormatterLogger("Fabric|Loader"); - - protected final Map modMap = new HashMap<>(); - protected List mods = new ArrayList<>(); - - private final Map adapterMap = new HashMap<>(); - private final EntrypointStorage entrypointStorage = new EntrypointStorage(); - private final AccessWidener accessWidener = new AccessWidener(); - - private boolean frozen = false; - - private Object gameInstance; - - private MappingResolver mappingResolver; - private GameProvider provider; - private Path gameDir; - private Path configDir; - - protected FabricLoader() { - } - - /** - * Freeze the FabricLoader, preventing additional mods from being loaded. - */ - public void freeze() { - if (frozen) { - throw new RuntimeException("Already frozen!"); - } - - frozen = true; - finishModLoading(); - } - - public GameProvider getGameProvider() { - if (provider == null) throw new IllegalStateException("game provider not set (yet)"); - - return provider; - } - - public void setGameProvider(GameProvider provider) { - this.provider = provider; - - setGameDir(provider.getLaunchDirectory()); - } - - private void setGameDir(Path gameDir) { - this.gameDir = gameDir; - this.configDir = gameDir.resolve("config"); - } - - @Override - public Object getGameInstance() { - return gameInstance; - } - - @Override - public EnvType getEnvironmentType() { - return FabricLauncherBase.getLauncher().getEnvironmentType(); - } - - /** - * @return The game instance's root directory. - */ - @Override - public Path getGameDir() { - return gameDir; - } - - @Override - @Deprecated - public File getGameDirectory() { - return getGameDir().toFile(); - } - - /** - * @return The game instance's configuration directory. - */ - @Override - public Path getConfigDir() { - if (!Files.exists(configDir)) { - try { - Files.createDirectories(configDir); - } catch (IOException e) { - throw new RuntimeException("Creating config directory", e); - } - } - - return configDir; - } - - @Override - @Deprecated - public File getConfigDirectory() { - return getConfigDir().toFile(); - } + public static final FabricLoader INSTANCE = FabricLoaderImpl.InitHelper.get(); - public Path getModsDir() { - return getGameDir().resolve("mods"); - } - - @Deprecated public File getModsDirectory() { - return getModsDir().toFile(); - } - - public void load() { - if (provider == null) throw new IllegalStateException("game provider not set"); - if (frozen) throw new IllegalStateException("Frozen - cannot load additional mods!"); - - try { - setup(); - } catch (ModResolutionException exception) { - FabricGuiEntry.displayCriticalError(exception, true); - } - } - - private void setup() throws ModResolutionException { - ModResolver resolver = new ModResolver(); - resolver.addCandidateFinder(new ClasspathModCandidateFinder()); - resolver.addCandidateFinder(new DirectoryModCandidateFinder(getModsDir(), isDevelopmentEnvironment())); - Map candidateMap = resolver.resolve(this); - - String modListText = candidateMap.values().stream() - .sorted(Comparator.comparing(candidate -> candidate.getInfo().getId())) - .map(candidate -> String.format("\t- %s@%s", candidate.getInfo().getId(), candidate.getInfo().getVersion().getFriendlyString())) - .collect(Collectors.joining("\n")); - - String modText; - switch (candidateMap.values().size()) { - case 0: - modText = "Loading %d mods"; - break; - case 1: - modText = "Loading %d mod:"; - break; - default: - modText = "Loading %d mods:"; - break; - } - - LOGGER.info("[%s] " + modText + "%n%s", getClass().getSimpleName(), candidateMap.values().size(), modListText); - - if (DependencyOverrides.INSTANCE.getDependencyOverrides().size() > 0) { - LOGGER.info(String.format("Dependencies overridden for \"%s\"", String.join(", ", DependencyOverrides.INSTANCE.getDependencyOverrides().keySet()))); - } - - boolean runtimeModRemapping = isDevelopmentEnvironment(); - - if (runtimeModRemapping && System.getProperty(SystemProperties.REMAP_CLASSPATH_FILE) == null) { - LOGGER.warn("Runtime mod remapping disabled due to no fabric.remapClasspathFile being specified. You may need to update loom."); - runtimeModRemapping = false; - } - - if (runtimeModRemapping) { - for (ModCandidate candidate : RuntimeModRemapper.remap(candidateMap.values(), ModResolver.getInMemoryFs())) { - addMod(candidate); - } - } else { - for (ModCandidate candidate : candidateMap.values()) { - addMod(candidate); - } - } - } - - protected void finishModLoading() { - // add mods to classpath - // TODO: This can probably be made safer, but that's a long-term goal - for (ModContainer mod : mods) { - if (!mod.getInfo().getId().equals("fabricloader") && !mod.getInfo().getType().equals("builtin")) { - FabricLauncherBase.getLauncher().propose(mod.getOriginUrl()); - } - } - - postprocessModMetadata(); - setupLanguageAdapters(); - setupMods(); - } - - public boolean hasEntrypoints(String key) { - return entrypointStorage.hasEntrypoints(key); - } - - @Override - public List getEntrypoints(String key, Class type) { - return entrypointStorage.getEntrypoints(key, type); + return getGameDir().resolve("mods").toFile(); } @Override - public List> getEntrypointContainers(String key, Class type) { - return entrypointStorage.getEntrypointContainers(key, type); - } - - @Override - public MappingResolver getMappingResolver() { - if (mappingResolver == null) { - mappingResolver = new FabricMappingResolver( - FabricLauncherBase.getLauncher().getMappingConfiguration()::getMappings, - FabricLauncherBase.getLauncher().getTargetNamespace() - ); - } - - return mappingResolver; - } - - @Override - public Optional getModContainer(String id) { - return Optional.ofNullable(modMap.get(id)); - } - - @Override - public Collection getAllMods() { - return Collections.unmodifiableList(mods); - } - - @Override - public boolean isModLoaded(String id) { - return modMap.containsKey(id); - } + public abstract List getEntrypoints(String key, Class type); - @Override - public boolean isDevelopmentEnvironment() { - return FabricLauncherBase.getLauncher().isDevelopment(); - } - - /** - * @return A list of all loaded mods, as ModContainers. - * @deprecated Use {@link net.fabricmc.loader.api.FabricLoader#getAllMods()} - */ - @Deprecated + @SuppressWarnings({ "unchecked", "rawtypes" }) public Collection getModContainers() { - return Collections.unmodifiableList(mods); + return (Collection) getAllMods(); } - @Deprecated + @SuppressWarnings({ "unchecked", "rawtypes" }) public List getMods() { - return Collections.unmodifiableList(mods); - } - - protected void addMod(ModCandidate candidate) throws ModResolutionException { - LoaderModMetadata info = candidate.getInfo(); - URL originUrl = candidate.getOriginUrl(); - - if (modMap.containsKey(info.getId())) { - throw new ModResolutionException("Duplicate mod ID: " + info.getId() + "! (" + modMap.get(info.getId()).getOriginUrl().getFile() + ", " + originUrl.getFile() + ")"); - } - - if (!info.loadsInEnvironment(getEnvironmentType())) { - return; - } - - ModContainer container = new ModContainer(info, originUrl); - mods.add(container); - modMap.put(info.getId(), container); - - for (String provides : info.getProvides()) { - if (modMap.containsKey(provides)) { - throw new ModResolutionException("Duplicate provided alias: " + provides + "! (" + modMap.get(info.getId()).getOriginUrl().getFile() + ", " + originUrl.getFile() + ")"); - } - - modMap.put(provides, container); - } - } - - protected void postprocessModMetadata() { - for (ModContainer mod : mods) { - if (!(mod.getInfo().getVersion() instanceof SemanticVersion)) { - LOGGER.warn("Mod `" + mod.getInfo().getId() + "` (" + mod.getInfo().getVersion().getFriendlyString() + ") does not respect SemVer - comparison support is limited."); - } else if (((SemanticVersion) mod.getInfo().getVersion()).getVersionComponentCount() >= 4) { - LOGGER.warn("Mod `" + mod.getInfo().getId() + "` (" + mod.getInfo().getVersion().getFriendlyString() + ") uses more dot-separated version components than SemVer allows; support for this is currently not guaranteed."); - } - } - } - - /* private void sortMods() { - LOGGER.debug("Sorting mods"); - - LinkedList sorted = new LinkedList<>(); - - for (ModContainer mod : mods) { - if (sorted.isEmpty() || mod.getInfo().getRequires().size() == 0) { - sorted.addFirst(mod); - } else { - boolean b = false; - - l1: for (int i = 0; i < sorted.size(); i++) { - for (Map.Entry entry : sorted.get(i).getInfo().getRequires().entrySet()) { - String depId = entry.getKey(); - ModMetadataV0.Dependency dep = entry.getValue(); - - if (depId.equalsIgnoreCase(mod.getInfo().getId()) && dep.satisfiedBy(mod.getInfo())) { - sorted.add(i, mod); - b = true; - break l1; - } - } - } - - if (!b) { - sorted.addLast(mod); - } - } - } - - mods = sorted; - } */ - - private void setupLanguageAdapters() { - adapterMap.put("default", DefaultLanguageAdapter.INSTANCE); - - for (ModContainer mod : mods) { - // add language adapters - for (Map.Entry laEntry : mod.getInfo().getLanguageAdapterDefinitions().entrySet()) { - if (adapterMap.containsKey(laEntry.getKey())) { - throw new RuntimeException("Duplicate language adapter key: " + laEntry.getKey() + "! (" + laEntry.getValue() + ", " + adapterMap.get(laEntry.getKey()).getClass().getName() + ")"); - } - - try { - adapterMap.put(laEntry.getKey(), (LanguageAdapter) Class.forName(laEntry.getValue(), true, FabricLauncherBase.getLauncher().getTargetClassLoader()).getDeclaredConstructor().newInstance()); - } catch (Exception e) { - throw new RuntimeException("Failed to instantiate language adapter: " + laEntry.getKey(), e); - } - } - } - } - - private void setupMods() { - for (ModContainer mod : mods) { - try { - for (String in : mod.getInfo().getOldInitializers()) { - String adapter = mod.getInfo().getOldStyleLanguageAdapter(); - entrypointStorage.addDeprecated(mod, adapter, in); - } - - for (String key : mod.getInfo().getEntrypointKeys()) { - for (EntrypointMetadata in : mod.getInfo().getEntrypoints(key)) { - entrypointStorage.add(mod, key, in, adapterMap); - } - } - } catch (Exception e) { - throw new RuntimeException(String.format("Failed to setup mod %s (%s)", mod.getInfo().getName(), mod.getOriginUrl().getFile()), e); - } - } - } - - public void loadAccessWideners() { - AccessWidenerReader accessWidenerReader = new AccessWidenerReader(accessWidener); - - for (net.fabricmc.loader.api.ModContainer modContainer : getAllMods()) { - LoaderModMetadata modMetadata = (LoaderModMetadata) modContainer.getMetadata(); - String accessWidener = modMetadata.getAccessWidener(); - - if (accessWidener != null) { - Path path = modContainer.getPath(accessWidener); - - try (BufferedReader reader = Files.newBufferedReader(path)) { - accessWidenerReader.read(reader, getMappingResolver().getCurrentRuntimeNamespace()); - } catch (Exception e) { - throw new RuntimeException("Failed to read accessWidener file from mod " + modMetadata.getId(), e); - } - } - } - } - - public void prepareModInit(Path newRunDir, Object gameInstance) { - if (!frozen) { - throw new RuntimeException("Cannot instantiate mods when not frozen!"); - } - - if (gameInstance != null && FabricLauncherBase.getLauncher() instanceof Knot) { - ClassLoader gameClassLoader = gameInstance.getClass().getClassLoader(); - ClassLoader targetClassLoader = FabricLauncherBase.getLauncher().getTargetClassLoader(); - boolean matchesKnot = (gameClassLoader == targetClassLoader); - boolean containsKnot = false; - - if (matchesKnot) { - containsKnot = true; - } else { - gameClassLoader = gameClassLoader.getParent(); - - while (gameClassLoader != null && gameClassLoader.getParent() != gameClassLoader) { - if (gameClassLoader == targetClassLoader) { - containsKnot = true; - } - - gameClassLoader = gameClassLoader.getParent(); - } - } - - if (!matchesKnot) { - if (containsKnot) { - getLogger().info("Environment: Target class loader is parent of game class loader."); - } else { - getLogger().warn("\n\n* CLASS LOADER MISMATCH! THIS IS VERY BAD AND WILL PROBABLY CAUSE WEIRD ISSUES! *\n" - + " - Expected game class loader: " + FabricLauncherBase.getLauncher().getTargetClassLoader() + "\n" - + " - Actual game class loader: " + gameClassLoader + "\n" - + "Could not find the expected class loader in game class loader parents!\n"); - } - } - } - - this.gameInstance = gameInstance; - - if (gameDir != null) { - try { - if (!gameDir.toRealPath().equals(newRunDir.toRealPath())) { - getLogger().warn("Inconsistent game execution directories: engine says " + newRunDir.toRealPath() + ", while initializer says " + gameDir.toRealPath() + "..."); - setGameDir(newRunDir); - } - } catch (IOException e) { - getLogger().warn("Exception while checking game execution directory consistency!", e); - } - } else { - setGameDir(newRunDir); - } - } - - public AccessWidener getAccessWidener() { - return accessWidener; - } - - public Logger getLogger() { - return LOGGER; - } - - /** - * Sets the game instance. This is only used in 20w22a+ by the dedicated server and should not be called by anything else. - */ - @Deprecated - public void setGameInstance(Object gameInstance) { - if (this.getEnvironmentType() != EnvType.SERVER) { - throw new UnsupportedOperationException("Cannot set game instance on a client!"); - } - - if (this.gameInstance != null) { - throw new UnsupportedOperationException("Cannot overwrite current game instance!"); - } - - this.gameInstance = gameInstance; - } - - @Override - public String[] getLaunchArguments(boolean sanitize) { - return getGameProvider().getLaunchArguments(sanitize); + return (List) getAllMods(); } } diff --git a/src/main/java/net/fabricmc/loader/ModContainer.java b/src/main/java/net/fabricmc/loader/ModContainer.java index 5e2a859c5..9ff9942b6 100644 --- a/src/main/java/net/fabricmc/loader/ModContainer.java +++ b/src/main/java/net/fabricmc/loader/ModContainer.java @@ -16,70 +16,15 @@ package net.fabricmc.loader; -import java.io.IOException; import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import net.fabricmc.loader.api.metadata.ModMetadata; import net.fabricmc.loader.metadata.LoaderModMetadata; -import net.fabricmc.loader.util.FileSystemUtil; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; -public class ModContainer implements net.fabricmc.loader.api.ModContainer { - private final LoaderModMetadata info; - private final URL originUrl; - private volatile Path root; - - public ModContainer(LoaderModMetadata info, URL originUrl) { - this.info = info; - this.originUrl = originUrl; - } - - @Override - public ModMetadata getMetadata() { - return info; - } - - @Override - public Path getRootPath() { - Path ret = root; - - if (ret == null) { - root = ret = obtainRootPath(); // obtainRootPath is thread safe, but we need to avoid plain or repeated reads to root - } - - return ret; - } - - private Path obtainRootPath() { - try { - Path holder = UrlUtil.asPath(originUrl).toAbsolutePath(); - - if (Files.isDirectory(holder)) { - return holder; - } else /* JAR */ { - FileSystemUtil.FileSystemDelegate delegate = FileSystemUtil.getJarFileSystem(holder, false); - - if (delegate.get() == null) { - throw new RuntimeException("Could not open JAR file " + holder.getFileName() + " for NIO reading!"); - } - - return delegate.get().getRootDirectories().iterator().next(); - - // We never close here. It's fine. getJarFileSystem() will handle it gracefully, and so should mods - } - } catch (IOException | UrlConversionException e) { - throw new RuntimeException("Failed to find root directory for mod '" + info.getId() + "'!", e); - } - } - - public LoaderModMetadata getInfo() { - return info; - } - - public URL getOriginUrl() { - return originUrl; - } +/** + * @deprecated Use {@link net.fabricmc.loader.api.ModContainer} instead + */ +@Deprecated +public abstract class ModContainer implements net.fabricmc.loader.api.ModContainer { + public abstract LoaderModMetadata getInfo(); + public abstract URL getOriginUrl(); } diff --git a/src/main/java/net/fabricmc/loader/api/FabricLoader.java b/src/main/java/net/fabricmc/loader/api/FabricLoader.java index a94e14048..43d0c2f2c 100644 --- a/src/main/java/net/fabricmc/loader/api/FabricLoader.java +++ b/src/main/java/net/fabricmc/loader/api/FabricLoader.java @@ -24,6 +24,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import net.fabricmc.loader.impl.FabricLoaderImpl; /** * The public-facing FabricLoader instance. @@ -36,13 +37,14 @@ public interface FabricLoader { /** * Returns the public-facing Fabric Loader instance. */ - @SuppressWarnings("deprecation") static FabricLoader getInstance() { - if (net.fabricmc.loader.FabricLoader.INSTANCE == null) { + FabricLoader ret = FabricLoaderImpl.INSTANCE; + + if (ret == null) { throw new RuntimeException("Accessed FabricLoader too early!"); } - return net.fabricmc.loader.FabricLoader.INSTANCE; + return ret; } /** diff --git a/src/main/java/net/fabricmc/loader/api/LanguageAdapter.java b/src/main/java/net/fabricmc/loader/api/LanguageAdapter.java index b7152cc4f..037622267 100644 --- a/src/main/java/net/fabricmc/loader/api/LanguageAdapter.java +++ b/src/main/java/net/fabricmc/loader/api/LanguageAdapter.java @@ -16,6 +16,8 @@ package net.fabricmc.loader.api; +import net.fabricmc.loader.impl.util.DefaultLanguageAdapter; + /** * Creates instances of objects from custom notations. * @@ -94,6 +96,13 @@ * */ public interface LanguageAdapter { + /** + * Get an instance of the default language adapter. + */ + static LanguageAdapter getDefault() { + return DefaultLanguageAdapter.INSTANCE; + } + /** * Creates an object of {@code type} from an arbitrary string declaration. * diff --git a/src/main/java/net/fabricmc/loader/api/SemanticVersion.java b/src/main/java/net/fabricmc/loader/api/SemanticVersion.java index a2e475aab..81b978a41 100644 --- a/src/main/java/net/fabricmc/loader/api/SemanticVersion.java +++ b/src/main/java/net/fabricmc/loader/api/SemanticVersion.java @@ -18,7 +18,7 @@ import java.util.Optional; -import net.fabricmc.loader.util.version.VersionDeserializer; +import net.fabricmc.loader.impl.util.version.VersionDeserializer; /** * Represents a Sematic Version. diff --git a/src/main/java/net/fabricmc/loader/api/Version.java b/src/main/java/net/fabricmc/loader/api/Version.java index c4f474651..52535ce9e 100644 --- a/src/main/java/net/fabricmc/loader/api/Version.java +++ b/src/main/java/net/fabricmc/loader/api/Version.java @@ -17,7 +17,7 @@ package net.fabricmc.loader.api; import net.fabricmc.loader.api.metadata.ModMetadata; -import net.fabricmc.loader.util.version.VersionDeserializer; +import net.fabricmc.loader.impl.util.version.VersionDeserializer; /** * Represents a version of a mod. diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointBranding.java b/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointBranding.java deleted file mode 100644 index c7cd128fe..000000000 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointBranding.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.loader.entrypoint.minecraft.hooks; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public final class EntrypointBranding { - public static final String FABRIC = "fabric"; - public static final String VANILLA = "vanilla"; - - private static final Logger LOGGER = LogManager.getLogger("Fabric|Branding"); - - private EntrypointBranding() { } - - public static String brand(final String brand) { - if (brand == null || brand.isEmpty()) { - LOGGER.warn("Null or empty branding found!", new IllegalStateException()); - return FABRIC; - } - - return VANILLA.equals(brand) ? FABRIC : brand + ',' + FABRIC; - } -} diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointClient.java b/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointClient.java deleted file mode 100644 index d1f1117a0..000000000 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointClient.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.loader.entrypoint.minecraft.hooks; - -import java.io.File; - -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.FabricLoader; - -public final class EntrypointClient { - @SuppressWarnings("deprecation") - public static void start(File runDir, Object gameInstance) { - if (runDir == null) { - runDir = new File("."); - } - - FabricLoader.INSTANCE.prepareModInit(runDir.toPath(), gameInstance); - EntrypointUtils.invoke("main", ModInitializer.class, ModInitializer::onInitialize); - EntrypointUtils.invoke("client", ClientModInitializer.class, ClientModInitializer::onInitializeClient); - } -} diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointServer.java b/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointServer.java deleted file mode 100644 index 4daaa634d..000000000 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointServer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.loader.entrypoint.minecraft.hooks; - -import java.io.File; - -import net.fabricmc.api.DedicatedServerModInitializer; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.FabricLoader; - -public final class EntrypointServer { - @SuppressWarnings("deprecation") - public static void start(File runDir, Object gameInstance) { - if (runDir == null) { - runDir = new File("."); - } - - FabricLoader.INSTANCE.prepareModInit(runDir.toPath(), gameInstance); - EntrypointUtils.invoke("main", ModInitializer.class, ModInitializer::onInitialize); - EntrypointUtils.invoke("server", DedicatedServerModInitializer.class, DedicatedServerModInitializer::onInitializeServer); - } -} diff --git a/src/main/java/net/fabricmc/loader/DependencyException.java b/src/main/java/net/fabricmc/loader/impl/DependencyException.java similarity index 97% rename from src/main/java/net/fabricmc/loader/DependencyException.java rename to src/main/java/net/fabricmc/loader/impl/DependencyException.java index 84367e6d2..9a7ee521d 100644 --- a/src/main/java/net/fabricmc/loader/DependencyException.java +++ b/src/main/java/net/fabricmc/loader/impl/DependencyException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader; +package net.fabricmc.loader.impl; @SuppressWarnings("serial") public class DependencyException extends RuntimeException { diff --git a/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java new file mode 100644 index 000000000..5f831cbb3 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java @@ -0,0 +1,501 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.objectweb.asm.Opcodes; + +import net.fabricmc.accesswidener.AccessWidener; +import net.fabricmc.accesswidener.AccessWidenerReader; +import net.fabricmc.api.EnvType; +import net.fabricmc.loader.api.LanguageAdapter; +import net.fabricmc.loader.api.MappingResolver; +import net.fabricmc.loader.api.SemanticVersion; +import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import net.fabricmc.loader.impl.discovery.ClasspathModCandidateFinder; +import net.fabricmc.loader.impl.discovery.DirectoryModCandidateFinder; +import net.fabricmc.loader.impl.discovery.ModCandidate; +import net.fabricmc.loader.impl.discovery.ModResolutionException; +import net.fabricmc.loader.impl.discovery.ModResolver; +import net.fabricmc.loader.impl.discovery.RuntimeModRemapper; +import net.fabricmc.loader.impl.entrypoint.EntrypointStorage; +import net.fabricmc.loader.impl.game.GameProvider; +import net.fabricmc.loader.impl.gui.FabricGuiEntry; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.launch.knot.Knot; +import net.fabricmc.loader.impl.metadata.DependencyOverrides; +import net.fabricmc.loader.impl.metadata.EntrypointMetadata; +import net.fabricmc.loader.impl.metadata.LoaderModMetadata; +import net.fabricmc.loader.impl.util.DefaultLanguageAdapter; +import net.fabricmc.loader.impl.util.SystemProperties; + +@SuppressWarnings("deprecation") +public final class FabricLoaderImpl extends net.fabricmc.loader.FabricLoader { + public static final FabricLoaderImpl INSTANCE = InitHelper.get(); + + public static final int ASM_VERSION = Opcodes.ASM9; + + protected static Logger LOGGER = LogManager.getFormatterLogger("Fabric|Loader"); + + protected final Map modMap = new HashMap<>(); + protected List mods = new ArrayList<>(); + + private final Map adapterMap = new HashMap<>(); + private final EntrypointStorage entrypointStorage = new EntrypointStorage(); + private final AccessWidener accessWidener = new AccessWidener(); + + private boolean frozen = false; + + private Object gameInstance; + + private MappingResolver mappingResolver; + private GameProvider provider; + private Path gameDir; + private Path configDir; + + private FabricLoaderImpl() { } + + /** + * Freeze the FabricLoader, preventing additional mods from being loaded. + */ + public void freeze() { + if (frozen) { + throw new RuntimeException("Already frozen!"); + } + + frozen = true; + finishModLoading(); + } + + public GameProvider getGameProvider() { + if (provider == null) throw new IllegalStateException("game provider not set (yet)"); + + return provider; + } + + public void setGameProvider(GameProvider provider) { + this.provider = provider; + + setGameDir(provider.getLaunchDirectory()); + } + + private void setGameDir(Path gameDir) { + this.gameDir = gameDir; + this.configDir = gameDir.resolve("config"); + } + + @Override + public Object getGameInstance() { + return gameInstance; + } + + @Override + public EnvType getEnvironmentType() { + return FabricLauncherBase.getLauncher().getEnvironmentType(); + } + + /** + * @return The game instance's root directory. + */ + @Override + public Path getGameDir() { + return gameDir; + } + + @Override + @Deprecated + public File getGameDirectory() { + return getGameDir().toFile(); + } + + /** + * @return The game instance's configuration directory. + */ + @Override + public Path getConfigDir() { + if (!Files.exists(configDir)) { + try { + Files.createDirectories(configDir); + } catch (IOException e) { + throw new RuntimeException("Creating config directory", e); + } + } + + return configDir; + } + + @Override + @Deprecated + public File getConfigDirectory() { + return getConfigDir().toFile(); + } + + public void load() { + if (provider == null) throw new IllegalStateException("game provider not set"); + if (frozen) throw new IllegalStateException("Frozen - cannot load additional mods!"); + + try { + setup(); + } catch (ModResolutionException exception) { + FabricGuiEntry.displayCriticalError(exception, true); + } + } + + private void setup() throws ModResolutionException { + ModResolver resolver = new ModResolver(); + resolver.addCandidateFinder(new ClasspathModCandidateFinder()); + resolver.addCandidateFinder(new DirectoryModCandidateFinder(gameDir.resolve("mods"), isDevelopmentEnvironment())); + Map candidateMap = resolver.resolve(this); + + String modListText = candidateMap.values().stream() + .sorted(Comparator.comparing(candidate -> candidate.getInfo().getId())) + .map(candidate -> String.format("\t- %s@%s", candidate.getInfo().getId(), candidate.getInfo().getVersion().getFriendlyString())) + .collect(Collectors.joining("\n")); + + String modText; + switch (candidateMap.values().size()) { + case 0: + modText = "Loading %d mods"; + break; + case 1: + modText = "Loading %d mod:"; + break; + default: + modText = "Loading %d mods:"; + break; + } + + LOGGER.info("[%s] " + modText + "%n%s", getClass().getSimpleName(), candidateMap.values().size(), modListText); + + if (DependencyOverrides.INSTANCE.getDependencyOverrides().size() > 0) { + LOGGER.info(String.format("Dependencies overridden for \"%s\"", String.join(", ", DependencyOverrides.INSTANCE.getDependencyOverrides().keySet()))); + } + + boolean runtimeModRemapping = isDevelopmentEnvironment(); + + if (runtimeModRemapping && System.getProperty(SystemProperties.REMAP_CLASSPATH_FILE) == null) { + LOGGER.warn("Runtime mod remapping disabled due to no fabric.remapClasspathFile being specified. You may need to update loom."); + runtimeModRemapping = false; + } + + if (runtimeModRemapping) { + for (ModCandidate candidate : RuntimeModRemapper.remap(candidateMap.values(), ModResolver.getInMemoryFs())) { + addMod(candidate); + } + } else { + for (ModCandidate candidate : candidateMap.values()) { + addMod(candidate); + } + } + } + + private void finishModLoading() { + // add mods to classpath + // TODO: This can probably be made safer, but that's a long-term goal + for (ModContainerImpl mod : mods) { + if (!mod.getInfo().getId().equals("fabricloader") && !mod.getInfo().getType().equals("builtin")) { + FabricLauncherBase.getLauncher().propose(mod.getOriginUrl()); + } + } + + postprocessModMetadata(); + setupLanguageAdapters(); + setupMods(); + } + + public boolean hasEntrypoints(String key) { + return entrypointStorage.hasEntrypoints(key); + } + + @Override + public List getEntrypoints(String key, Class type) { + return entrypointStorage.getEntrypoints(key, type); + } + + @Override + public List> getEntrypointContainers(String key, Class type) { + return entrypointStorage.getEntrypointContainers(key, type); + } + + @Override + public MappingResolver getMappingResolver() { + if (mappingResolver == null) { + mappingResolver = new MappingResolverImpl( + FabricLauncherBase.getLauncher().getMappingConfiguration()::getMappings, + FabricLauncherBase.getLauncher().getTargetNamespace() + ); + } + + return mappingResolver; + } + + @Override + public Optional getModContainer(String id) { + return Optional.ofNullable(modMap.get(id)); + } + + @Override + public Collection getAllMods() { + return Collections.unmodifiableList(mods); + } + + @Override + public boolean isModLoaded(String id) { + return modMap.containsKey(id); + } + + @Override + public boolean isDevelopmentEnvironment() { + return FabricLauncherBase.getLauncher().isDevelopment(); + } + + protected void addMod(ModCandidate candidate) throws ModResolutionException { + LoaderModMetadata info = candidate.getInfo(); + URL originUrl = candidate.getOriginUrl(); + + if (modMap.containsKey(info.getId())) { + throw new ModResolutionException("Duplicate mod ID: " + info.getId() + "! (" + modMap.get(info.getId()).getOriginUrl().getFile() + ", " + originUrl.getFile() + ")"); + } + + if (!info.loadsInEnvironment(getEnvironmentType())) { + return; + } + + ModContainerImpl container = new ModContainerImpl(info, originUrl); + mods.add(container); + modMap.put(info.getId(), container); + + for (String provides : info.getProvides()) { + if (modMap.containsKey(provides)) { + throw new ModResolutionException("Duplicate provided alias: " + provides + "! (" + modMap.get(info.getId()).getOriginUrl().getFile() + ", " + originUrl.getFile() + ")"); + } + + modMap.put(provides, container); + } + } + + protected void postprocessModMetadata() { + for (ModContainerImpl mod : mods) { + if (!(mod.getInfo().getVersion() instanceof SemanticVersion)) { + LOGGER.warn("Mod `" + mod.getInfo().getId() + "` (" + mod.getInfo().getVersion().getFriendlyString() + ") does not respect SemVer - comparison support is limited."); + } else if (((SemanticVersion) mod.getInfo().getVersion()).getVersionComponentCount() >= 4) { + LOGGER.warn("Mod `" + mod.getInfo().getId() + "` (" + mod.getInfo().getVersion().getFriendlyString() + ") uses more dot-separated version components than SemVer allows; support for this is currently not guaranteed."); + } + } + } + + /* private void sortMods() { + LOGGER.debug("Sorting mods"); + + LinkedList sorted = new LinkedList<>(); + + for (ModContainer mod : mods) { + if (sorted.isEmpty() || mod.getInfo().getRequires().size() == 0) { + sorted.addFirst(mod); + } else { + boolean b = false; + + l1: for (int i = 0; i < sorted.size(); i++) { + for (Map.Entry entry : sorted.get(i).getInfo().getRequires().entrySet()) { + String depId = entry.getKey(); + ModMetadataV0.Dependency dep = entry.getValue(); + + if (depId.equalsIgnoreCase(mod.getInfo().getId()) && dep.satisfiedBy(mod.getInfo())) { + sorted.add(i, mod); + b = true; + break l1; + } + } + } + + if (!b) { + sorted.addLast(mod); + } + } + } + + mods = sorted; + } */ + + private void setupLanguageAdapters() { + adapterMap.put("default", DefaultLanguageAdapter.INSTANCE); + + for (ModContainerImpl mod : mods) { + // add language adapters + for (Map.Entry laEntry : mod.getInfo().getLanguageAdapterDefinitions().entrySet()) { + if (adapterMap.containsKey(laEntry.getKey())) { + throw new RuntimeException("Duplicate language adapter key: " + laEntry.getKey() + "! (" + laEntry.getValue() + ", " + adapterMap.get(laEntry.getKey()).getClass().getName() + ")"); + } + + try { + adapterMap.put(laEntry.getKey(), (LanguageAdapter) Class.forName(laEntry.getValue(), true, FabricLauncherBase.getLauncher().getTargetClassLoader()).getDeclaredConstructor().newInstance()); + } catch (Exception e) { + throw new RuntimeException("Failed to instantiate language adapter: " + laEntry.getKey(), e); + } + } + } + } + + private void setupMods() { + for (ModContainerImpl mod : mods) { + try { + for (String in : mod.getInfo().getOldInitializers()) { + String adapter = mod.getInfo().getOldStyleLanguageAdapter(); + entrypointStorage.addDeprecated(mod, adapter, in); + } + + for (String key : mod.getInfo().getEntrypointKeys()) { + for (EntrypointMetadata in : mod.getInfo().getEntrypoints(key)) { + entrypointStorage.add(mod, key, in, adapterMap); + } + } + } catch (Exception e) { + throw new RuntimeException(String.format("Failed to setup mod %s (%s)", mod.getInfo().getName(), mod.getOriginUrl().getFile()), e); + } + } + } + + public void loadAccessWideners() { + AccessWidenerReader accessWidenerReader = new AccessWidenerReader(accessWidener); + + for (net.fabricmc.loader.api.ModContainer modContainer : getAllMods()) { + LoaderModMetadata modMetadata = (LoaderModMetadata) modContainer.getMetadata(); + String accessWidener = modMetadata.getAccessWidener(); + + if (accessWidener != null) { + Path path = modContainer.getPath(accessWidener); + + try (BufferedReader reader = Files.newBufferedReader(path)) { + accessWidenerReader.read(reader, getMappingResolver().getCurrentRuntimeNamespace()); + } catch (Exception e) { + throw new RuntimeException("Failed to read accessWidener file from mod " + modMetadata.getId(), e); + } + } + } + } + + public void prepareModInit(Path newRunDir, Object gameInstance) { + if (!frozen) { + throw new RuntimeException("Cannot instantiate mods when not frozen!"); + } + + if (gameInstance != null && FabricLauncherBase.getLauncher() instanceof Knot) { + ClassLoader gameClassLoader = gameInstance.getClass().getClassLoader(); + ClassLoader targetClassLoader = FabricLauncherBase.getLauncher().getTargetClassLoader(); + boolean matchesKnot = (gameClassLoader == targetClassLoader); + boolean containsKnot = false; + + if (matchesKnot) { + containsKnot = true; + } else { + gameClassLoader = gameClassLoader.getParent(); + + while (gameClassLoader != null && gameClassLoader.getParent() != gameClassLoader) { + if (gameClassLoader == targetClassLoader) { + containsKnot = true; + } + + gameClassLoader = gameClassLoader.getParent(); + } + } + + if (!matchesKnot) { + if (containsKnot) { + getLogger().info("Environment: Target class loader is parent of game class loader."); + } else { + getLogger().warn("\n\n* CLASS LOADER MISMATCH! THIS IS VERY BAD AND WILL PROBABLY CAUSE WEIRD ISSUES! *\n" + + " - Expected game class loader: " + FabricLauncherBase.getLauncher().getTargetClassLoader() + "\n" + + " - Actual game class loader: " + gameClassLoader + "\n" + + "Could not find the expected class loader in game class loader parents!\n"); + } + } + } + + this.gameInstance = gameInstance; + + if (gameDir != null) { + try { + if (!gameDir.toRealPath().equals(newRunDir.toRealPath())) { + getLogger().warn("Inconsistent game execution directories: engine says " + newRunDir.toRealPath() + ", while initializer says " + gameDir.toRealPath() + "..."); + setGameDir(newRunDir); + } + } catch (IOException e) { + getLogger().warn("Exception while checking game execution directory consistency!", e); + } + } else { + setGameDir(newRunDir); + } + } + + public AccessWidener getAccessWidener() { + return accessWidener; + } + + public Logger getLogger() { + return LOGGER; + } + + /** + * Sets the game instance. This is only used in 20w22a+ by the dedicated server and should not be called by anything else. + */ + public void setGameInstance(Object gameInstance) { + if (getEnvironmentType() != EnvType.SERVER) { + throw new UnsupportedOperationException("Cannot set game instance on a client!"); + } + + if (this.gameInstance != null) { + throw new UnsupportedOperationException("Cannot overwrite current game instance!"); + } + + this.gameInstance = gameInstance; + } + + @Override + public String[] getLaunchArguments(boolean sanitize) { + return getGameProvider().getLaunchArguments(sanitize); + } + + /** + * Provides singleton for static init assignment regardless of load order. + */ + public static class InitHelper { + private static FabricLoaderImpl instance; + + public static FabricLoaderImpl get() { + if (instance == null) instance = new FabricLoaderImpl(); + + return instance; + } + } +} diff --git a/src/main/java/net/fabricmc/loader/FabricMappingResolver.java b/src/main/java/net/fabricmc/loader/impl/MappingResolverImpl.java similarity index 94% rename from src/main/java/net/fabricmc/loader/FabricMappingResolver.java rename to src/main/java/net/fabricmc/loader/impl/MappingResolverImpl.java index 9962c64d3..f1407bb8c 100644 --- a/src/main/java/net/fabricmc/loader/FabricMappingResolver.java +++ b/src/main/java/net/fabricmc/loader/impl/MappingResolverImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader; +package net.fabricmc.loader.impl; import java.util.Collection; import java.util.Collections; @@ -30,7 +30,7 @@ import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.mappings.EntryTriple; -class FabricMappingResolver implements MappingResolver { +class MappingResolverImpl implements MappingResolver { private final Supplier mappingsSupplier; private final Set namespaces; private final Map namespaceDataMap = new HashMap<>(); @@ -43,7 +43,7 @@ private static class NamespaceData { private final Map methodNames = new HashMap<>(); } - FabricMappingResolver(Supplier mappingsSupplier, String targetNamespace) { + MappingResolverImpl(Supplier mappingsSupplier, String targetNamespace) { this.mappingsSupplier = mappingsSupplier; this.targetNamespace = targetNamespace; namespaces = Collections.unmodifiableSet(new HashSet<>(mappingsSupplier.get().getMetadata().getNamespaces())); @@ -81,7 +81,7 @@ private static String replaceSlashesWithDots(String cname) { } private String mapClassName(Map classNameMap, String s) { - return classNameMap.computeIfAbsent(s, FabricMappingResolver::replaceSlashesWithDots); + return classNameMap.computeIfAbsent(s, MappingResolverImpl::replaceSlashesWithDots); } private void recordMember(String fromNamespace, Collection descriptoredList, Map putInto, String fromClass) { diff --git a/src/main/java/net/fabricmc/loader/impl/ModContainerImpl.java b/src/main/java/net/fabricmc/loader/impl/ModContainerImpl.java new file mode 100644 index 000000000..8b4e7481c --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/ModContainerImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl; + +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; + +import net.fabricmc.loader.api.metadata.ModMetadata; +import net.fabricmc.loader.impl.metadata.LoaderModMetadata; +import net.fabricmc.loader.impl.util.FileSystemUtil; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; + +@SuppressWarnings("deprecation") +public class ModContainerImpl extends net.fabricmc.loader.ModContainer { + private final LoaderModMetadata info; + private final URL originUrl; + private volatile Path root; + + public ModContainerImpl(LoaderModMetadata info, URL originUrl) { + this.info = info; + this.originUrl = originUrl; + } + + @Override + public ModMetadata getMetadata() { + return info; + } + + @Override + public Path getRootPath() { + Path ret = root; + + if (ret == null) { + root = ret = obtainRootPath(); // obtainRootPath is thread safe, but we need to avoid plain or repeated reads to root + } + + return ret; + } + + private Path obtainRootPath() { + try { + Path holder = UrlUtil.asPath(originUrl).toAbsolutePath(); + + if (Files.isDirectory(holder)) { + return holder; + } else /* JAR */ { + FileSystemUtil.FileSystemDelegate delegate = FileSystemUtil.getJarFileSystem(holder, false); + + if (delegate.get() == null) { + throw new RuntimeException("Could not open JAR file " + holder.getFileName() + " for NIO reading!"); + } + + return delegate.get().getRootDirectories().iterator().next(); + + // We never close here. It's fine. getJarFileSystem() will handle it gracefully, and so should mods + } + } catch (IOException | UrlConversionException e) { + throw new RuntimeException("Failed to find root directory for mod '" + info.getId() + "'!", e); + } + } + + @Override + public LoaderModMetadata getInfo() { + return info; + } + + @Override + public URL getOriginUrl() { + return originUrl; + } +} diff --git a/src/main/java/net/fabricmc/loader/discovery/BuiltinMetadataWrapper.java b/src/main/java/net/fabricmc/loader/impl/discovery/BuiltinMetadataWrapper.java similarity index 93% rename from src/main/java/net/fabricmc/loader/discovery/BuiltinMetadataWrapper.java rename to src/main/java/net/fabricmc/loader/impl/discovery/BuiltinMetadataWrapper.java index dfb1346b9..4304d6bcc 100644 --- a/src/main/java/net/fabricmc/loader/discovery/BuiltinMetadataWrapper.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/BuiltinMetadataWrapper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import java.util.Collection; import java.util.Collections; @@ -32,10 +32,10 @@ import net.fabricmc.loader.api.metadata.ModEnvironment; import net.fabricmc.loader.api.metadata.ModMetadata; import net.fabricmc.loader.api.metadata.Person; -import net.fabricmc.loader.metadata.AbstractModMetadata; -import net.fabricmc.loader.metadata.EntrypointMetadata; -import net.fabricmc.loader.metadata.LoaderModMetadata; -import net.fabricmc.loader.metadata.NestedJarEntry; +import net.fabricmc.loader.impl.metadata.AbstractModMetadata; +import net.fabricmc.loader.impl.metadata.EntrypointMetadata; +import net.fabricmc.loader.impl.metadata.LoaderModMetadata; +import net.fabricmc.loader.impl.metadata.NestedJarEntry; class BuiltinMetadataWrapper extends AbstractModMetadata implements LoaderModMetadata { private final ModMetadata parent; diff --git a/src/main/java/net/fabricmc/loader/discovery/ClasspathModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/ClasspathModCandidateFinder.java similarity index 89% rename from src/main/java/net/fabricmc/loader/discovery/ClasspathModCandidateFinder.java rename to src/main/java/net/fabricmc/loader/impl/discovery/ClasspathModCandidateFinder.java index 60611bc38..8b8b6dcc5 100644 --- a/src/main/java/net/fabricmc/loader/discovery/ClasspathModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ClasspathModCandidateFinder.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import java.io.File; import java.io.IOException; @@ -25,15 +25,14 @@ import java.util.function.BiConsumer; import java.util.stream.Stream; -import net.fabricmc.loader.FabricLoader; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; public class ClasspathModCandidateFinder implements ModCandidateFinder { - @SuppressWarnings("deprecation") @Override - public void findCandidates(FabricLoader loader, BiConsumer appender) { + public void findCandidates(FabricLoaderImpl loader, BiConsumer appender) { Stream urls; URL fabricCodeSource; @@ -82,7 +81,7 @@ public void findCandidates(FabricLoader loader, BiConsumer appende // Fabric being supposedly uninitialized. // This heuristic could probably be better, but I doubt that any sane // mod would include a second FabricLoader. - if (!FabricLoader.INSTANCE.isDevelopmentEnvironment() || !url.equals(fabricCodeSource)) { + if (!FabricLoaderImpl.INSTANCE.isDevelopmentEnvironment() || !url.equals(fabricCodeSource)) { FabricLauncherBase.getLauncher().propose(url); } } diff --git a/src/main/java/net/fabricmc/loader/discovery/DirectoryModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java similarity index 90% rename from src/main/java/net/fabricmc/loader/discovery/DirectoryModCandidateFinder.java rename to src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java index ae5eb99f6..426c172f3 100644 --- a/src/main/java/net/fabricmc/loader/discovery/DirectoryModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import java.io.IOException; import java.net.URL; @@ -27,9 +27,9 @@ import java.util.EnumSet; import java.util.function.BiConsumer; -import net.fabricmc.loader.FabricLoader; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; public class DirectoryModCandidateFinder implements ModCandidateFinder { private final Path path; @@ -41,7 +41,7 @@ public DirectoryModCandidateFinder(Path path, boolean requiresRemap) { } @Override - public void findCandidates(FabricLoader loader, BiConsumer urlProposer) { + public void findCandidates(FabricLoaderImpl loader, BiConsumer urlProposer) { if (!Files.exists(path)) { try { Files.createDirectory(path); diff --git a/src/main/java/net/fabricmc/loader/discovery/ModCandidate.java b/src/main/java/net/fabricmc/loader/impl/discovery/ModCandidate.java similarity index 94% rename from src/main/java/net/fabricmc/loader/discovery/ModCandidate.java rename to src/main/java/net/fabricmc/loader/impl/discovery/ModCandidate.java index 8ed3216ff..6046b451c 100644 --- a/src/main/java/net/fabricmc/loader/discovery/ModCandidate.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ModCandidate.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import java.net.URL; -import net.fabricmc.loader.metadata.LoaderModMetadata; +import net.fabricmc.loader.impl.metadata.LoaderModMetadata; public class ModCandidate { private final LoaderModMetadata info; diff --git a/src/main/java/net/fabricmc/loader/discovery/ModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/ModCandidateFinder.java similarity index 80% rename from src/main/java/net/fabricmc/loader/discovery/ModCandidateFinder.java rename to src/main/java/net/fabricmc/loader/impl/discovery/ModCandidateFinder.java index fb4948aa0..59fd9bd2b 100644 --- a/src/main/java/net/fabricmc/loader/discovery/ModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ModCandidateFinder.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import java.net.URL; import java.util.function.BiConsumer; -import net.fabricmc.loader.FabricLoader; +import net.fabricmc.loader.impl.FabricLoaderImpl; @FunctionalInterface public interface ModCandidateFinder { - void findCandidates(FabricLoader loader, BiConsumer urlProposer); + void findCandidates(FabricLoaderImpl loader, BiConsumer urlProposer); } diff --git a/src/main/java/net/fabricmc/loader/discovery/ModCandidateSet.java b/src/main/java/net/fabricmc/loader/impl/discovery/ModCandidateSet.java similarity index 98% rename from src/main/java/net/fabricmc/loader/discovery/ModCandidateSet.java rename to src/main/java/net/fabricmc/loader/impl/discovery/ModCandidateSet.java index 6021630e2..e7cf7f4f6 100644 --- a/src/main/java/net/fabricmc/loader/discovery/ModCandidateSet.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ModCandidateSet.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/net/fabricmc/loader/discovery/ModResolutionException.java b/src/main/java/net/fabricmc/loader/impl/discovery/ModResolutionException.java similarity index 95% rename from src/main/java/net/fabricmc/loader/discovery/ModResolutionException.java rename to src/main/java/net/fabricmc/loader/impl/discovery/ModResolutionException.java index 123bd2ae4..107baf4b5 100644 --- a/src/main/java/net/fabricmc/loader/discovery/ModResolutionException.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ModResolutionException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; @SuppressWarnings("serial") public class ModResolutionException extends Exception { diff --git a/src/main/java/net/fabricmc/loader/discovery/ModResolver.java b/src/main/java/net/fabricmc/loader/impl/discovery/ModResolver.java similarity index 96% rename from src/main/java/net/fabricmc/loader/discovery/ModResolver.java rename to src/main/java/net/fabricmc/loader/impl/discovery/ModResolver.java index b857dd528..a344de6a5 100644 --- a/src/main/java/net/fabricmc/loader/discovery/ModResolver.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ModResolver.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import static com.google.common.jimfs.Feature.FILE_CHANNEL; import static com.google.common.jimfs.Feature.SECURE_DIRECTORY_STREAM; @@ -53,20 +53,20 @@ import com.google.common.jimfs.PathType; import org.apache.logging.log4j.Logger; -import net.fabricmc.loader.FabricLoader; import net.fabricmc.loader.api.Version; import net.fabricmc.loader.api.metadata.ModDependency; -import net.fabricmc.loader.game.GameProvider.BuiltinMod; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.lib.gson.MalformedJsonException; -import net.fabricmc.loader.metadata.BuiltinModMetadata; -import net.fabricmc.loader.metadata.LoaderModMetadata; -import net.fabricmc.loader.metadata.ModMetadataParser; -import net.fabricmc.loader.metadata.NestedJarEntry; -import net.fabricmc.loader.metadata.ParseMetadataException; -import net.fabricmc.loader.util.FileSystemUtil; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.game.GameProvider.BuiltinMod; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.lib.gson.MalformedJsonException; +import net.fabricmc.loader.impl.metadata.BuiltinModMetadata; +import net.fabricmc.loader.impl.metadata.LoaderModMetadata; +import net.fabricmc.loader.impl.metadata.ModMetadataParser; +import net.fabricmc.loader.impl.metadata.NestedJarEntry; +import net.fabricmc.loader.impl.metadata.ParseMetadataException; +import net.fabricmc.loader.impl.util.FileSystemUtil; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; import net.fabricmc.loader.util.sat4j.core.VecInt; import net.fabricmc.loader.util.sat4j.minisat.SolverFactory; import net.fabricmc.loader.util.sat4j.specs.ContradictionException; @@ -345,7 +345,6 @@ public Map findCompatibleSet(Logger logger, Map result, StringBuilder errors, String errorType, boolean cond) { String depModId = dependency.getModId(); @@ -368,7 +367,7 @@ private void addErrorToList(Logger logger, ModCandidate candidate, ModDependency if (depCandidate == null) { for (ModCandidate value : result.values()) { if (value.getInfo().getProvides().contains(depModId)) { - if (FabricLoader.INSTANCE.isDevelopmentEnvironment()) { + if (FabricLoaderImpl.INSTANCE.isDevelopmentEnvironment()) { logger.warn("Mod " + candidate.getInfo().getId() + " is using the provided alias " + depModId + " in place of the real mod id " + value.getInfo().getId() + ". Please use the mod id instead of a provided alias."); } @@ -589,13 +588,13 @@ private static boolean isModIdValid(String modId, List errorList) { @SuppressWarnings("serial") static class UrlProcessAction extends RecursiveAction { - private final FabricLoader loader; + private final FabricLoaderImpl loader; private final Map candidatesById; private final URL url; private final int depth; private final boolean requiresRemap; - UrlProcessAction(FabricLoader loader, Map candidatesById, URL url, int depth, boolean requiresRemap) { + UrlProcessAction(FabricLoaderImpl loader, Map candidatesById, URL url, int depth, boolean requiresRemap) { this.loader = loader; this.candidatesById = candidatesById; this.url = url; @@ -762,7 +761,7 @@ protected void compute() { } } - public Map resolve(FabricLoader loader) throws ModResolutionException { + public Map resolve(FabricLoaderImpl loader) throws ModResolutionException { ConcurrentMap candidatesById = new ConcurrentHashMap<>(); long time1 = System.currentTimeMillis(); diff --git a/src/main/java/net/fabricmc/loader/discovery/RuntimeModRemapper.java b/src/main/java/net/fabricmc/loader/impl/discovery/RuntimeModRemapper.java similarity index 93% rename from src/main/java/net/fabricmc/loader/discovery/RuntimeModRemapper.java rename to src/main/java/net/fabricmc/loader/impl/discovery/RuntimeModRemapper.java index 10851d74d..55db381e2 100644 --- a/src/main/java/net/fabricmc/loader/discovery/RuntimeModRemapper.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/RuntimeModRemapper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.discovery; +package net.fabricmc.loader.impl.discovery; import java.io.BufferedReader; import java.io.ByteArrayInputStream; @@ -43,13 +43,13 @@ import net.fabricmc.accesswidener.AccessWidenerReader; import net.fabricmc.accesswidener.AccessWidenerRemapper; import net.fabricmc.accesswidener.AccessWidenerWriter; -import net.fabricmc.loader.launch.common.FabricLauncher; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.util.FileSystemUtil; -import net.fabricmc.loader.util.SystemProperties; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; -import net.fabricmc.loader.util.mappings.TinyRemapperMappingsHelper; +import net.fabricmc.loader.impl.launch.FabricLauncher; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.util.FileSystemUtil; +import net.fabricmc.loader.impl.util.SystemProperties; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; +import net.fabricmc.loader.impl.util.mappings.TinyRemapperMappingsHelper; import net.fabricmc.tinyremapper.InputTag; import net.fabricmc.tinyremapper.NonClassCopyMode; import net.fabricmc.tinyremapper.OutputConsumerPath; diff --git a/src/main/java/net/fabricmc/loader/entrypoint/EntrypointContainerImpl.java b/src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointContainerImpl.java similarity index 57% rename from src/main/java/net/fabricmc/loader/entrypoint/EntrypointContainerImpl.java rename to src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointContainerImpl.java index a94843304..fd73c7297 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/EntrypointContainerImpl.java +++ b/src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointContainerImpl.java @@ -14,27 +14,33 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint; - -import java.util.function.Supplier; +package net.fabricmc.loader.impl.entrypoint; +import net.fabricmc.loader.api.EntrypointException; import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; -public class EntrypointContainerImpl implements EntrypointContainer { - private final ModContainer container; - private final Supplier entrypointSupplier; +public final class EntrypointContainerImpl implements EntrypointContainer { + private final String key; + private final Class type; + private final EntrypointStorage.Entry entry; private T instance; - public EntrypointContainerImpl(ModContainer container, Supplier entrypointSupplier) { - this.container = container; - this.entrypointSupplier = entrypointSupplier; + public EntrypointContainerImpl(String key, Class type, EntrypointStorage.Entry entry) { + this.key = key; + this.type = type; + this.entry = entry; } + @SuppressWarnings("deprecation") @Override public synchronized T getEntrypoint() { if (instance == null) { - this.instance = entrypointSupplier.get(); + try { + instance = entry.getOrCreate(type); + } catch (Exception ex) { + throw new EntrypointException(key, getProvider().getMetadata().getId(), ex); + } } return instance; @@ -42,6 +48,6 @@ public synchronized T getEntrypoint() { @Override public ModContainer getProvider() { - return container; + return entry.getModContainer(); } } diff --git a/src/main/java/net/fabricmc/loader/EntrypointStorage.java b/src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointStorage.java similarity index 68% rename from src/main/java/net/fabricmc/loader/EntrypointStorage.java rename to src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointStorage.java index 22894476b..03883a85c 100644 --- a/src/main/java/net/fabricmc/loader/EntrypointStorage.java +++ b/src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointStorage.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package net.fabricmc.loader; +package net.fabricmc.loader.impl.entrypoint; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; @@ -26,15 +27,16 @@ import net.fabricmc.loader.api.LanguageAdapter; import net.fabricmc.loader.api.LanguageAdapterException; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; -import net.fabricmc.loader.entrypoint.EntrypointContainerImpl; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.metadata.EntrypointMetadata; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.ModContainerImpl; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.metadata.EntrypointMetadata; -class EntrypointStorage { +public final class EntrypointStorage { interface Entry { T getOrCreate(Class type) throws Exception; - ModContainer getModContainer(); + ModContainerImpl getModContainer(); } @SuppressWarnings("deprecation") @@ -43,12 +45,12 @@ private static class OldEntry implements Entry { .missingSuperclassBehaviour(net.fabricmc.loader.language.LanguageAdapter.MissingSuperclassBehavior.RETURN_NULL) .build(); - private final ModContainer mod; + private final ModContainerImpl mod; private final String languageAdapter; private final String value; private Object object; - private OldEntry(ModContainer mod, String languageAdapter, String value) { + private OldEntry(ModContainerImpl mod, String languageAdapter, String value) { this.mod = mod; this.languageAdapter = languageAdapter; this.value = value; @@ -61,7 +63,7 @@ public String toString() { @SuppressWarnings({ "unchecked" }) @Override - public T getOrCreate(Class type) throws Exception { + public synchronized T getOrCreate(Class type) throws Exception { if (object == null) { net.fabricmc.loader.language.LanguageAdapter adapter = (net.fabricmc.loader.language.LanguageAdapter) Class.forName(languageAdapter, true, FabricLauncherBase.getLauncher().getTargetClassLoader()).getConstructor().newInstance(); object = adapter.createInstance(value, options); @@ -75,22 +77,22 @@ public T getOrCreate(Class type) throws Exception { } @Override - public ModContainer getModContainer() { + public ModContainerImpl getModContainer() { return mod; } } private static final class NewEntry implements Entry { - private final ModContainer mod; + private final ModContainerImpl mod; private final LanguageAdapter adapter; private final String value; private final Map, Object> instanceMap; - NewEntry(ModContainer mod, LanguageAdapter adapter, String value) { + NewEntry(ModContainerImpl mod, LanguageAdapter adapter, String value) { this.mod = mod; this.adapter = adapter; this.value = value; - this.instanceMap = new HashMap<>(1); + this.instanceMap = new IdentityHashMap<>(1); } @Override @@ -100,18 +102,21 @@ public String toString() { @SuppressWarnings("unchecked") @Override - public T getOrCreate(Class type) throws Exception { - return (T) instanceMap.computeIfAbsent(type, t -> { - try { - return adapter.create(mod, value, t); - } catch (LanguageAdapterException ex) { - throw sneakyThrows(ex); - } - }); + public synchronized T getOrCreate(Class type) throws Exception { + // this impl allows reentrancy (unlike computeIfAbsent) + T ret = (T) instanceMap.get(type); + + if (ret == null) { + ret = adapter.create(mod, value, type); + T prev = (T) instanceMap.putIfAbsent(type, ret); + if (prev != null) ret = prev; + } + + return ret; } @Override - public ModContainer getModContainer() { + public ModContainerImpl getModContainer() { return mod; } } @@ -122,33 +127,31 @@ private List getOrCreateEntries(String key) { return entryMap.computeIfAbsent(key, (z) -> new ArrayList<>()); } - @SuppressWarnings("deprecation") - protected void addDeprecated(ModContainer modContainer, String adapter, String value) throws ClassNotFoundException, LanguageAdapterException { - FabricLoader.INSTANCE.getLogger().debug("Registering 0.3.x old-style initializer " + value + " for mod " + modContainer.getInfo().getId()); + public void addDeprecated(ModContainerImpl modContainer, String adapter, String value) throws ClassNotFoundException, LanguageAdapterException { + FabricLoaderImpl.INSTANCE.getLogger().debug("Registering 0.3.x old-style initializer " + value + " for mod " + modContainer.getInfo().getId()); OldEntry oe = new OldEntry(modContainer, adapter, value); getOrCreateEntries("main").add(oe); getOrCreateEntries("client").add(oe); getOrCreateEntries("server").add(oe); } - @SuppressWarnings("deprecation") - protected void add(ModContainer modContainer, String key, EntrypointMetadata metadata, Map adapterMap) throws Exception { + public void add(ModContainerImpl modContainer, String key, EntrypointMetadata metadata, Map adapterMap) throws Exception { if (!adapterMap.containsKey(metadata.getAdapter())) { throw new Exception("Could not find adapter '" + metadata.getAdapter() + "' (mod " + modContainer.getInfo().getId() + "!)"); } - FabricLoader.INSTANCE.getLogger().debug("Registering new-style initializer " + metadata.getValue() + " for mod " + modContainer.getInfo().getId() + " (key " + key + ")"); + FabricLoaderImpl.INSTANCE.getLogger().debug("Registering new-style initializer " + metadata.getValue() + " for mod " + modContainer.getInfo().getId() + " (key " + key + ")"); getOrCreateEntries(key).add(new NewEntry( modContainer, adapterMap.get(metadata.getAdapter()), metadata.getValue() )); } - boolean hasEntrypoints(String key) { + public boolean hasEntrypoints(String key) { return entryMap.containsKey(key); } @SuppressWarnings("deprecation") - protected List getEntrypoints(String key, Class type) { + public List getEntrypoints(String key, Class type) { List entries = entryMap.get(key); if (entries == null) return Collections.emptyList(); @@ -178,21 +181,14 @@ protected List getEntrypoints(String key, Class type) { return results; } - @SuppressWarnings("deprecation") - protected List> getEntrypointContainers(String key, Class type) { + public List> getEntrypointContainers(String key, Class type) { List entries = entryMap.get(key); if (entries == null) return Collections.emptyList(); List> results = new ArrayList<>(entries.size()); for (Entry entry : entries) { - results.add(new EntrypointContainerImpl<>(entry.getModContainer(), () -> { - try { - return entry.getOrCreate(type); - } catch (Exception ex) { - throw new EntrypointException(key, entry.getModContainer().getMetadata().getId(), ex); - } - })); + results.add(new EntrypointContainerImpl<>(key, type, entry)); } return results; diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointUtils.java b/src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointUtils.java similarity index 87% rename from src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointUtils.java rename to src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointUtils.java index f96e3b5e4..88e13d670 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointUtils.java +++ b/src/main/java/net/fabricmc/loader/impl/entrypoint/EntrypointUtils.java @@ -14,18 +14,17 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.minecraft.hooks; +package net.fabricmc.loader.impl.entrypoint; import java.util.Collection; import java.util.function.Consumer; -import net.fabricmc.loader.FabricLoader; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import net.fabricmc.loader.impl.FabricLoaderImpl; public final class EntrypointUtils { public static void invoke(String name, Class type, Consumer invoker) { - @SuppressWarnings("deprecation") - FabricLoader loader = FabricLoader.INSTANCE; + FabricLoaderImpl loader = FabricLoaderImpl.INSTANCE; if (!loader.hasEntrypoints(name)) { loader.getLogger().debug("No subscribers for entrypoint '" + name + "'"); @@ -35,8 +34,7 @@ public static void invoke(String name, Class type, Consumer in } private static void invoke0(String name, Class type, Consumer invoker) { - @SuppressWarnings("deprecation") - FabricLoader loader = FabricLoader.INSTANCE; + FabricLoaderImpl loader = FabricLoaderImpl.INSTANCE; RuntimeException exception = null; Collection> entrypoints = loader.getEntrypointContainers(name, type); diff --git a/src/main/java/net/fabricmc/loader/game/GameProvider.java b/src/main/java/net/fabricmc/loader/impl/game/GameProvider.java similarity index 91% rename from src/main/java/net/fabricmc/loader/game/GameProvider.java rename to src/main/java/net/fabricmc/loader/impl/game/GameProvider.java index 8ddbed8cb..5dc405bb7 100644 --- a/src/main/java/net/fabricmc/loader/game/GameProvider.java +++ b/src/main/java/net/fabricmc/loader/impl/game/GameProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.game; +package net.fabricmc.loader.impl.game; import java.net.URL; import java.nio.file.Path; @@ -23,7 +23,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.metadata.ModMetadata; -import net.fabricmc.loader.entrypoint.EntrypointTransformer; +import net.fabricmc.loader.impl.game.patch.GameTransformer; public interface GameProvider { String getGameId(); @@ -39,7 +39,7 @@ public interface GameProvider { List getGameContextJars(); boolean locateGame(EnvType envType, String[] args, ClassLoader loader); - EntrypointTransformer getEntrypointTransformer(); + GameTransformer getEntrypointTransformer(); void launch(ClassLoader loader); String[] getLaunchArguments(boolean sanitize); diff --git a/src/main/java/net/fabricmc/loader/game/GameProviderHelper.java b/src/main/java/net/fabricmc/loader/impl/game/GameProviderHelper.java similarity index 85% rename from src/main/java/net/fabricmc/loader/game/GameProviderHelper.java rename to src/main/java/net/fabricmc/loader/impl/game/GameProviderHelper.java index 732a2a9cf..15eb73080 100644 --- a/src/main/java/net/fabricmc/loader/game/GameProviderHelper.java +++ b/src/main/java/net/fabricmc/loader/impl/game/GameProviderHelper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.game; +package net.fabricmc.loader.impl.game; import java.io.IOException; import java.net.URL; @@ -26,10 +26,10 @@ import java.util.Optional; import java.util.stream.Collectors; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; -final class GameProviderHelper { +public final class GameProviderHelper { public static class EntrypointResult { public final String entrypointName; public final Path entrypointPath; @@ -42,7 +42,7 @@ public static class EntrypointResult { private GameProviderHelper() { } - static Optional getSource(ClassLoader loader, String filename) { + public static Optional getSource(ClassLoader loader, String filename) { URL url; if ((url = loader.getResource(filename)) != null) { @@ -60,7 +60,7 @@ static Optional getSource(ClassLoader loader, String filename) { return Optional.empty(); } - static List getSources(ClassLoader loader, String filename) { + public static List getSources(ClassLoader loader, String filename) { try { Enumeration urls = loader.getResources(filename); List paths = new ArrayList<>(); @@ -84,7 +84,7 @@ static List getSources(ClassLoader loader, String filename) { } } - static Optional findFirstClass(ClassLoader loader, List classNames) { + public static Optional findFirstClass(ClassLoader loader, List classNames) { List entrypointFilenames = classNames.stream() .map((ep) -> ep.replace('.', '/') + ".class") .collect(Collectors.toList()); diff --git a/src/main/java/net/fabricmc/loader/game/GameProviders.java b/src/main/java/net/fabricmc/loader/impl/game/GameProviders.java similarity index 88% rename from src/main/java/net/fabricmc/loader/game/GameProviders.java rename to src/main/java/net/fabricmc/loader/impl/game/GameProviders.java index 9237fd5e0..13b2c6c97 100644 --- a/src/main/java/net/fabricmc/loader/game/GameProviders.java +++ b/src/main/java/net/fabricmc/loader/impl/game/GameProviders.java @@ -14,11 +14,13 @@ * limitations under the License. */ -package net.fabricmc.loader.game; +package net.fabricmc.loader.impl.game; import java.util.Collections; import java.util.List; +import net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider; + public final class GameProviders { private GameProviders() { } diff --git a/src/main/java/net/fabricmc/loader/impl/game/minecraft/Hooks.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/Hooks.java new file mode 100644 index 000000000..5a10f1004 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/Hooks.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.game.minecraft; + +import java.io.File; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.DedicatedServerModInitializer; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.entrypoint.EntrypointUtils; + +public final class Hooks { + public static final String INTERNAL_NAME = Hooks.class.getName().replace('.', '/'); + + public static String appletMainClass; + + public static final String FABRIC = "fabric"; + public static final String VANILLA = "vanilla"; + + private static final Logger LOGGER = LogManager.getLogger("Fabric|Branding"); + + public static String insertBranding(final String brand) { + if (brand == null || brand.isEmpty()) { + LOGGER.warn("Null or empty branding found!", new IllegalStateException()); + return FABRIC; + } + + return VANILLA.equals(brand) ? FABRIC : brand + ',' + FABRIC; + } + + public static void startClient(File runDir, Object gameInstance) { + if (runDir == null) { + runDir = new File("."); + } + + FabricLoaderImpl.INSTANCE.prepareModInit(runDir.toPath(), gameInstance); + EntrypointUtils.invoke("main", ModInitializer.class, ModInitializer::onInitialize); + EntrypointUtils.invoke("client", ClientModInitializer.class, ClientModInitializer::onInitializeClient); + } + + public static void startServer(File runDir, Object gameInstance) { + if (runDir == null) { + runDir = new File("."); + } + + FabricLoaderImpl.INSTANCE.prepareModInit(runDir.toPath(), gameInstance); + EntrypointUtils.invoke("main", ModInitializer.class, ModInitializer::onInitialize); + EntrypointUtils.invoke("server", DedicatedServerModInitializer.class, DedicatedServerModInitializer::onInitializeServer); + } + + public static void setGameInstance(Object gameInstance) { + FabricLoaderImpl.INSTANCE.setGameInstance(gameInstance); + } +} diff --git a/src/main/java/net/fabricmc/loader/minecraft/McVersion.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/McVersion.java similarity index 98% rename from src/main/java/net/fabricmc/loader/minecraft/McVersion.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/McVersion.java index f29b6e72d..70a35c924 100644 --- a/src/main/java/net/fabricmc/loader/minecraft/McVersion.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/McVersion.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.minecraft; +package net.fabricmc.loader.impl.game.minecraft; import java.util.OptionalInt; diff --git a/src/main/java/net/fabricmc/loader/minecraft/McVersionLookup.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/McVersionLookup.java similarity index 96% rename from src/main/java/net/fabricmc/loader/minecraft/McVersionLookup.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/McVersionLookup.java index f7ab833a9..04f71a700 100644 --- a/src/main/java/net/fabricmc/loader/minecraft/McVersionLookup.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/McVersionLookup.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.minecraft; +package net.fabricmc.loader.impl.game.minecraft; import java.io.DataInputStream; import java.io.IOException; @@ -36,16 +36,15 @@ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; -import net.fabricmc.loader.FabricLoader; -import net.fabricmc.loader.lib.gson.JsonReader; -import net.fabricmc.loader.lib.gson.JsonToken; -import net.fabricmc.loader.metadata.ParseMetadataException; -import net.fabricmc.loader.util.FileSystemUtil; -import net.fabricmc.loader.util.version.SemanticVersionImpl; -import net.fabricmc.loader.util.version.SemanticVersionPredicateParser; -import net.fabricmc.loader.util.version.VersionParsingException; +import net.fabricmc.loader.api.VersionParsingException; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.lib.gson.JsonReader; +import net.fabricmc.loader.impl.lib.gson.JsonToken; +import net.fabricmc.loader.impl.metadata.ParseMetadataException; +import net.fabricmc.loader.impl.util.FileSystemUtil; +import net.fabricmc.loader.impl.util.version.SemanticVersionImpl; +import net.fabricmc.loader.impl.util.version.SemanticVersionPredicateParser; -@SuppressWarnings("deprecation") public final class McVersionLookup { private static final Pattern VERSION_PATTERN = Pattern.compile( "0\\.\\d+(\\.\\d+)?a?(_\\d+)?|" // match classic versions first: 0.1.2a_34 @@ -466,7 +465,7 @@ private interface Analyzer { private static final class FieldStringConstantVisitor extends ClassVisitor implements Analyzer { FieldStringConstantVisitor(String fieldName) { - super(FabricLoader.ASM_VERSION); + super(FabricLoaderImpl.ASM_VERSION); this.fieldName = fieldName; } @@ -537,7 +536,7 @@ protected void visitAnyInsn() { private static final class MethodStringConstantContainsVisitor extends ClassVisitor implements Analyzer { MethodStringConstantContainsVisitor(String methodOwner, String methodName) { - super(FabricLoader.ASM_VERSION); + super(FabricLoaderImpl.ASM_VERSION); this.methodOwner = methodOwner; this.methodName = methodName; @@ -592,7 +591,7 @@ protected void visitAnyInsn() { private static final class MethodConstantRetVisitor extends ClassVisitor implements Analyzer { MethodConstantRetVisitor(String methodName) { - super(FabricLoader.ASM_VERSION); + super(FabricLoaderImpl.ASM_VERSION); this.methodName = methodName; } @@ -650,7 +649,7 @@ protected void visitAnyInsn() { private static final class MethodConstantVisitor extends ClassVisitor implements Analyzer { MethodConstantVisitor(String methodNameHint) { - super(FabricLoader.ASM_VERSION); + super(FabricLoaderImpl.ASM_VERSION); this.methodNameHint = methodNameHint; } @@ -668,7 +667,7 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str return null; } - return new MethodVisitor(FabricLoader.ASM_VERSION) { + return new MethodVisitor(FabricLoaderImpl.ASM_VERSION) { @Override public void visitLdcInsn(Object value) { String str; @@ -690,7 +689,7 @@ && isProbableVersion(str = (String) value)) { private abstract static class InsnFwdMethodVisitor extends MethodVisitor { InsnFwdMethodVisitor() { - super(FabricLoader.ASM_VERSION); + super(FabricLoaderImpl.ASM_VERSION); } protected abstract void visitAnyInsn(); diff --git a/src/main/java/net/fabricmc/loader/game/MinecraftGameProvider.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java similarity index 84% rename from src/main/java/net/fabricmc/loader/game/MinecraftGameProvider.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java index 63059007a..7ccab0cf2 100644 --- a/src/main/java/net/fabricmc/loader/game/MinecraftGameProvider.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.game; +package net.fabricmc.loader.impl.game.minecraft; import java.io.File; import java.lang.reflect.Method; @@ -30,17 +30,17 @@ import java.util.Optional; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.entrypoint.EntrypointTransformer; -import net.fabricmc.loader.entrypoint.minecraft.EntrypointPatchBranding; -import net.fabricmc.loader.entrypoint.minecraft.EntrypointPatchFML125; -import net.fabricmc.loader.entrypoint.minecraft.EntrypointPatchHook; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.metadata.BuiltinModMetadata; -import net.fabricmc.loader.metadata.ModDependencyImpl; -import net.fabricmc.loader.minecraft.McVersion; -import net.fabricmc.loader.minecraft.McVersionLookup; -import net.fabricmc.loader.util.Arguments; -import net.fabricmc.loader.util.SystemProperties; +import net.fabricmc.loader.impl.game.GameProvider; +import net.fabricmc.loader.impl.game.GameProviderHelper; +import net.fabricmc.loader.impl.game.minecraft.patch.BrandingPatch; +import net.fabricmc.loader.impl.game.minecraft.patch.EntrypointPatch; +import net.fabricmc.loader.impl.game.minecraft.patch.EntrypointPatchFML125; +import net.fabricmc.loader.impl.game.patch.GameTransformer; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.metadata.BuiltinModMetadata; +import net.fabricmc.loader.impl.metadata.ModDependencyImpl; +import net.fabricmc.loader.impl.util.Arguments; +import net.fabricmc.loader.impl.util.SystemProperties; public class MinecraftGameProvider implements GameProvider { private EnvType envType; @@ -50,9 +50,9 @@ public class MinecraftGameProvider implements GameProvider { private McVersion versionData; private boolean hasModLoader = false; - public static final EntrypointTransformer TRANSFORMER = new EntrypointTransformer(it -> Arrays.asList( - new EntrypointPatchHook(it), - new EntrypointPatchBranding(it), + public static final GameTransformer TRANSFORMER = new GameTransformer(it -> Arrays.asList( + new EntrypointPatch(it), + new BrandingPatch(it), new EntrypointPatchFML125(it) )); @@ -201,7 +201,7 @@ public String[] getLaunchArguments(boolean sanitize) { } @Override - public EntrypointTransformer getEntrypointTransformer() { + public GameTransformer getEntrypointTransformer() { return TRANSFORMER; } @@ -225,7 +225,7 @@ public void launch(ClassLoader loader) { String targetClass = entrypoint; if (envType == EnvType.CLIENT && targetClass.contains("Applet")) { - targetClass = "net.fabricmc.loader.entrypoint.applet.AppletMain"; + targetClass = "net.fabricmc.loader.impl.game.minecraft.entrypoint.applet.AppletMain"; } try { diff --git a/src/main/java/net/fabricmc/loader/launch/FabricClassTransformer.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricClassTransformer.java similarity index 87% rename from src/main/java/net/fabricmc/loader/launch/FabricClassTransformer.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricClassTransformer.java index 33e177cec..d2903ffac 100644 --- a/src/main/java/net/fabricmc/loader/launch/FabricClassTransformer.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricClassTransformer.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package net.fabricmc.loader.launch; +package net.fabricmc.loader.impl.game.minecraft.launchwrapper; import net.minecraft.launchwrapper.IClassTransformer; -import net.fabricmc.loader.transformer.FabricTransformer; +import net.fabricmc.loader.impl.transformer.FabricTransformer; public class FabricClassTransformer implements IClassTransformer { @Override diff --git a/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricClientTweaker.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricClientTweaker.java new file mode 100644 index 000000000..c9c49c8b0 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricClientTweaker.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.game.minecraft.launchwrapper; + +import net.fabricmc.api.EnvType; + +public class FabricClientTweaker extends FabricTweaker { + @Override + public EnvType getEnvironmentType() { + return EnvType.CLIENT; + } + + @Override + public String getLaunchTarget() { + return "net.minecraft.client.main.Main"; + } +} diff --git a/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricServerTweaker.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricServerTweaker.java new file mode 100644 index 000000000..88bfe87bf --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricServerTweaker.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.game.minecraft.launchwrapper; + +import net.fabricmc.api.EnvType; + +public class FabricServerTweaker extends FabricTweaker { + @Override + public EnvType getEnvironmentType() { + return EnvType.SERVER; + } + + @Override + public String getLaunchTarget() { + return "net.minecraft.server.MinecraftServer"; + } +} diff --git a/src/main/java/net/fabricmc/loader/launch/FabricTweaker.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricTweaker.java similarity index 90% rename from src/main/java/net/fabricmc/loader/launch/FabricTweaker.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricTweaker.java index f8b9f1ab6..0cfd16d87 100644 --- a/src/main/java/net/fabricmc/loader/launch/FabricTweaker.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/launchwrapper/FabricTweaker.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch; +package net.fabricmc.loader.impl.game.minecraft.launchwrapper; import java.io.ByteArrayOutputStream; import java.io.File; @@ -43,17 +43,17 @@ import net.minecraft.launchwrapper.LaunchClassLoader; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.FabricLoader; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; -import net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils; -import net.fabricmc.loader.game.GameProvider; -import net.fabricmc.loader.game.MinecraftGameProvider; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.launch.common.FabricMixinBootstrap; -import net.fabricmc.loader.util.Arguments; -import net.fabricmc.loader.util.SystemProperties; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.entrypoint.EntrypointUtils; +import net.fabricmc.loader.impl.game.GameProvider; +import net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.launch.FabricMixinBootstrap; +import net.fabricmc.loader.impl.util.Arguments; +import net.fabricmc.loader.impl.util.SystemProperties; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; public abstract class FabricTweaker extends FabricLauncherBase implements ITweaker { protected static Logger LOGGER = LogManager.getFormatterLogger("Fabric|Tweaker"); @@ -91,7 +91,6 @@ public void acceptOptions(List localArgs, File gameDir, File assetsDir, FabricLauncherBase.processArgumentMap(arguments, getEnvironmentType()); } - @SuppressWarnings("deprecation") @Override public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) { isDevelopment = Boolean.parseBoolean(System.getProperty(SystemProperties.DEVELOPMENT, "false")); @@ -118,12 +117,12 @@ public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) { throw new RuntimeException("Could not locate Minecraft: provider locate failed"); } - FabricLoader loader = FabricLoader.INSTANCE; + FabricLoaderImpl loader = FabricLoaderImpl.INSTANCE; loader.setGameProvider(provider); loader.load(); loader.freeze(); - launchClassLoader.registerTransformer("net.fabricmc.loader.launch.FabricClassTransformer"); + launchClassLoader.registerTransformer(FabricClassTransformer.class.getName()); if (!isDevelopment) { // Obfuscated environment @@ -150,13 +149,13 @@ public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) { } } - FabricLoader.INSTANCE.loadAccessWideners(); + FabricLoaderImpl.INSTANCE.loadAccessWideners(); MinecraftGameProvider.TRANSFORMER.locateEntrypoints(this); // Setup Mixin environment MixinBootstrap.init(); - FabricMixinBootstrap.init(getEnvironmentType(), FabricLoader.INSTANCE); + FabricMixinBootstrap.init(getEnvironmentType(), FabricLoaderImpl.INSTANCE); MixinEnvironment.getDefaultEnvironment().setSide(getEnvironmentType() == EnvType.CLIENT ? MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER); EntrypointUtils.invoke("preLaunch", PreLaunchEntrypoint.class, PreLaunchEntrypoint::onPreLaunch); diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchBranding.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/BrandingPatch.java similarity index 78% rename from src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchBranding.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/BrandingPatch.java index 9e4bafec4..9dea2f22d 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchBranding.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/BrandingPatch.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.minecraft; +package net.fabricmc.loader.impl.game.minecraft.patch; import java.io.IOException; import java.util.ListIterator; @@ -26,12 +26,13 @@ import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; -import net.fabricmc.loader.entrypoint.EntrypointPatch; -import net.fabricmc.loader.entrypoint.EntrypointTransformer; -import net.fabricmc.loader.launch.common.FabricLauncher; +import net.fabricmc.loader.impl.game.minecraft.Hooks; +import net.fabricmc.loader.impl.game.patch.GamePatch; +import net.fabricmc.loader.impl.game.patch.GameTransformer; +import net.fabricmc.loader.impl.launch.FabricLauncher; -public final class EntrypointPatchBranding extends EntrypointPatch { - public EntrypointPatchBranding(EntrypointTransformer transformer) { +public final class BrandingPatch extends GamePatch { + public BrandingPatch(GameTransformer transformer) { super(transformer); } @@ -67,7 +68,7 @@ private boolean applyBrandingPatch(ClassNode classNode) { while (it.hasNext()) { if (it.next().getOpcode() == Opcodes.ARETURN) { it.previous(); - it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointBranding", "brand", "(Ljava/lang/String;)Ljava/lang/String;", false)); + it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Hooks.INTERNAL_NAME, "insertBranding", "(Ljava/lang/String;)Ljava/lang/String;", false)); it.next(); } } diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchHook.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/EntrypointPatch.java similarity index 93% rename from src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchHook.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/EntrypointPatch.java index dfdf4d45d..06168e9b5 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchHook.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/EntrypointPatch.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.minecraft; +package net.fabricmc.loader.impl.game.minecraft.patch; import java.io.IOException; import java.util.List; @@ -35,17 +35,19 @@ import org.objectweb.asm.tree.VarInsnNode; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.entrypoint.EntrypointPatch; -import net.fabricmc.loader.entrypoint.EntrypointTransformer; -import net.fabricmc.loader.launch.common.FabricLauncher; +import net.fabricmc.loader.impl.game.minecraft.Hooks; +import net.fabricmc.loader.impl.game.patch.GamePatch; +import net.fabricmc.loader.impl.game.patch.GameTransformer; +import net.fabricmc.loader.impl.launch.FabricLauncher; -public class EntrypointPatchHook extends EntrypointPatch { - public EntrypointPatchHook(EntrypointTransformer transformer) { +public class EntrypointPatch extends GamePatch { + public EntrypointPatch(GameTransformer transformer) { super(transformer); } private void finishEntrypoint(EnvType type, ListIterator it) { - it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/fabricmc/loader/entrypoint/minecraft/hooks/Entrypoint" + (type == EnvType.CLIENT ? "Client" : "Server"), "start", "(Ljava/io/File;Ljava/lang/Object;)V", false)); + String methodName = String.format("start%s", type == EnvType.CLIENT ? "Client" : "Server"); + it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Hooks.INTERNAL_NAME, methodName, "(Ljava/io/File;Ljava/lang/Object;)V", false)); } @Override @@ -357,9 +359,7 @@ public void process(FabricLauncher launcher, Consumer classEmitter) { // Duplicate dedicated server instance for loader serverStartIt.add(new InsnNode(Opcodes.DUP)); - serverStartIt.add(new FieldInsnNode(Opcodes.GETSTATIC, "net/fabricmc/loader/FabricLoader", "INSTANCE", "Lnet/fabricmc/loader/FabricLoader;")); - serverStartIt.add(new InsnNode(Opcodes.SWAP)); - serverStartIt.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/fabricmc/loader/FabricLoader", "setGameInstance", "(Ljava/lang/Object;)V", false)); + serverStartIt.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Hooks.INTERNAL_NAME, "setGameInstance", "(Ljava/lang/Object;)V", false)); } patched = true; @@ -384,12 +384,12 @@ public void process(FabricLauncher launcher, Consumer classEmitter) { moveBefore(it, Opcodes.RETURN); } - /* it.add(new TypeInsnNode(Opcodes.NEW, "java/io/File")); + /*it.add(new TypeInsnNode(Opcodes.NEW, "java/io/File")); it.add(new InsnNode(Opcodes.DUP)); it.add(new LdcInsnNode(".")); it.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/io/File", "", "(Ljava/lang/String;)V", false)); */ it.add(new InsnNode(Opcodes.ACONST_NULL)); - it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/fabricmc/loader/entrypoint/applet/AppletMain", "hookGameDir", "(Ljava/io/File;)Ljava/io/File;", false)); + it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletMain", "hookGameDir", "(Ljava/io/File;)Ljava/io/File;", false)); it.add(new VarInsnNode(Opcodes.ALOAD, 0)); finishEntrypoint(type, it); } else { @@ -397,7 +397,7 @@ public void process(FabricLauncher launcher, Consumer classEmitter) { ListIterator it = gameConstructor.instructions.iterator(); moveAfter(it, Opcodes.INVOKESPECIAL); /* Object.init */ it.add(new FieldInsnNode(Opcodes.GETSTATIC, gameClass.name, runDirectory.name, runDirectory.desc)); - it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/fabricmc/loader/entrypoint/applet/AppletMain", "hookGameDir", "(Ljava/io/File;)Ljava/io/File;", false)); + it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletMain", "hookGameDir", "(Ljava/io/File;)Ljava/io/File;", false)); it.add(new FieldInsnNode(Opcodes.PUTSTATIC, gameClass.name, runDirectory.name, runDirectory.desc)); it = gameMethod.instructions.iterator(); @@ -467,7 +467,7 @@ public void process(FabricLauncher launcher, Consumer classEmitter) { } if (isApplet) { - EntrypointTransformer.appletMainClass = entrypoint; + Hooks.appletMainClass = entrypoint; } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchFML125.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/EntrypointPatchFML125.java similarity index 75% rename from src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchFML125.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/EntrypointPatchFML125.java index 5f955d984..2783e908f 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/EntrypointPatchFML125.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/EntrypointPatchFML125.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.minecraft; +package net.fabricmc.loader.impl.game.minecraft.patch; import java.io.IOException; import java.util.function.Consumer; @@ -23,18 +23,18 @@ import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.tree.ClassNode; -import net.fabricmc.loader.entrypoint.EntrypointPatch; -import net.fabricmc.loader.entrypoint.EntrypointTransformer; -import net.fabricmc.loader.launch.common.FabricLauncher; -import net.fabricmc.loader.launch.knot.Knot; +import net.fabricmc.loader.impl.game.patch.GamePatch; +import net.fabricmc.loader.impl.game.patch.GameTransformer; +import net.fabricmc.loader.impl.launch.FabricLauncher; +import net.fabricmc.loader.impl.launch.knot.Knot; -public class EntrypointPatchFML125 extends EntrypointPatch { - private static final String FROM = "net.fabricmc.loader.entrypoint.minecraft.ModClassLoader_125_FML"; +public class EntrypointPatchFML125 extends GamePatch { + private static final String FROM = ModClassLoader_125_FML.class.getName(); private static final String TO = "cpw.mods.fml.common.ModClassLoader"; - private static final String FROM_INTERNAL = "net/fabricmc/loader/entrypoint/minecraft/ModClassLoader_125_FML"; + private static final String FROM_INTERNAL = FROM.replace('.', '/'); private static final String TO_INTERNAL = "cpw/mods/fml/common/ModClassLoader"; - public EntrypointPatchFML125(EntrypointTransformer transformer) { + public EntrypointPatchFML125(GameTransformer transformer) { super(transformer); } diff --git a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/ModClassLoader_125_FML.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/ModClassLoader_125_FML.java similarity index 92% rename from src/main/java/net/fabricmc/loader/entrypoint/minecraft/ModClassLoader_125_FML.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/ModClassLoader_125_FML.java index 7b11626c7..60ae03d69 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/minecraft/ModClassLoader_125_FML.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/ModClassLoader_125_FML.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.minecraft; +package net.fabricmc.loader.impl.game.minecraft.patch; import java.io.File; import java.io.IOException; @@ -23,9 +23,9 @@ import java.net.URLClassLoader; import java.util.Enumeration; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; /** * Wrapper class replacing pre-1.3 FML's ModClassLoader (which relies on diff --git a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletForcedShutdownListener.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletForcedShutdownListener.java similarity index 95% rename from src/main/java/net/fabricmc/loader/entrypoint/applet/AppletForcedShutdownListener.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletForcedShutdownListener.java index 1f07782a7..368b2bbc0 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletForcedShutdownListener.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletForcedShutdownListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.applet; +package net.fabricmc.loader.impl.game.minecraft.patch.applet; /** * PLEASE NOTE: diff --git a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletFrame.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletFrame.java similarity index 97% rename from src/main/java/net/fabricmc/loader/entrypoint/applet/AppletFrame.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletFrame.java index f0760642e..9cb9e9c91 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletFrame.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletFrame.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.applet; +package net.fabricmc.loader.impl.game.minecraft.patch.applet; import java.awt.Dimension; import java.awt.Frame; @@ -27,7 +27,7 @@ import javax.swing.ImageIcon; -import net.fabricmc.loader.util.Arguments; +import net.fabricmc.loader.impl.util.Arguments; /** * PLEASE NOTE: diff --git a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletLauncher.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletLauncher.java similarity index 95% rename from src/main/java/net/fabricmc/loader/entrypoint/applet/AppletLauncher.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletLauncher.java index b2296c26d..837949c44 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletLauncher.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletLauncher.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.applet; +package net.fabricmc.loader.impl.game.minecraft.patch.applet; import java.applet.Applet; import java.applet.AppletStub; @@ -27,8 +27,8 @@ import java.util.HashMap; import java.util.Map; -import net.fabricmc.loader.entrypoint.EntrypointTransformer; -import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.fabricmc.loader.impl.game.minecraft.Hooks; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; /** * PLEASE NOTE: @@ -65,7 +65,7 @@ public AppletLauncher(File instance, String username, String sessionid, String h try { mcApplet = (Applet) FabricLauncherBase.getLauncher() .getTargetClassLoader() - .loadClass(EntrypointTransformer.appletMainClass) + .loadClass(Hooks.appletMainClass) .getDeclaredConstructor() .newInstance(); diff --git a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletMain.java b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletMain.java similarity index 93% rename from src/main/java/net/fabricmc/loader/entrypoint/applet/AppletMain.java rename to src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletMain.java index c78e7be21..a461cbdb6 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/applet/AppletMain.java +++ b/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/applet/AppletMain.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint.applet; +package net.fabricmc.loader.impl.game.minecraft.patch.applet; import java.io.File; diff --git a/src/main/java/net/fabricmc/loader/entrypoint/EntrypointPatch.java b/src/main/java/net/fabricmc/loader/impl/game/patch/GamePatch.java similarity index 94% rename from src/main/java/net/fabricmc/loader/entrypoint/EntrypointPatch.java rename to src/main/java/net/fabricmc/loader/impl/game/patch/GamePatch.java index 9fa37e72a..21aed3d7b 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/EntrypointPatch.java +++ b/src/main/java/net/fabricmc/loader/impl/game/patch/GamePatch.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint; +package net.fabricmc.loader.impl.game.patch; import java.io.IOException; import java.util.List; @@ -29,12 +29,12 @@ import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.MethodNode; -import net.fabricmc.loader.launch.common.FabricLauncher; +import net.fabricmc.loader.impl.launch.FabricLauncher; -public abstract class EntrypointPatch { - private final EntrypointTransformer transformer; +public abstract class GamePatch { + private final GameTransformer transformer; - public EntrypointPatch(EntrypointTransformer transformer) { + public GamePatch(GameTransformer transformer) { this.transformer = transformer; } diff --git a/src/main/java/net/fabricmc/loader/entrypoint/EntrypointTransformer.java b/src/main/java/net/fabricmc/loader/impl/game/patch/GameTransformer.java similarity index 88% rename from src/main/java/net/fabricmc/loader/entrypoint/EntrypointTransformer.java rename to src/main/java/net/fabricmc/loader/impl/game/patch/GameTransformer.java index ee068e658..4a826dd80 100644 --- a/src/main/java/net/fabricmc/loader/entrypoint/EntrypointTransformer.java +++ b/src/main/java/net/fabricmc/loader/impl/game/patch/GameTransformer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.entrypoint; +package net.fabricmc.loader.impl.game.patch; import java.io.IOException; import java.util.HashMap; @@ -28,17 +28,15 @@ import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; -import net.fabricmc.loader.launch.common.FabricLauncher; - -public class EntrypointTransformer { - public static String appletMainClass; +import net.fabricmc.loader.impl.launch.FabricLauncher; +public class GameTransformer { public final Logger logger = LogManager.getFormatterLogger("FabricLoader|EntrypointTransformer"); - private final List patches; + private final List patches; private Map patchedClasses; private boolean entrypointsLocated = false; - public EntrypointTransformer(Function> patches) { + public GameTransformer(Function> patches) { this.patches = patches.apply(this); } diff --git a/src/main/java/net/fabricmc/loader/gui/FabricGuiEntry.java b/src/main/java/net/fabricmc/loader/impl/gui/FabricGuiEntry.java similarity index 84% rename from src/main/java/net/fabricmc/loader/gui/FabricGuiEntry.java rename to src/main/java/net/fabricmc/loader/impl/gui/FabricGuiEntry.java index 05b6e7a9f..075d58b8c 100644 --- a/src/main/java/net/fabricmc/loader/gui/FabricGuiEntry.java +++ b/src/main/java/net/fabricmc/loader/impl/gui/FabricGuiEntry.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package net.fabricmc.loader.gui; +package net.fabricmc.loader.impl.gui; import java.awt.GraphicsEnvironment; import java.util.HashSet; import java.util.Set; -import net.fabricmc.loader.FabricLoader; -import net.fabricmc.loader.game.GameProvider; -import net.fabricmc.loader.gui.FabricStatusTree.FabricStatusNode; -import net.fabricmc.loader.gui.FabricStatusTree.FabricStatusTab; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.game.GameProvider; +import net.fabricmc.loader.impl.gui.FabricStatusTree.FabricStatusNode; +import net.fabricmc.loader.impl.gui.FabricStatusTree.FabricStatusTab; /** The main entry point for all fabric-based stuff. */ public final class FabricGuiEntry { @@ -40,11 +40,10 @@ private static void openWindow(FabricStatusTree tree, boolean shouldWait) throws /** @param exitAfter If true then this will call {@link System#exit(int)} after showing the gui, otherwise this will * return normally. */ - @SuppressWarnings("deprecation") public static void displayCriticalError(Throwable exception, boolean exitAfter) { - FabricLoader.INSTANCE.getLogger().fatal("A critical error occurred", exception); + FabricLoaderImpl.INSTANCE.getLogger().fatal("A critical error occurred", exception); - GameProvider provider = FabricLoader.INSTANCE.getGameProvider(); + GameProvider provider = FabricLoaderImpl.INSTANCE.getGameProvider(); if ((provider == null || provider.canOpenErrorGui()) && !GraphicsEnvironment.isHeadless()) { FabricStatusTree tree = new FabricStatusTree(); @@ -61,7 +60,7 @@ public static void displayCriticalError(Throwable exception, boolean exitAfter) open(tree); } catch (Exception e) { if (exitAfter) { - FabricLoader.INSTANCE.getLogger().warn("Failed to open the error gui!", e); + FabricLoaderImpl.INSTANCE.getLogger().warn("Failed to open the error gui!", e); } else { throw new RuntimeException("Failed to open the error gui!", e); } diff --git a/src/main/java/net/fabricmc/loader/gui/FabricMainWindow.java b/src/main/java/net/fabricmc/loader/impl/gui/FabricMainWindow.java similarity index 97% rename from src/main/java/net/fabricmc/loader/gui/FabricMainWindow.java rename to src/main/java/net/fabricmc/loader/impl/gui/FabricMainWindow.java index e41ebe179..2473a9f2b 100644 --- a/src/main/java/net/fabricmc/loader/gui/FabricMainWindow.java +++ b/src/main/java/net/fabricmc/loader/impl/gui/FabricMainWindow.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.gui; +package net.fabricmc.loader.impl.gui; import java.awt.BorderLayout; import java.awt.Component; @@ -60,10 +60,10 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; -import net.fabricmc.loader.gui.FabricStatusTree.FabricStatusButton; -import net.fabricmc.loader.gui.FabricStatusTree.FabricStatusNode; -import net.fabricmc.loader.gui.FabricStatusTree.FabricStatusTab; -import net.fabricmc.loader.gui.FabricStatusTree.FabricTreeWarningLevel; +import net.fabricmc.loader.impl.gui.FabricStatusTree.FabricStatusButton; +import net.fabricmc.loader.impl.gui.FabricStatusTree.FabricStatusNode; +import net.fabricmc.loader.impl.gui.FabricStatusTree.FabricStatusTab; +import net.fabricmc.loader.impl.gui.FabricStatusTree.FabricTreeWarningLevel; class FabricMainWindow { static Icon missingIcon = null; diff --git a/src/main/java/net/fabricmc/loader/gui/FabricStatusTree.java b/src/main/java/net/fabricmc/loader/impl/gui/FabricStatusTree.java similarity index 99% rename from src/main/java/net/fabricmc/loader/gui/FabricStatusTree.java rename to src/main/java/net/fabricmc/loader/impl/gui/FabricStatusTree.java index 178bb8cc9..2423786b9 100644 --- a/src/main/java/net/fabricmc/loader/gui/FabricStatusTree.java +++ b/src/main/java/net/fabricmc/loader/impl/gui/FabricStatusTree.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.gui; +package net.fabricmc.loader.impl.gui; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/src/main/java/net/fabricmc/loader/gui/package-info.java b/src/main/java/net/fabricmc/loader/impl/gui/package-info.java similarity index 95% rename from src/main/java/net/fabricmc/loader/gui/package-info.java rename to src/main/java/net/fabricmc/loader/impl/gui/package-info.java index 7619e925d..b95ee014c 100644 --- a/src/main/java/net/fabricmc/loader/gui/package-info.java +++ b/src/main/java/net/fabricmc/loader/impl/gui/package-info.java @@ -19,4 +19,4 @@ * *

This could potentially be useful for showing an tree-like structure while in-game, however this usecase is rather * limited. */ -package net.fabricmc.loader.gui; +package net.fabricmc.loader.impl.gui; diff --git a/src/main/java/net/fabricmc/loader/impl/launch/FabricLauncher.java b/src/main/java/net/fabricmc/loader/impl/launch/FabricLauncher.java new file mode 100644 index 000000000..5ad6005ca --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/launch/FabricLauncher.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.launch; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Collection; + +import net.fabricmc.api.EnvType; + +public interface FabricLauncher { + MappingConfiguration getMappingConfiguration(); + + void propose(URL url); + + EnvType getEnvironmentType(); + + boolean isClassLoaded(String name); + + InputStream getResourceAsStream(String name); + + ClassLoader getTargetClassLoader(); + + /** + * Gets the byte array for a particular class. + * + * @param name The name of the class to retrieve + * @param runTransformers Whether to run all transformers except mixin on the class + */ + byte[] getClassByteArray(String name, boolean runTransformers) throws IOException; + + boolean isDevelopment(); + + String getEntrypoint(); + + String getTargetNamespace(); + + Collection getLoadTimeDependencies(); +} diff --git a/src/main/java/net/fabricmc/loader/impl/launch/FabricLauncherBase.java b/src/main/java/net/fabricmc/loader/impl/launch/FabricLauncherBase.java new file mode 100644 index 000000000..155d3c771 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/launch/FabricLauncherBase.java @@ -0,0 +1,302 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.launch; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URL; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.jar.JarFile; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.spongepowered.asm.mixin.MixinEnvironment; + +import net.fabricmc.api.EnvType; +import net.fabricmc.loader.impl.util.Arguments; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; +import net.fabricmc.loader.impl.util.mappings.TinyRemapperMappingsHelper; +import net.fabricmc.mapping.tree.TinyTree; +import net.fabricmc.tinyremapper.OutputConsumerPath; +import net.fabricmc.tinyremapper.TinyRemapper; + +public abstract class FabricLauncherBase implements FabricLauncher { + public static Path minecraftJar; + + protected static Logger LOGGER = LogManager.getFormatterLogger("FabricLoader"); + private static boolean mixinReady; + private static Map properties; + private static FabricLauncher launcher; + private static MappingConfiguration mappingConfiguration = new MappingConfiguration(); + + protected FabricLauncherBase() { + setLauncher(this); + } + + public static File getLaunchDirectory(Arguments argMap) { + return new File(argMap.getOrDefault("gameDir", ".")); + } + + public static Class getClass(String className) throws ClassNotFoundException { + return Class.forName(className, true, getLauncher().getTargetClassLoader()); + } + + @Override + public MappingConfiguration getMappingConfiguration() { + return mappingConfiguration; + } + + private static boolean emittedInfo = false; + + protected static Path deobfuscate(String gameId, String gameVersion, Path gameDir, Path jarFile, FabricLauncher launcher) { + if (!Files.exists(jarFile)) { + throw new RuntimeException("Could not locate Minecraft: " + jarFile + " not found"); + } + + LOGGER.debug("Requesting deobfuscation of " + jarFile.getFileName()); + + if (!launcher.isDevelopment()) { // in-dev is already deobfuscated + Path deobfJarDir = gameDir.resolve(".fabric").resolve("remappedJars"); + + if (!gameId.isEmpty()) { + String versionedId = gameVersion.isEmpty() ? gameId : String.format("%s-%s", gameId, gameVersion); + deobfJarDir = deobfJarDir.resolve(versionedId); + } + + String targetNamespace = mappingConfiguration.getTargetNamespace(); + // TODO: allow versioning mappings? + String deobfJarFilename = targetNamespace + "-" + jarFile.getFileName(); + Path deobfJarFile = deobfJarDir.resolve(deobfJarFilename); + Path deobfJarFileTmp = deobfJarDir.resolve(deobfJarFilename + ".tmp"); + + if (Files.exists(deobfJarFileTmp)) { // previous unfinished remap attempt + LOGGER.warn("Incomplete remapped file found! This means that the remapping process failed on the previous launch. If this persists, make sure to let us at Fabric know!"); + + try { + Files.deleteIfExists(deobfJarFile); + Files.deleteIfExists(deobfJarFileTmp); + } catch (IOException e) { + throw new RuntimeException("can't delete incompletely remapped files", e); + } + } + + TinyTree mappings; + + if (!Files.exists(deobfJarFile) + && (mappings = mappingConfiguration.getMappings()) != null + && mappings.getMetadata().getNamespaces().contains(targetNamespace)) { + LOGGER.debug("Fabric mapping file detected, applying..."); + + if (!emittedInfo) { + LOGGER.info("Fabric is preparing JARs on first launch, this may take a few seconds..."); + emittedInfo = true; + } + + try { + deobfuscate0(jarFile, deobfJarFile, deobfJarFileTmp, mappings, targetNamespace); + } catch (IOException e) { + throw new RuntimeException("error remapping game jar "+jarFile, e); + } + } + + jarFile = deobfJarFile; + } + + try { + launcher.propose(UrlUtil.asUrl(jarFile)); + } catch (UrlConversionException e) { + throw new RuntimeException(e); + } + + if (minecraftJar == null) { + minecraftJar = jarFile; + } + + return jarFile; + } + + private static void deobfuscate0(Path jarFile, Path deobfJarFile, Path deobfJarFileTmp, TinyTree mappings, String targetNamespace) throws IOException { + Files.createDirectories(deobfJarFile.getParent()); + + boolean found; + + do { + TinyRemapper remapper = TinyRemapper.newRemapper() + .withMappings(TinyRemapperMappingsHelper.create(mappings, "official", targetNamespace)) + .rebuildSourceFilenames(true) + .build(); + + Set depPaths = new HashSet<>(); + + for (URL url : launcher.getLoadTimeDependencies()) { + try { + Path path = UrlUtil.asPath(url); + + if (!Files.exists(path)) { + throw new RuntimeException("Path does not exist: " + path); + } + + if (!path.equals(jarFile)) { + depPaths.add(path); + } + } catch (UrlConversionException e) { + throw new RuntimeException("Failed to convert '" + url + "' to path!", e); + } + } + + try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(deobfJarFileTmp) + // force jar despite the .tmp extension + .assumeArchive(true) + // don't accept class names from a blacklist of dependencies that Fabric itself utilizes + // TODO: really could use a better solution, as always... + .filter(clsName -> !clsName.startsWith("com/google/common/") + && !clsName.startsWith("com/google/gson/") + && !clsName.startsWith("com/google/thirdparty/") + && !clsName.startsWith("org/apache/logging/log4j/")) + .build()) { + for (Path path : depPaths) { + LOGGER.debug("Appending '" + path + "' to remapper classpath"); + remapper.readClassPath(path); + } + + remapper.readInputs(jarFile); + remapper.apply(outputConsumer); + } finally { + remapper.finish(); + } + + // Minecraft doesn't tend to check if a ZipFileSystem is already present, + // so we clean up here. + + depPaths.add(deobfJarFileTmp); + + for (Path p : depPaths) { + try { + p.getFileSystem().close(); + } catch (Exception e) { + // pass + } + + try { + FileSystems.getFileSystem(new URI("jar:" + p.toUri())).close(); + } catch (Exception e) { + // pass + } + } + + try (JarFile jar = new JarFile(deobfJarFileTmp.toFile())) { + found = jar.stream().anyMatch((e) -> e.getName().endsWith(".class")); + } + + if (!found) { + LOGGER.error("Generated deobfuscated JAR contains no classes! Trying again..."); + Files.delete(deobfJarFileTmp); + } else { + Files.move(deobfJarFileTmp, deobfJarFile); + } + } while (!found); + + if (!Files.exists(deobfJarFile)) { + throw new RuntimeException("Remapped .JAR file does not exist after remapping! Cannot continue!"); + } + } + + public static void processArgumentMap(Arguments argMap, EnvType envType) { + switch (envType) { + case CLIENT: + if (!argMap.containsKey("accessToken")) { + argMap.put("accessToken", "FabricMC"); + } + + if (!argMap.containsKey("version")) { + argMap.put("version", "Fabric"); + } + + String versionType = ""; + + if (argMap.containsKey("versionType") && !argMap.get("versionType").equalsIgnoreCase("release")) { + versionType = argMap.get("versionType") + "/"; + } + + argMap.put("versionType", versionType + "Fabric"); + + if (!argMap.containsKey("gameDir")) { + argMap.put("gameDir", getLaunchDirectory(argMap).getAbsolutePath()); + } + + break; + case SERVER: + argMap.remove("version"); + argMap.remove("gameDir"); + argMap.remove("assetsDir"); + break; + } + } + + protected static void setProperties(Map propertiesA) { + if (properties != null && properties != propertiesA) { + throw new RuntimeException("Duplicate setProperties call!"); + } + + properties = propertiesA; + } + + private static void setLauncher(FabricLauncher launcherA) { + if (launcher != null && launcher != launcherA) { + throw new RuntimeException("Duplicate setLauncher call!"); + } + + launcher = launcherA; + } + + public static FabricLauncher getLauncher() { + return launcher; + } + + public static Map getProperties() { + return properties; + } + + protected static void finishMixinBootstrapping() { + if (mixinReady) { + throw new RuntimeException("Must not call FabricLauncherBase.finishMixinBootstrapping() twice!"); + } + + try { + Method m = MixinEnvironment.class.getDeclaredMethod("gotoPhase", MixinEnvironment.Phase.class); + m.setAccessible(true); + m.invoke(null, MixinEnvironment.Phase.INIT); + m.invoke(null, MixinEnvironment.Phase.DEFAULT); + } catch (Exception e) { + throw new RuntimeException(e); + } + + mixinReady = true; + } + + public static boolean isMixinReady() { + return mixinReady; + } +} diff --git a/src/main/java/net/fabricmc/loader/launch/common/FabricMixinBootstrap.java b/src/main/java/net/fabricmc/loader/impl/launch/FabricMixinBootstrap.java similarity index 88% rename from src/main/java/net/fabricmc/loader/launch/common/FabricMixinBootstrap.java rename to src/main/java/net/fabricmc/loader/impl/launch/FabricMixinBootstrap.java index 4dd9cc023..686644730 100644 --- a/src/main/java/net/fabricmc/loader/launch/common/FabricMixinBootstrap.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/FabricMixinBootstrap.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.common; +package net.fabricmc.loader.impl.launch; import java.util.List; import java.util.Set; @@ -27,10 +27,10 @@ import org.spongepowered.asm.mixin.Mixins; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.FabricLoader; import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.metadata.LoaderModMetadata; -import net.fabricmc.loader.util.mappings.MixinIntermediaryDevRemapper; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.metadata.LoaderModMetadata; +import net.fabricmc.loader.impl.util.mappings.MixinIntermediaryDevRemapper; import net.fabricmc.mapping.tree.TinyTree; public final class FabricMixinBootstrap { @@ -43,7 +43,7 @@ static void addConfiguration(String configuration) { Mixins.addConfiguration(configuration); } - static Set getMixinConfigs(FabricLoader loader, EnvType type) { + static Set getMixinConfigs(FabricLoaderImpl loader, EnvType type) { return loader.getAllMods().stream() .map(ModContainer::getMetadata) .filter((m) -> m instanceof LoaderModMetadata) @@ -52,7 +52,7 @@ static Set getMixinConfigs(FabricLoader loader, EnvType type) { .collect(Collectors.toSet()); } - public static void init(EnvType side, FabricLoader loader) { + public static void init(EnvType side, FabricLoaderImpl loader) { if (initialized) { throw new RuntimeException("FabricMixinBootstrap has already been initialized!"); } diff --git a/src/main/java/net/fabricmc/loader/impl/launch/MappingConfiguration.java b/src/main/java/net/fabricmc/loader/impl/launch/MappingConfiguration.java new file mode 100644 index 000000000..6c2ea88e9 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/launch/MappingConfiguration.java @@ -0,0 +1,75 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.launch; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import net.fabricmc.mapping.tree.TinyMappingFactory; +import net.fabricmc.mapping.tree.TinyTree; + +public class MappingConfiguration { + protected static Logger LOGGER = LogManager.getFormatterLogger("FabricLoader"); + + private static TinyTree mappings; + private static boolean checkedMappings; + + public TinyTree getMappings() { + if (!checkedMappings) { + InputStream mappingStream = FabricLauncherBase.class.getClassLoader().getResourceAsStream("mappings/mappings.tiny"); + + if (mappingStream != null) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(mappingStream))) { + long time = System.currentTimeMillis(); + mappings = TinyMappingFactory.loadWithDetection(reader); + LOGGER.debug("Loading mappings took " + (System.currentTimeMillis() - time) + " ms"); + } catch (IOException ee) { + ee.printStackTrace(); + } + + try { + mappingStream.close(); + } catch (IOException ee) { + ee.printStackTrace(); + } + } + + if (mappings == null) { + LOGGER.info("Mappings not present!"); + mappings = TinyMappingFactory.EMPTY_TREE; + } + + checkedMappings = true; + } + + return mappings; + } + + public String getTargetNamespace() { + return FabricLauncherBase.getLauncher().isDevelopment() ? "named" : "intermediary"; + } + + public boolean requiresPackageAccessHack() { + // TODO + return getTargetNamespace().equals("named"); + } +} diff --git a/src/main/java/net/fabricmc/loader/launch/knot/DummyClassLoader.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/DummyClassLoader.java similarity index 96% rename from src/main/java/net/fabricmc/loader/launch/knot/DummyClassLoader.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/DummyClassLoader.java index 27055b8ed..77a9da076 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/DummyClassLoader.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/DummyClassLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.io.IOException; import java.net.URL; diff --git a/src/main/java/net/fabricmc/loader/launch/knot/FabricGlobalPropertyService.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/FabricGlobalPropertyService.java similarity index 94% rename from src/main/java/net/fabricmc/loader/launch/knot/FabricGlobalPropertyService.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/FabricGlobalPropertyService.java index a0387ffa6..e8eea25cc 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/FabricGlobalPropertyService.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/FabricGlobalPropertyService.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import org.spongepowered.asm.service.IGlobalPropertyService; import org.spongepowered.asm.service.IPropertyKey; -import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; public class FabricGlobalPropertyService implements IGlobalPropertyService { @Override diff --git a/src/main/java/net/fabricmc/loader/launch/knot/Knot.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/Knot.java similarity index 86% rename from src/main/java/net/fabricmc/loader/launch/knot/Knot.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/Knot.java index 52c32543a..8526ea042 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/Knot.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/Knot.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.io.File; import java.io.IOException; @@ -33,16 +33,16 @@ import org.spongepowered.asm.launch.MixinBootstrap; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.FabricLoader; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; -import net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils; -import net.fabricmc.loader.game.GameProvider; -import net.fabricmc.loader.game.GameProviders; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.launch.common.FabricMixinBootstrap; -import net.fabricmc.loader.util.SystemProperties; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.entrypoint.EntrypointUtils; +import net.fabricmc.loader.impl.game.GameProvider; +import net.fabricmc.loader.impl.game.GameProviders; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.launch.FabricMixinBootstrap; +import net.fabricmc.loader.impl.util.SystemProperties; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; public final class Knot extends FabricLauncherBase { protected Map properties = new HashMap<>(); @@ -53,12 +53,23 @@ public final class Knot extends FabricLauncherBase { private final File gameJarFile; private GameProvider provider; + public static void launch(String[] args, EnvType type) { + String gameJarPath = System.getProperty(SystemProperties.GAME_JAR_PATH); + Knot knot = new Knot(type, gameJarPath != null ? new File(gameJarPath) : null); + ClassLoader cl = knot.init(args); + + if (knot.provider == null) { + throw new IllegalStateException("Game provider was not initialized! (Knot#init(String[]))"); + } + + knot.provider.launch(cl); + } + public Knot(EnvType type, File gameJarFile) { this.envType = type; this.gameJarFile = gameJarFile; } - @SuppressWarnings("deprecation") protected ClassLoader init(String[] args) { setProperties(properties); @@ -127,12 +138,12 @@ protected ClassLoader init(String[] args) { Thread.currentThread().setContextClassLoader(cl); - FabricLoader loader = FabricLoader.INSTANCE; + FabricLoaderImpl loader = FabricLoaderImpl.INSTANCE; loader.setGameProvider(provider); loader.load(); loader.freeze(); - FabricLoader.INSTANCE.loadAccessWideners(); + FabricLoaderImpl.INSTANCE.loadAccessWideners(); MixinBootstrap.init(); FabricMixinBootstrap.init(getEnvironmentType(), loader); @@ -145,14 +156,6 @@ protected ClassLoader init(String[] args) { return cl; } - public void launch(ClassLoader cl) { - if (this.provider == null) { - throw new IllegalStateException("Game provider was not initialized! (Knot#init(String[]))"); - } - - provider.launch(cl); - } - @Override public String getTargetNamespace() { // TODO: Won't work outside of Yarn diff --git a/src/main/java/net/fabricmc/loader/launch/knot/KnotClassDelegate.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassDelegate.java similarity index 94% rename from src/main/java/net/fabricmc/loader/launch/knot/KnotClassDelegate.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassDelegate.java index f301fa190..7f1f98fdb 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/KnotClassDelegate.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassDelegate.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -34,12 +34,12 @@ import org.spongepowered.asm.mixin.transformer.FabricMixinTransformerProxy; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.game.GameProvider; -import net.fabricmc.loader.launch.common.FabricLauncherBase; -import net.fabricmc.loader.transformer.FabricTransformer; -import net.fabricmc.loader.util.FileSystemUtil; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.game.GameProvider; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.transformer.FabricTransformer; +import net.fabricmc.loader.impl.util.FileSystemUtil; +import net.fabricmc.loader.impl.util.UrlConversionException; +import net.fabricmc.loader.impl.util.UrlUtil; class KnotClassDelegate { static class Metadata { diff --git a/src/main/java/net/fabricmc/loader/launch/knot/KnotClassLoader.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassLoader.java similarity index 98% rename from src/main/java/net/fabricmc/loader/launch/knot/KnotClassLoader.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassLoader.java index 33da693f6..ff1510bae 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/KnotClassLoader.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.io.IOException; import java.io.InputStream; @@ -25,7 +25,7 @@ import java.util.Objects; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.game.GameProvider; +import net.fabricmc.loader.impl.game.GameProvider; class KnotClassLoader extends SecureClassLoader implements KnotClassLoaderInterface { private static class DynamicURLClassLoader extends URLClassLoader { diff --git a/src/main/java/net/fabricmc/loader/launch/knot/KnotClassLoaderInterface.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassLoaderInterface.java similarity index 95% rename from src/main/java/net/fabricmc/loader/launch/knot/KnotClassLoaderInterface.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassLoaderInterface.java index 5f0e1a3d4..3aba2c007 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/KnotClassLoaderInterface.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassLoaderInterface.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClient.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClient.java new file mode 100644 index 000000000..a44b8486c --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClient.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.launch.knot; + +import net.fabricmc.api.EnvType; + +public class KnotClient { + public static void main(String[] args) { + Knot.launch(args, EnvType.CLIENT); + } +} diff --git a/src/main/java/net/fabricmc/loader/launch/knot/KnotCompatibilityClassLoader.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotCompatibilityClassLoader.java similarity index 96% rename from src/main/java/net/fabricmc/loader/launch/knot/KnotCompatibilityClassLoader.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/KnotCompatibilityClassLoader.java index e1f5c9734..a76dd3f49 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/KnotCompatibilityClassLoader.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotCompatibilityClassLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.io.IOException; import java.io.InputStream; @@ -22,7 +22,7 @@ import java.net.URLClassLoader; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.game.GameProvider; +import net.fabricmc.loader.impl.game.GameProvider; class KnotCompatibilityClassLoader extends URLClassLoader implements KnotClassLoaderInterface { private final KnotClassDelegate delegate; diff --git a/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotServer.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotServer.java new file mode 100644 index 000000000..33c1e196a --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotServer.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.launch.knot; + +import net.fabricmc.api.EnvType; + +public class KnotServer { + public static void main(String[] args) { + Knot.launch(args, EnvType.SERVER); + } +} diff --git a/src/main/java/net/fabricmc/loader/launch/knot/MixinContainerHandleMod.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinContainerHandleMod.java similarity index 95% rename from src/main/java/net/fabricmc/loader/launch/knot/MixinContainerHandleMod.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/MixinContainerHandleMod.java index 72e31d525..ff81da71b 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/MixinContainerHandleMod.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinContainerHandleMod.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/net/fabricmc/loader/launch/knot/MixinServiceKnot.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinServiceKnot.java similarity index 98% rename from src/main/java/net/fabricmc/loader/launch/knot/MixinServiceKnot.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/MixinServiceKnot.java index 91de0aac8..07617d422 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/MixinServiceKnot.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinServiceKnot.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.io.IOException; import java.io.InputStream; @@ -37,7 +37,7 @@ import org.spongepowered.asm.service.ITransformerProvider; import org.spongepowered.asm.util.ReEntranceLock; -import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; public class MixinServiceKnot implements IMixinService, IClassProvider, IClassBytecodeProvider, ITransformerProvider, IClassTracker { private final ReEntranceLock lock; diff --git a/src/main/java/net/fabricmc/loader/launch/knot/MixinServiceKnotBootstrap.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinServiceKnotBootstrap.java similarity index 89% rename from src/main/java/net/fabricmc/loader/launch/knot/MixinServiceKnotBootstrap.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/MixinServiceKnotBootstrap.java index 530bb20e1..2024e157e 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/MixinServiceKnotBootstrap.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinServiceKnotBootstrap.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import org.spongepowered.asm.service.IMixinServiceBootstrap; @@ -26,7 +26,7 @@ public String getName() { @Override public String getServiceClassName() { - return "net.fabricmc.loader.launch.knot.MixinServiceKnot"; + return "net.fabricmc.loader.impl.launch.knot.MixinServiceKnot"; } @Override diff --git a/src/main/java/net/fabricmc/loader/launch/knot/MixinStringPropertyKey.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinStringPropertyKey.java similarity index 96% rename from src/main/java/net/fabricmc/loader/launch/knot/MixinStringPropertyKey.java rename to src/main/java/net/fabricmc/loader/impl/launch/knot/MixinStringPropertyKey.java index 6eb0fb43b..39fb744cf 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/MixinStringPropertyKey.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/MixinStringPropertyKey.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.knot; +package net.fabricmc.loader.impl.launch.knot; import java.util.Objects; diff --git a/src/main/java/net/fabricmc/loader/launch/server/FabricServerLauncher.java b/src/main/java/net/fabricmc/loader/impl/launch/server/FabricServerLauncher.java similarity index 93% rename from src/main/java/net/fabricmc/loader/launch/server/FabricServerLauncher.java rename to src/main/java/net/fabricmc/loader/impl/launch/server/FabricServerLauncher.java index c9b516cd0..299b2a81a 100644 --- a/src/main/java/net/fabricmc/loader/launch/server/FabricServerLauncher.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/server/FabricServerLauncher.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.server; +package net.fabricmc.loader.impl.launch.server; import java.io.File; import java.io.FileInputStream; @@ -25,12 +25,13 @@ import java.net.URLClassLoader; import java.util.Properties; -import net.fabricmc.loader.util.SystemProperties; -import net.fabricmc.loader.util.UrlUtil; +import net.fabricmc.loader.impl.launch.knot.KnotServer; +import net.fabricmc.loader.impl.util.SystemProperties; +import net.fabricmc.loader.impl.util.UrlUtil; public class FabricServerLauncher { private static final ClassLoader parentLoader = FabricServerLauncher.class.getClassLoader(); - private static String mainClass = "net.fabricmc.loader.launch.knot.KnotServer"; + private static String mainClass = KnotServer.class.getName(); public static void main(String[] args) { URL propUrl = parentLoader.getResource("fabric-server-launch.properties"); diff --git a/src/main/java/net/fabricmc/loader/launch/server/InjectingURLClassLoader.java b/src/main/java/net/fabricmc/loader/impl/launch/server/InjectingURLClassLoader.java similarity index 97% rename from src/main/java/net/fabricmc/loader/launch/server/InjectingURLClassLoader.java rename to src/main/java/net/fabricmc/loader/impl/launch/server/InjectingURLClassLoader.java index cb49f4519..cd57e31af 100644 --- a/src/main/java/net/fabricmc/loader/launch/server/InjectingURLClassLoader.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/server/InjectingURLClassLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.launch.server; +package net.fabricmc.loader.impl.launch.server; import java.net.URL; import java.net.URLClassLoader; diff --git a/src/main/java/net/fabricmc/loader/lib/gson/JsonReader.java b/src/main/java/net/fabricmc/loader/impl/lib/gson/JsonReader.java similarity index 99% rename from src/main/java/net/fabricmc/loader/lib/gson/JsonReader.java rename to src/main/java/net/fabricmc/loader/impl/lib/gson/JsonReader.java index 3faac7897..dd067bf3d 100644 --- a/src/main/java/net/fabricmc/loader/lib/gson/JsonReader.java +++ b/src/main/java/net/fabricmc/loader/impl/lib/gson/JsonReader.java @@ -17,7 +17,7 @@ * This file has been modified by the Fabric project (repackage, minor changes). */ -package net.fabricmc.loader.lib.gson; +package net.fabricmc.loader.impl.lib.gson; import java.io.Closeable; import java.io.EOFException; diff --git a/src/main/java/net/fabricmc/loader/lib/gson/JsonScope.java b/src/main/java/net/fabricmc/loader/impl/lib/gson/JsonScope.java similarity index 97% rename from src/main/java/net/fabricmc/loader/lib/gson/JsonScope.java rename to src/main/java/net/fabricmc/loader/impl/lib/gson/JsonScope.java index bc935a9d6..24add7b67 100644 --- a/src/main/java/net/fabricmc/loader/lib/gson/JsonScope.java +++ b/src/main/java/net/fabricmc/loader/impl/lib/gson/JsonScope.java @@ -17,7 +17,7 @@ * This file has been modified by the Fabric project (repackage, minor changes). */ -package net.fabricmc.loader.lib.gson; +package net.fabricmc.loader.impl.lib.gson; /** * Lexical scoping elements within a JSON reader or writer. diff --git a/src/main/java/net/fabricmc/loader/lib/gson/JsonToken.java b/src/main/java/net/fabricmc/loader/impl/lib/gson/JsonToken.java similarity index 97% rename from src/main/java/net/fabricmc/loader/lib/gson/JsonToken.java rename to src/main/java/net/fabricmc/loader/impl/lib/gson/JsonToken.java index 13d57e569..377517de0 100644 --- a/src/main/java/net/fabricmc/loader/lib/gson/JsonToken.java +++ b/src/main/java/net/fabricmc/loader/impl/lib/gson/JsonToken.java @@ -17,7 +17,7 @@ * This file has been modified by the Fabric project (repackage, minor changes). */ -package net.fabricmc.loader.lib.gson; +package net.fabricmc.loader.impl.lib.gson; /** * A structure, name or value type in a JSON-encoded string. diff --git a/src/main/java/net/fabricmc/loader/lib/gson/MalformedJsonException.java b/src/main/java/net/fabricmc/loader/impl/lib/gson/MalformedJsonException.java similarity index 97% rename from src/main/java/net/fabricmc/loader/lib/gson/MalformedJsonException.java rename to src/main/java/net/fabricmc/loader/impl/lib/gson/MalformedJsonException.java index 5ac35f8de..dcd018e58 100644 --- a/src/main/java/net/fabricmc/loader/lib/gson/MalformedJsonException.java +++ b/src/main/java/net/fabricmc/loader/impl/lib/gson/MalformedJsonException.java @@ -17,7 +17,7 @@ * This file has been modified by the Fabric project (repackage, minor changes). */ -package net.fabricmc.loader.lib.gson; +package net.fabricmc.loader.impl.lib.gson; import java.io.IOException; diff --git a/src/main/java/net/fabricmc/loader/metadata/AbstractModMetadata.java b/src/main/java/net/fabricmc/loader/impl/metadata/AbstractModMetadata.java similarity index 98% rename from src/main/java/net/fabricmc/loader/metadata/AbstractModMetadata.java rename to src/main/java/net/fabricmc/loader/impl/metadata/AbstractModMetadata.java index ee324aa29..338588872 100644 --- a/src/main/java/net/fabricmc/loader/metadata/AbstractModMetadata.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/AbstractModMetadata.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.util.Map; diff --git a/src/main/java/net/fabricmc/loader/metadata/BuiltinModMetadata.java b/src/main/java/net/fabricmc/loader/impl/metadata/BuiltinModMetadata.java similarity index 97% rename from src/main/java/net/fabricmc/loader/metadata/BuiltinModMetadata.java rename to src/main/java/net/fabricmc/loader/impl/metadata/BuiltinModMetadata.java index 83a29770a..19ea02f81 100644 --- a/src/main/java/net/fabricmc/loader/metadata/BuiltinModMetadata.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/BuiltinModMetadata.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.util.ArrayList; import java.util.Collection; @@ -33,7 +33,7 @@ import net.fabricmc.loader.api.metadata.ModEnvironment; import net.fabricmc.loader.api.metadata.ModMetadata; import net.fabricmc.loader.api.metadata.Person; -import net.fabricmc.loader.util.version.VersionDeserializer; +import net.fabricmc.loader.impl.util.version.VersionDeserializer; public final class BuiltinModMetadata extends AbstractModMetadata { private final String id; @@ -295,7 +295,7 @@ public ContactInformation getContact() { return contact; } - private final ContactInformation contact = contactMap.isEmpty() ? ContactInformation.EMPTY : new MapBackedContactInformation(contactMap); + private final ContactInformation contact = contactMap.isEmpty() ? ContactInformation.EMPTY : new ContactInformationImpl(contactMap); }; } } diff --git a/src/main/java/net/fabricmc/loader/metadata/ContactInfoBackedPerson.java b/src/main/java/net/fabricmc/loader/impl/metadata/ContactInfoBackedPerson.java similarity index 95% rename from src/main/java/net/fabricmc/loader/metadata/ContactInfoBackedPerson.java rename to src/main/java/net/fabricmc/loader/impl/metadata/ContactInfoBackedPerson.java index 96fece060..dda26c13d 100644 --- a/src/main/java/net/fabricmc/loader/metadata/ContactInfoBackedPerson.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/ContactInfoBackedPerson.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import net.fabricmc.loader.api.metadata.ContactInformation; diff --git a/src/main/java/net/fabricmc/loader/impl/metadata/ContactInformationImpl.java b/src/main/java/net/fabricmc/loader/impl/metadata/ContactInformationImpl.java new file mode 100644 index 000000000..efd7cb71c --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/metadata/ContactInformationImpl.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.metadata; + +import java.util.Collections; +import java.util.Map; +import java.util.Optional; + +import net.fabricmc.loader.api.metadata.ContactInformation; + +public class ContactInformationImpl implements ContactInformation { + private final Map map; + + public ContactInformationImpl(Map map) { + this.map = Collections.unmodifiableMap(map); + } + + @Override + public Optional get(String key) { + return Optional.ofNullable(map.get(key)); + } + + @Override + public Map asMap() { + return map; + } +} diff --git a/src/main/java/net/fabricmc/loader/metadata/CustomValueImpl.java b/src/main/java/net/fabricmc/loader/impl/metadata/CustomValueImpl.java similarity index 98% rename from src/main/java/net/fabricmc/loader/metadata/CustomValueImpl.java rename to src/main/java/net/fabricmc/loader/impl/metadata/CustomValueImpl.java index b5a6aa6af..f13427763 100644 --- a/src/main/java/net/fabricmc/loader/metadata/CustomValueImpl.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/CustomValueImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.io.IOException; import java.util.ArrayList; @@ -27,7 +27,7 @@ import java.util.Objects; import net.fabricmc.loader.api.metadata.CustomValue; -import net.fabricmc.loader.lib.gson.JsonReader; +import net.fabricmc.loader.impl.lib.gson.JsonReader; abstract class CustomValueImpl implements CustomValue { static final CustomValue BOOLEAN_TRUE = new BooleanImpl(true); diff --git a/src/main/java/net/fabricmc/loader/metadata/DependencyOverrides.java b/src/main/java/net/fabricmc/loader/impl/metadata/DependencyOverrides.java similarity index 95% rename from src/main/java/net/fabricmc/loader/metadata/DependencyOverrides.java rename to src/main/java/net/fabricmc/loader/impl/metadata/DependencyOverrides.java index 47f34fe33..f42d43ddc 100644 --- a/src/main/java/net/fabricmc/loader/metadata/DependencyOverrides.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/DependencyOverrides.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.io.IOException; import java.io.InputStreamReader; @@ -30,10 +30,10 @@ import java.util.List; import java.util.Map; -import net.fabricmc.loader.FabricLoader; import net.fabricmc.loader.api.metadata.ModDependency; -import net.fabricmc.loader.lib.gson.JsonReader; -import net.fabricmc.loader.lib.gson.JsonToken; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.lib.gson.JsonReader; +import net.fabricmc.loader.impl.lib.gson.JsonToken; public final class DependencyOverrides { private static final Collection ALLOWED_KEYS = new HashSet<>(Arrays.asList("depends", "recommends", "suggests", "conflicts", "breaks")); @@ -43,8 +43,7 @@ public final class DependencyOverrides { private final Map>> dependencyOverrides; private DependencyOverrides() { - @SuppressWarnings("deprecation") - Path path = FabricLoader.INSTANCE.getConfigDir().resolve("fabric_loader_dependencies.json"); + Path path = FabricLoaderImpl.INSTANCE.getConfigDir().resolve("fabric_loader_dependencies.json"); exists = Files.exists(path); if (!exists) { diff --git a/src/main/java/net/fabricmc/loader/impl/metadata/EntrypointMetadata.java b/src/main/java/net/fabricmc/loader/impl/metadata/EntrypointMetadata.java new file mode 100644 index 000000000..8fb13b204 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/metadata/EntrypointMetadata.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.metadata; + +@SuppressWarnings("deprecation") +public interface EntrypointMetadata extends net.fabricmc.loader.metadata.EntrypointMetadata { + @Override + String getAdapter(); + @Override + String getValue(); +} diff --git a/src/main/java/net/fabricmc/loader/impl/metadata/LoaderModMetadata.java b/src/main/java/net/fabricmc/loader/impl/metadata/LoaderModMetadata.java new file mode 100644 index 000000000..c98c6b0c5 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/metadata/LoaderModMetadata.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.metadata; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.logging.log4j.Logger; + +import net.fabricmc.api.EnvType; + +/** + * Internal variant of the ModMetadata interface. + */ +@SuppressWarnings("deprecation") +public interface LoaderModMetadata extends net.fabricmc.loader.metadata.LoaderModMetadata { + int getSchemaVersion(); + + default String getOldStyleLanguageAdapter() { + return "net.fabricmc.loader.language.JavaLanguageAdapter"; + } + + Map getLanguageAdapterDefinitions(); + Collection getJars(); + Collection getMixinConfigs(EnvType type); + /* @Nullable */ + String getAccessWidener(); + @Override + boolean loadsInEnvironment(EnvType type); + + Collection getOldInitializers(); + @Override + List getEntrypoints(String type); + @Override + Collection getEntrypointKeys(); + + void emitFormatWarnings(Logger logger); +} diff --git a/src/main/java/net/fabricmc/loader/metadata/ModDependencyImpl.java b/src/main/java/net/fabricmc/loader/impl/metadata/ModDependencyImpl.java similarity index 94% rename from src/main/java/net/fabricmc/loader/metadata/ModDependencyImpl.java rename to src/main/java/net/fabricmc/loader/impl/metadata/ModDependencyImpl.java index c37f3d865..080f06f5b 100644 --- a/src/main/java/net/fabricmc/loader/metadata/ModDependencyImpl.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/ModDependencyImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.util.List; import java.util.Set; @@ -23,7 +23,7 @@ import net.fabricmc.loader.api.VersionParsingException; import net.fabricmc.loader.api.VersionPredicate; import net.fabricmc.loader.api.metadata.ModDependency; -import net.fabricmc.loader.util.version.VersionPredicateParser; +import net.fabricmc.loader.impl.util.version.VersionPredicateParser; public final class ModDependencyImpl implements ModDependency { private final String modId; diff --git a/src/main/java/net/fabricmc/loader/metadata/ModMetadataParser.java b/src/main/java/net/fabricmc/loader/impl/metadata/ModMetadataParser.java similarity index 97% rename from src/main/java/net/fabricmc/loader/metadata/ModMetadataParser.java rename to src/main/java/net/fabricmc/loader/impl/metadata/ModMetadataParser.java index bfee4ea6e..9f586bd09 100644 --- a/src/main/java/net/fabricmc/loader/metadata/ModMetadataParser.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/ModMetadataParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.io.IOException; import java.io.InputStreamReader; @@ -27,8 +27,8 @@ import org.apache.logging.log4j.Logger; import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.lib.gson.JsonReader; -import net.fabricmc.loader.lib.gson.JsonToken; +import net.fabricmc.loader.impl.lib.gson.JsonReader; +import net.fabricmc.loader.impl.lib.gson.JsonToken; public final class ModMetadataParser { private static final Logger LOGGER = LogManager.getLogger(); diff --git a/src/main/java/net/fabricmc/loader/metadata/NestedJarEntry.java b/src/main/java/net/fabricmc/loader/impl/metadata/NestedJarEntry.java similarity index 93% rename from src/main/java/net/fabricmc/loader/metadata/NestedJarEntry.java rename to src/main/java/net/fabricmc/loader/impl/metadata/NestedJarEntry.java index 040b9ec7e..fde1a4512 100644 --- a/src/main/java/net/fabricmc/loader/metadata/NestedJarEntry.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/NestedJarEntry.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; public interface NestedJarEntry { String getFile(); diff --git a/src/main/java/net/fabricmc/loader/metadata/ParseMetadataException.java b/src/main/java/net/fabricmc/loader/impl/metadata/ParseMetadataException.java similarity index 92% rename from src/main/java/net/fabricmc/loader/metadata/ParseMetadataException.java rename to src/main/java/net/fabricmc/loader/impl/metadata/ParseMetadataException.java index d219e24d3..d8d1f659a 100644 --- a/src/main/java/net/fabricmc/loader/metadata/ParseMetadataException.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/ParseMetadataException.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; -import net.fabricmc.loader.lib.gson.JsonReader; +import net.fabricmc.loader.impl.lib.gson.JsonReader; @SuppressWarnings("serial") public class ParseMetadataException extends Exception { diff --git a/src/main/java/net/fabricmc/loader/metadata/ParseWarning.java b/src/main/java/net/fabricmc/loader/impl/metadata/ParseWarning.java similarity index 96% rename from src/main/java/net/fabricmc/loader/metadata/ParseWarning.java rename to src/main/java/net/fabricmc/loader/impl/metadata/ParseWarning.java index 5197c31de..035659a39 100644 --- a/src/main/java/net/fabricmc/loader/metadata/ParseWarning.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/ParseWarning.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; final class ParseWarning { private final int line; diff --git a/src/main/java/net/fabricmc/loader/metadata/SimplePerson.java b/src/main/java/net/fabricmc/loader/impl/metadata/SimplePerson.java similarity index 96% rename from src/main/java/net/fabricmc/loader/metadata/SimplePerson.java rename to src/main/java/net/fabricmc/loader/impl/metadata/SimplePerson.java index b77a15399..b183c6c31 100644 --- a/src/main/java/net/fabricmc/loader/metadata/SimplePerson.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/SimplePerson.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import net.fabricmc.loader.api.metadata.ContactInformation; import net.fabricmc.loader.api.metadata.Person; diff --git a/src/main/java/net/fabricmc/loader/metadata/V0ModMetadata.java b/src/main/java/net/fabricmc/loader/impl/metadata/V0ModMetadata.java similarity index 99% rename from src/main/java/net/fabricmc/loader/metadata/V0ModMetadata.java rename to src/main/java/net/fabricmc/loader/impl/metadata/V0ModMetadata.java index 23aa7be11..642bd6927 100644 --- a/src/main/java/net/fabricmc/loader/metadata/V0ModMetadata.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/V0ModMetadata.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/net/fabricmc/loader/metadata/V0ModMetadataParser.java b/src/main/java/net/fabricmc/loader/impl/metadata/V0ModMetadataParser.java similarity index 96% rename from src/main/java/net/fabricmc/loader/metadata/V0ModMetadataParser.java rename to src/main/java/net/fabricmc/loader/impl/metadata/V0ModMetadataParser.java index a3a836b11..98d4ef3a8 100644 --- a/src/main/java/net/fabricmc/loader/metadata/V0ModMetadataParser.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/V0ModMetadataParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.io.IOException; import java.util.ArrayList; @@ -34,9 +34,9 @@ import net.fabricmc.loader.api.metadata.ModDependency; import net.fabricmc.loader.api.metadata.ModEnvironment; import net.fabricmc.loader.api.metadata.Person; -import net.fabricmc.loader.lib.gson.JsonReader; -import net.fabricmc.loader.lib.gson.JsonToken; -import net.fabricmc.loader.util.version.VersionDeserializer; +import net.fabricmc.loader.impl.lib.gson.JsonReader; +import net.fabricmc.loader.impl.lib.gson.JsonToken; +import net.fabricmc.loader.impl.util.version.VersionDeserializer; final class V0ModMetadataParser { private static final Pattern WEBSITE_PATTERN = Pattern.compile("\\((.+)\\)"); @@ -276,7 +276,7 @@ private static ContactInformation readLinks(List warnings, JsonRea throw new ParseMetadataException("Expected links to be an object or string", reader); } - return new MapBackedContactInformation(contactInfo); + return new ContactInformationImpl(contactInfo); } private static V0ModMetadata.Mixins readMixins(List warnings, JsonReader reader) throws IOException, ParseMetadataException { @@ -416,7 +416,7 @@ private static Person readPerson(List warnings, JsonReader reader) name = String.join(" ", parts); - return new ContactInfoBackedPerson(name, new MapBackedContactInformation(contactMap)); + return new ContactInfoBackedPerson(name, new ContactInformationImpl(contactMap)); case BEGIN_OBJECT: reader.beginObject(); @@ -452,7 +452,7 @@ private static Person readPerson(List warnings, JsonReader reader) } reader.endObject(); - return new ContactInfoBackedPerson(name, new MapBackedContactInformation(contactMap)); + return new ContactInfoBackedPerson(name, new ContactInformationImpl(contactMap)); default: throw new ParseMetadataException("Expected person to be a string or object", reader); } diff --git a/src/main/java/net/fabricmc/loader/metadata/V1ModMetadata.java b/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadata.java similarity index 99% rename from src/main/java/net/fabricmc/loader/metadata/V1ModMetadata.java rename to src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadata.java index 9d62e8f7f..0c434e740 100644 --- a/src/main/java/net/fabricmc/loader/metadata/V1ModMetadata.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadata.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/net/fabricmc/loader/metadata/V1ModMetadataParser.java b/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadataParser.java similarity index 98% rename from src/main/java/net/fabricmc/loader/metadata/V1ModMetadataParser.java rename to src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadataParser.java index b36af7c39..8e3ea7c93 100644 --- a/src/main/java/net/fabricmc/loader/metadata/V1ModMetadataParser.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadataParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.metadata; +package net.fabricmc.loader.impl.metadata; import java.io.IOException; import java.util.ArrayList; @@ -35,9 +35,9 @@ import net.fabricmc.loader.api.metadata.ModDependency; import net.fabricmc.loader.api.metadata.ModEnvironment; import net.fabricmc.loader.api.metadata.Person; -import net.fabricmc.loader.lib.gson.JsonReader; -import net.fabricmc.loader.lib.gson.JsonToken; -import net.fabricmc.loader.util.version.VersionDeserializer; +import net.fabricmc.loader.impl.lib.gson.JsonReader; +import net.fabricmc.loader.impl.lib.gson.JsonToken; +import net.fabricmc.loader.impl.util.version.VersionDeserializer; final class V1ModMetadataParser { /** @@ -503,7 +503,7 @@ private static void readPeople(List warnings, JsonReader reader, L personName = reader.nextString(); break; - // Effectively optional + // Effectively optional case "contact": contactInformation = V1ModMetadataParser.readContactInfo(reader); break; @@ -556,7 +556,7 @@ private static ContactInformation readContactInfo(JsonReader reader) throws IOEx reader.endObject(); // Map is wrapped as unmodifiable in the contact info impl - return new MapBackedContactInformation(map); + return new ContactInformationImpl(map); } private static void readLicense(JsonReader reader, List license) throws IOException, ParseMetadataException { diff --git a/src/main/java/net/fabricmc/loader/transformer/ClassStripper.java b/src/main/java/net/fabricmc/loader/impl/transformer/ClassStripper.java similarity index 98% rename from src/main/java/net/fabricmc/loader/transformer/ClassStripper.java rename to src/main/java/net/fabricmc/loader/impl/transformer/ClassStripper.java index 270785f3c..a70395994 100644 --- a/src/main/java/net/fabricmc/loader/transformer/ClassStripper.java +++ b/src/main/java/net/fabricmc/loader/impl/transformer/ClassStripper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.transformer; +package net.fabricmc.loader.impl.transformer; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/net/fabricmc/loader/transformer/EnvironmentStrippingData.java b/src/main/java/net/fabricmc/loader/impl/transformer/EnvironmentStrippingData.java similarity index 99% rename from src/main/java/net/fabricmc/loader/transformer/EnvironmentStrippingData.java rename to src/main/java/net/fabricmc/loader/impl/transformer/EnvironmentStrippingData.java index 3c12f671f..78f40fff8 100644 --- a/src/main/java/net/fabricmc/loader/transformer/EnvironmentStrippingData.java +++ b/src/main/java/net/fabricmc/loader/impl/transformer/EnvironmentStrippingData.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.transformer; +package net.fabricmc.loader.impl.transformer; import java.util.Collection; import java.util.HashSet; diff --git a/src/main/java/net/fabricmc/loader/transformer/FabricTransformer.java b/src/main/java/net/fabricmc/loader/impl/transformer/FabricTransformer.java similarity index 79% rename from src/main/java/net/fabricmc/loader/transformer/FabricTransformer.java rename to src/main/java/net/fabricmc/loader/impl/transformer/FabricTransformer.java index 50438feef..cb6c6503a 100644 --- a/src/main/java/net/fabricmc/loader/transformer/FabricTransformer.java +++ b/src/main/java/net/fabricmc/loader/impl/transformer/FabricTransformer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.transformer; +package net.fabricmc.loader.impl.transformer; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; @@ -22,9 +22,9 @@ import net.fabricmc.accesswidener.AccessWidenerVisitor; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.FabricLoader; -import net.fabricmc.loader.game.MinecraftGameProvider; -import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; public final class FabricTransformer { public static byte[] lwTransformerHook(String name, String transformedName, byte[] bytes) { @@ -44,12 +44,11 @@ public static byte[] lwTransformerHook(String name, String transformedName, byte } } - @SuppressWarnings("deprecation") public static byte[] transform(boolean isDevelopment, EnvType envType, String name, byte[] bytes) { boolean isMinecraftClass = name.startsWith("net.minecraft.") || name.startsWith("com.mojang.blaze3d.") || name.indexOf('.') < 0; boolean transformAccess = isMinecraftClass && FabricLauncherBase.getLauncher().getMappingConfiguration().requiresPackageAccessHack(); boolean environmentStrip = !isMinecraftClass || isDevelopment; - boolean applyAccessWidener = isMinecraftClass && FabricLoader.INSTANCE.getAccessWidener().getTargets().contains(name); + boolean applyAccessWidener = isMinecraftClass && FabricLoaderImpl.INSTANCE.getAccessWidener().getTargets().contains(name); if (!transformAccess && !environmentStrip && !applyAccessWidener) { return bytes; @@ -61,17 +60,17 @@ public static byte[] transform(boolean isDevelopment, EnvType envType, String na int visitorCount = 0; if (applyAccessWidener) { - visitor = AccessWidenerVisitor.createClassVisitor(FabricLoader.ASM_VERSION, visitor, FabricLoader.INSTANCE.getAccessWidener()); + visitor = AccessWidenerVisitor.createClassVisitor(FabricLoaderImpl.ASM_VERSION, visitor, FabricLoaderImpl.INSTANCE.getAccessWidener()); visitorCount++; } if (transformAccess) { - visitor = new PackageAccessFixer(FabricLoader.ASM_VERSION, visitor); + visitor = new PackageAccessFixer(FabricLoaderImpl.ASM_VERSION, visitor); visitorCount++; } if (environmentStrip) { - EnvironmentStrippingData stripData = new EnvironmentStrippingData(FabricLoader.ASM_VERSION, envType.toString()); + EnvironmentStrippingData stripData = new EnvironmentStrippingData(FabricLoaderImpl.ASM_VERSION, envType.toString()); classReader.accept(stripData, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES); if (stripData.stripEntireClass()) { @@ -79,7 +78,7 @@ public static byte[] transform(boolean isDevelopment, EnvType envType, String na } if (!stripData.isEmpty()) { - visitor = new ClassStripper(FabricLoader.ASM_VERSION, visitor, stripData.getStripInterfaces(), stripData.getStripFields(), stripData.getStripMethods()); + visitor = new ClassStripper(FabricLoaderImpl.ASM_VERSION, visitor, stripData.getStripInterfaces(), stripData.getStripFields(), stripData.getStripMethods()); visitorCount++; } } diff --git a/src/main/java/net/fabricmc/loader/transformer/PackageAccessFixer.java b/src/main/java/net/fabricmc/loader/impl/transformer/PackageAccessFixer.java similarity index 97% rename from src/main/java/net/fabricmc/loader/transformer/PackageAccessFixer.java rename to src/main/java/net/fabricmc/loader/impl/transformer/PackageAccessFixer.java index f8681e47c..1217e52e8 100644 --- a/src/main/java/net/fabricmc/loader/transformer/PackageAccessFixer.java +++ b/src/main/java/net/fabricmc/loader/impl/transformer/PackageAccessFixer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.transformer; +package net.fabricmc.loader.impl.transformer; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; diff --git a/src/main/java/net/fabricmc/loader/util/Arguments.java b/src/main/java/net/fabricmc/loader/impl/util/Arguments.java similarity index 98% rename from src/main/java/net/fabricmc/loader/util/Arguments.java rename to src/main/java/net/fabricmc/loader/impl/util/Arguments.java index 453b015b0..efc248bf9 100644 --- a/src/main/java/net/fabricmc/loader/util/Arguments.java +++ b/src/main/java/net/fabricmc/loader/impl/util/Arguments.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util; +package net.fabricmc.loader.impl.util; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/net/fabricmc/loader/impl/util/DefaultLanguageAdapter.java b/src/main/java/net/fabricmc/loader/impl/util/DefaultLanguageAdapter.java new file mode 100644 index 000000000..9e3318b1f --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/util/DefaultLanguageAdapter.java @@ -0,0 +1,141 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.util; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandleProxies; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import net.fabricmc.loader.api.LanguageAdapter; +import net.fabricmc.loader.api.LanguageAdapterException; +import net.fabricmc.loader.api.ModContainer; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; + +public final class DefaultLanguageAdapter implements LanguageAdapter { + public static final DefaultLanguageAdapter INSTANCE = new DefaultLanguageAdapter(); + + private DefaultLanguageAdapter() { } + + @SuppressWarnings("unchecked") + @Override + public T create(ModContainer mod, String value, Class type) throws LanguageAdapterException { + String[] methodSplit = value.split("::"); + + if (methodSplit.length >= 3) { + throw new LanguageAdapterException("Invalid handle format: " + value); + } + + Class c; + + try { + c = Class.forName(methodSplit[0], true, FabricLauncherBase.getLauncher().getTargetClassLoader()); + } catch (ClassNotFoundException e) { + throw new LanguageAdapterException(e); + } + + if (methodSplit.length == 1) { + if (type.isAssignableFrom(c)) { + try { + return (T) c.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + throw new LanguageAdapterException(e); + } + } else { + throw new LanguageAdapterException("Class " + c.getName() + " cannot be cast to " + type.getName() + "!"); + } + } else /* length == 2 */ { + List methodList = new ArrayList<>(); + + for (Method m : c.getDeclaredMethods()) { + if (!(m.getName().equals(methodSplit[1]))) { + continue; + } + + methodList.add(m); + } + + try { + Field field = c.getDeclaredField(methodSplit[1]); + Class fType = field.getType(); + + if ((field.getModifiers() & Modifier.STATIC) == 0) { + throw new LanguageAdapterException("Field " + value + " must be static!"); + } + + if (!methodList.isEmpty()) { + throw new LanguageAdapterException("Ambiguous " + value + " - refers to both field and method!"); + } + + if (!type.isAssignableFrom(fType)) { + throw new LanguageAdapterException("Field " + value + " cannot be cast to " + type.getName() + "!"); + } + + return (T) field.get(null); + } catch (NoSuchFieldException e) { + // ignore + } catch (IllegalAccessException e) { + throw new LanguageAdapterException("Field " + value + " cannot be accessed!", e); + } + + if (!type.isInterface()) { + throw new LanguageAdapterException("Cannot proxy method " + value + " to non-interface type " + type.getName() + "!"); + } + + if (methodList.isEmpty()) { + throw new LanguageAdapterException("Could not find " + value + "!"); + } else if (methodList.size() >= 2) { + throw new LanguageAdapterException("Found multiple method entries of name " + value + "!"); + } + + final Method targetMethod = methodList.get(0); + Object object = null; + + if ((targetMethod.getModifiers() & Modifier.STATIC) == 0) { + try { + object = c.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + throw new LanguageAdapterException(e); + } + } + + MethodHandle handle; + + try { + handle = MethodHandles.lookup() + .unreflect(targetMethod); + } catch (Exception ex) { + throw new LanguageAdapterException(ex); + } + + if (object != null) { + handle = handle.bindTo(object); + } + + // uses proxy as well, but this handles default and object methods + try { + return MethodHandleProxies.asInterfaceInstance(type, handle); + } catch (Exception ex) { + throw new LanguageAdapterException(ex); + } + } + } +} diff --git a/src/main/java/net/fabricmc/loader/util/FileSystemUtil.java b/src/main/java/net/fabricmc/loader/impl/util/FileSystemUtil.java similarity index 98% rename from src/main/java/net/fabricmc/loader/util/FileSystemUtil.java rename to src/main/java/net/fabricmc/loader/impl/util/FileSystemUtil.java index 107cf05c8..12e6855d3 100644 --- a/src/main/java/net/fabricmc/loader/util/FileSystemUtil.java +++ b/src/main/java/net/fabricmc/loader/impl/util/FileSystemUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util; +package net.fabricmc.loader.impl.util; import java.io.File; import java.io.IOException; diff --git a/src/main/java/net/fabricmc/loader/util/StringUtil.java b/src/main/java/net/fabricmc/loader/impl/util/StringUtil.java similarity index 95% rename from src/main/java/net/fabricmc/loader/util/StringUtil.java rename to src/main/java/net/fabricmc/loader/impl/util/StringUtil.java index f2de33f90..2111f0c7c 100644 --- a/src/main/java/net/fabricmc/loader/util/StringUtil.java +++ b/src/main/java/net/fabricmc/loader/impl/util/StringUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util; +package net.fabricmc.loader.impl.util; public final class StringUtil { private StringUtil() { } diff --git a/src/main/java/net/fabricmc/loader/util/SystemProperties.java b/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java similarity index 96% rename from src/main/java/net/fabricmc/loader/util/SystemProperties.java rename to src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java index 25f6ec578..676fca227 100644 --- a/src/main/java/net/fabricmc/loader/util/SystemProperties.java +++ b/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util; +package net.fabricmc.loader.impl.util; public final class SystemProperties { public static final String DEVELOPMENT = "fabric.development"; diff --git a/src/main/java/net/fabricmc/loader/impl/util/UrlConversionException.java b/src/main/java/net/fabricmc/loader/impl/util/UrlConversionException.java new file mode 100644 index 000000000..9ab56be06 --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/util/UrlConversionException.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.util; + +@SuppressWarnings({ "serial", "deprecation" }) +public class UrlConversionException extends net.fabricmc.loader.util.UrlConversionException { + public UrlConversionException() { + super(); + } + + public UrlConversionException(String s) { + super(s); + } + + public UrlConversionException(Throwable t) { + super(t); + } + + public UrlConversionException(String s, Throwable t) { + super(s, t); + } +} diff --git a/src/main/java/net/fabricmc/loader/impl/util/UrlUtil.java b/src/main/java/net/fabricmc/loader/impl/util/UrlUtil.java new file mode 100644 index 000000000..816e1b84f --- /dev/null +++ b/src/main/java/net/fabricmc/loader/impl/util/UrlUtil.java @@ -0,0 +1,91 @@ +/* + * Copyright 2016 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.loader.impl.util; + +import java.io.File; +import java.net.JarURLConnection; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Path; +import java.nio.file.Paths; + +public final class UrlUtil { + private UrlUtil() { } + + public static URL getSource(String filename, URL resourceURL) throws UrlConversionException { + URL codeSourceURL; + + try { + URLConnection connection = resourceURL.openConnection(); + + if (connection instanceof JarURLConnection) { + codeSourceURL = ((JarURLConnection) connection).getJarFileURL(); + } else { + String path = resourceURL.getPath(); + + if (path.endsWith(filename)) { + codeSourceURL = new URL(resourceURL.getProtocol(), resourceURL.getHost(), resourceURL.getPort(), path.substring(0, path.length() - filename.length())); + } else { + throw new UrlConversionException("Could not figure out code source for file '" + filename + "' and URL '" + resourceURL + "'!"); + } + } + } catch (Exception e) { + throw new UrlConversionException(e); + } + + return codeSourceURL; + } + + public static File asFile(URL url) throws UrlConversionException { + try { + return new File(url.toURI()); + } catch (URISyntaxException e) { + throw new UrlConversionException(e); + } + } + + public static Path asPath(URL url) throws UrlConversionException { + if (url.getProtocol().equals("file")) { + // TODO: Is this required? + return asFile(url).toPath(); + } else { + try { + return Paths.get(url.toURI()); + } catch (URISyntaxException e) { + throw new UrlConversionException(e); + } + } + } + + public static URL asUrl(File file) throws UrlConversionException { + try { + return file.toURI().toURL(); + } catch (MalformedURLException e) { + throw new UrlConversionException(e); + } + } + + public static URL asUrl(Path path) throws UrlConversionException { + try { + return new URL(null, path.toUri().toString()); + } catch (MalformedURLException e) { + throw new UrlConversionException(e); + } + } +} diff --git a/src/main/java/net/fabricmc/loader/util/mappings/MixinIntermediaryDevRemapper.java b/src/main/java/net/fabricmc/loader/impl/util/mappings/MixinIntermediaryDevRemapper.java similarity index 99% rename from src/main/java/net/fabricmc/loader/util/mappings/MixinIntermediaryDevRemapper.java rename to src/main/java/net/fabricmc/loader/impl/util/mappings/MixinIntermediaryDevRemapper.java index 42e0bea52..99b9237c4 100644 --- a/src/main/java/net/fabricmc/loader/util/mappings/MixinIntermediaryDevRemapper.java +++ b/src/main/java/net/fabricmc/loader/impl/util/mappings/MixinIntermediaryDevRemapper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.mappings; +package net.fabricmc.loader.impl.util.mappings; import java.util.ArrayDeque; import java.util.Collection; diff --git a/src/main/java/net/fabricmc/loader/util/mappings/TinyRemapperMappingsHelper.java b/src/main/java/net/fabricmc/loader/impl/util/mappings/TinyRemapperMappingsHelper.java similarity index 97% rename from src/main/java/net/fabricmc/loader/util/mappings/TinyRemapperMappingsHelper.java rename to src/main/java/net/fabricmc/loader/impl/util/mappings/TinyRemapperMappingsHelper.java index 35b47032b..9a8aea652 100644 --- a/src/main/java/net/fabricmc/loader/util/mappings/TinyRemapperMappingsHelper.java +++ b/src/main/java/net/fabricmc/loader/impl/util/mappings/TinyRemapperMappingsHelper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.mappings; +package net.fabricmc.loader.impl.util.mappings; import net.fabricmc.mapping.tree.ClassDef; import net.fabricmc.mapping.tree.FieldDef; diff --git a/src/main/java/net/fabricmc/loader/util/version/SemanticVersionImpl.java b/src/main/java/net/fabricmc/loader/impl/util/version/SemanticVersionImpl.java similarity index 99% rename from src/main/java/net/fabricmc/loader/util/version/SemanticVersionImpl.java rename to src/main/java/net/fabricmc/loader/impl/util/version/SemanticVersionImpl.java index 1c36f8615..86f986635 100644 --- a/src/main/java/net/fabricmc/loader/util/version/SemanticVersionImpl.java +++ b/src/main/java/net/fabricmc/loader/impl/util/version/SemanticVersionImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.version; +package net.fabricmc.loader.impl.util.version; import java.util.Arrays; import java.util.Objects; diff --git a/src/main/java/net/fabricmc/loader/util/version/SemanticVersionPredicateParser.java b/src/main/java/net/fabricmc/loader/impl/util/version/SemanticVersionPredicateParser.java similarity index 98% rename from src/main/java/net/fabricmc/loader/util/version/SemanticVersionPredicateParser.java rename to src/main/java/net/fabricmc/loader/impl/util/version/SemanticVersionPredicateParser.java index bf7769c2b..68261adbe 100644 --- a/src/main/java/net/fabricmc/loader/util/version/SemanticVersionPredicateParser.java +++ b/src/main/java/net/fabricmc/loader/impl/util/version/SemanticVersionPredicateParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.version; +package net.fabricmc.loader.impl.util.version; import java.util.ArrayList; import java.util.LinkedHashMap; diff --git a/src/main/java/net/fabricmc/loader/util/version/StringVersion.java b/src/main/java/net/fabricmc/loader/impl/util/version/StringVersion.java similarity index 95% rename from src/main/java/net/fabricmc/loader/util/version/StringVersion.java rename to src/main/java/net/fabricmc/loader/impl/util/version/StringVersion.java index 90354276b..b78316141 100644 --- a/src/main/java/net/fabricmc/loader/util/version/StringVersion.java +++ b/src/main/java/net/fabricmc/loader/impl/util/version/StringVersion.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.version; +package net.fabricmc.loader.impl.util.version; import net.fabricmc.loader.api.Version; diff --git a/src/main/java/net/fabricmc/loader/util/version/StringVersionPredicateParser.java b/src/main/java/net/fabricmc/loader/impl/util/version/StringVersionPredicateParser.java similarity index 95% rename from src/main/java/net/fabricmc/loader/util/version/StringVersionPredicateParser.java rename to src/main/java/net/fabricmc/loader/impl/util/version/StringVersionPredicateParser.java index 92aefcf88..b1231afaf 100644 --- a/src/main/java/net/fabricmc/loader/util/version/StringVersionPredicateParser.java +++ b/src/main/java/net/fabricmc/loader/impl/util/version/StringVersionPredicateParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.version; +package net.fabricmc.loader.impl.util.version; import java.util.function.Predicate; diff --git a/src/main/java/net/fabricmc/loader/util/version/VersionDeserializer.java b/src/main/java/net/fabricmc/loader/impl/util/version/VersionDeserializer.java similarity index 96% rename from src/main/java/net/fabricmc/loader/util/version/VersionDeserializer.java rename to src/main/java/net/fabricmc/loader/impl/util/version/VersionDeserializer.java index a2eb9ab46..9eb0cef64 100644 --- a/src/main/java/net/fabricmc/loader/util/version/VersionDeserializer.java +++ b/src/main/java/net/fabricmc/loader/impl/util/version/VersionDeserializer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.version; +package net.fabricmc.loader.impl.util.version; import net.fabricmc.loader.api.SemanticVersion; import net.fabricmc.loader.api.Version; diff --git a/src/main/java/net/fabricmc/loader/util/version/VersionPredicateParser.java b/src/main/java/net/fabricmc/loader/impl/util/version/VersionPredicateParser.java similarity index 96% rename from src/main/java/net/fabricmc/loader/util/version/VersionPredicateParser.java rename to src/main/java/net/fabricmc/loader/impl/util/version/VersionPredicateParser.java index 31d456de6..16d893d1b 100644 --- a/src/main/java/net/fabricmc/loader/util/version/VersionPredicateParser.java +++ b/src/main/java/net/fabricmc/loader/impl/util/version/VersionPredicateParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.loader.util.version; +package net.fabricmc.loader.impl.util.version; import java.util.function.Predicate; diff --git a/src/main/java/net/fabricmc/loader/language/JavaLanguageAdapter.java b/src/main/java/net/fabricmc/loader/language/JavaLanguageAdapter.java index a630a4084..effbac296 100644 --- a/src/main/java/net/fabricmc/loader/language/JavaLanguageAdapter.java +++ b/src/main/java/net/fabricmc/loader/language/JavaLanguageAdapter.java @@ -25,7 +25,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; @Deprecated public class JavaLanguageAdapter implements LanguageAdapter { diff --git a/src/main/java/net/fabricmc/loader/launch/FabricClientTweaker.java b/src/main/java/net/fabricmc/loader/launch/FabricClientTweaker.java index 510d179f1..b9cccf286 100644 --- a/src/main/java/net/fabricmc/loader/launch/FabricClientTweaker.java +++ b/src/main/java/net/fabricmc/loader/launch/FabricClientTweaker.java @@ -16,16 +16,9 @@ package net.fabricmc.loader.launch; -import net.fabricmc.api.EnvType; - -public final class FabricClientTweaker extends FabricTweaker { - @Override - public EnvType getEnvironmentType() { - return EnvType.CLIENT; - } - - @Override - public String getLaunchTarget() { - return "net.minecraft.client.main.Main"; - } +/** + * @deprecated Use {@link net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricClientTweaker} instead + */ +@Deprecated +public final class FabricClientTweaker extends net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricClientTweaker { } diff --git a/src/main/java/net/fabricmc/loader/launch/FabricServerTweaker.java b/src/main/java/net/fabricmc/loader/launch/FabricServerTweaker.java index 615e5b940..653b7d182 100644 --- a/src/main/java/net/fabricmc/loader/launch/FabricServerTweaker.java +++ b/src/main/java/net/fabricmc/loader/launch/FabricServerTweaker.java @@ -16,16 +16,9 @@ package net.fabricmc.loader.launch; -import net.fabricmc.api.EnvType; - -public final class FabricServerTweaker extends FabricTweaker { - @Override - public EnvType getEnvironmentType() { - return EnvType.SERVER; - } - - @Override - public String getLaunchTarget() { - return "net.minecraft.server.MinecraftServer"; - } +/** + * @deprecated Use {@link net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricServerTweaker} instead + */ +@Deprecated +public final class FabricServerTweaker extends net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricServerTweaker { } diff --git a/src/main/java/net/fabricmc/loader/launch/common/FabricLauncher.java b/src/main/java/net/fabricmc/loader/launch/common/FabricLauncher.java index a141a8e90..9223f281a 100644 --- a/src/main/java/net/fabricmc/loader/launch/common/FabricLauncher.java +++ b/src/main/java/net/fabricmc/loader/launch/common/FabricLauncher.java @@ -23,32 +23,18 @@ import net.fabricmc.api.EnvType; +/** + * @deprecated Internal API, do not use + */ +@Deprecated public interface FabricLauncher { MappingConfiguration getMappingConfiguration(); - void propose(URL url); - EnvType getEnvironmentType(); - boolean isClassLoaded(String name); - InputStream getResourceAsStream(String name); - ClassLoader getTargetClassLoader(); - - /** - * Gets the byte array for a particular class. - * - * @param name The name of the class to retrieve - * @param runTransformers Whether to run all transformers except mixin on the class - */ byte[] getClassByteArray(String name, boolean runTransformers) throws IOException; - boolean isDevelopment(); - - String getEntrypoint(); - - String getTargetNamespace(); - Collection getLoadTimeDependencies(); } diff --git a/src/main/java/net/fabricmc/loader/launch/common/FabricLauncherBase.java b/src/main/java/net/fabricmc/loader/launch/common/FabricLauncherBase.java index bd31cc75c..2237fdc8d 100644 --- a/src/main/java/net/fabricmc/loader/launch/common/FabricLauncherBase.java +++ b/src/main/java/net/fabricmc/loader/launch/common/FabricLauncherBase.java @@ -16,287 +16,71 @@ package net.fabricmc.loader.launch.common; -import java.io.File; import java.io.IOException; -import java.lang.reflect.Method; -import java.net.URI; +import java.io.InputStream; import java.net.URL; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.jar.JarFile; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.mixin.MixinEnvironment; +import java.util.Collection; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.util.Arguments; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; -import net.fabricmc.loader.util.mappings.TinyRemapperMappingsHelper; -import net.fabricmc.mapping.tree.TinyTree; -import net.fabricmc.tinyremapper.OutputConsumerPath; -import net.fabricmc.tinyremapper.TinyRemapper; - -public abstract class FabricLauncherBase implements FabricLauncher { - public static Path minecraftJar; - - protected static Logger LOGGER = LogManager.getFormatterLogger("FabricLoader"); - private static boolean mixinReady; - private static Map properties; - private static FabricLauncher launcher; - private static MappingConfiguration mappingConfiguration = new MappingConfiguration(); - - protected FabricLauncherBase() { - setLauncher(this); - } +import net.fabricmc.loader.api.FabricLoader; - public static File getLaunchDirectory(Arguments argMap) { - return new File(argMap.getOrDefault("gameDir", ".")); - } +/** + * @deprecated Internal API, do not use + */ +@Deprecated +public class FabricLauncherBase implements FabricLauncher { + private final net.fabricmc.loader.impl.launch.FabricLauncher parent = net.fabricmc.loader.impl.launch.FabricLauncherBase.getLauncher(); public static Class getClass(String className) throws ClassNotFoundException { return Class.forName(className, true, getLauncher().getTargetClassLoader()); } - @Override - public MappingConfiguration getMappingConfiguration() { - return mappingConfiguration; + public static FabricLauncher getLauncher() { + return new FabricLauncherBase(); } - private static boolean emittedInfo = false; - - protected static Path deobfuscate(String gameId, String gameVersion, Path gameDir, Path jarFile, FabricLauncher launcher) { - if (!Files.exists(jarFile)) { - throw new RuntimeException("Could not locate Minecraft: " + jarFile + " not found"); - } - - LOGGER.debug("Requesting deobfuscation of " + jarFile.getFileName()); - - if (!launcher.isDevelopment()) { // in-dev is already deobfuscated - Path deobfJarDir = gameDir.resolve(".fabric").resolve("remappedJars"); - - if (!gameId.isEmpty()) { - String versionedId = gameVersion.isEmpty() ? gameId : String.format("%s-%s", gameId, gameVersion); - deobfJarDir = deobfJarDir.resolve(versionedId); - } - - String targetNamespace = mappingConfiguration.getTargetNamespace(); - // TODO: allow versioning mappings? - String deobfJarFilename = targetNamespace + "-" + jarFile.getFileName(); - Path deobfJarFile = deobfJarDir.resolve(deobfJarFilename); - Path deobfJarFileTmp = deobfJarDir.resolve(deobfJarFilename + ".tmp"); - - if (Files.exists(deobfJarFileTmp)) { // previous unfinished remap attempt - LOGGER.warn("Incomplete remapped file found! This means that the remapping process failed on the previous launch. If this persists, make sure to let us at Fabric know!"); - - try { - Files.deleteIfExists(deobfJarFile); - Files.deleteIfExists(deobfJarFileTmp); - } catch (IOException e) { - throw new RuntimeException("can't delete incompletely remapped files", e); - } - } - - TinyTree mappings; - - if (!Files.exists(deobfJarFile) - && (mappings = mappingConfiguration.getMappings()) != null - && mappings.getMetadata().getNamespaces().contains(targetNamespace)) { - LOGGER.debug("Fabric mapping file detected, applying..."); - - if (!emittedInfo) { - LOGGER.info("Fabric is preparing JARs on first launch, this may take a few seconds..."); - emittedInfo = true; - } - - try { - deobfuscate0(jarFile, deobfJarFile, deobfJarFileTmp, mappings, targetNamespace); - } catch (IOException e) { - throw new RuntimeException("error remapping game jar "+jarFile, e); - } - } - - jarFile = deobfJarFile; - } - - try { - launcher.propose(UrlUtil.asUrl(jarFile)); - } catch (UrlConversionException e) { - throw new RuntimeException(e); - } - - if (minecraftJar == null) { - minecraftJar = jarFile; - } - - return jarFile; + @Override + public MappingConfiguration getMappingConfiguration() { + return new MappingConfiguration(); } - private static void deobfuscate0(Path jarFile, Path deobfJarFile, Path deobfJarFileTmp, TinyTree mappings, String targetNamespace) throws IOException { - Files.createDirectories(deobfJarFile.getParent()); - - boolean found; - - do { - TinyRemapper remapper = TinyRemapper.newRemapper() - .withMappings(TinyRemapperMappingsHelper.create(mappings, "official", targetNamespace)) - .rebuildSourceFilenames(true) - .build(); - - Set depPaths = new HashSet<>(); - - for (URL url : launcher.getLoadTimeDependencies()) { - try { - Path path = UrlUtil.asPath(url); - - if (!Files.exists(path)) { - throw new RuntimeException("Path does not exist: " + path); - } - - if (!path.equals(jarFile)) { - depPaths.add(path); - } - } catch (UrlConversionException e) { - throw new RuntimeException("Failed to convert '" + url + "' to path!", e); - } - } - - try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(deobfJarFileTmp) - // force jar despite the .tmp extension - .assumeArchive(true) - // don't accept class names from a blacklist of dependencies that Fabric itself utilizes - // TODO: really could use a better solution, as always... - .filter(clsName -> !clsName.startsWith("com/google/common/") - && !clsName.startsWith("com/google/gson/") - && !clsName.startsWith("com/google/thirdparty/") - && !clsName.startsWith("org/apache/logging/log4j/")) - .build()) { - for (Path path : depPaths) { - LOGGER.debug("Appending '" + path + "' to remapper classpath"); - remapper.readClassPath(path); - } - - remapper.readInputs(jarFile); - remapper.apply(outputConsumer); - } finally { - remapper.finish(); - } - - // Minecraft doesn't tend to check if a ZipFileSystem is already present, - // so we clean up here. - - depPaths.add(deobfJarFileTmp); - - for (Path p : depPaths) { - try { - p.getFileSystem().close(); - } catch (Exception e) { - // pass - } - - try { - FileSystems.getFileSystem(new URI("jar:" + p.toUri())).close(); - } catch (Exception e) { - // pass - } - } - - try (JarFile jar = new JarFile(deobfJarFileTmp.toFile())) { - found = jar.stream().anyMatch((e) -> e.getName().endsWith(".class")); - } - - if (!found) { - LOGGER.error("Generated deobfuscated JAR contains no classes! Trying again..."); - Files.delete(deobfJarFileTmp); - } else { - Files.move(deobfJarFileTmp, deobfJarFile); - } - } while (!found); - - if (!Files.exists(deobfJarFile)) { - throw new RuntimeException("Remapped .JAR file does not exist after remapping! Cannot continue!"); - } + @Override + public void propose(URL url) { + parent.propose(url); } - public static void processArgumentMap(Arguments argMap, EnvType envType) { - switch (envType) { - case CLIENT: - if (!argMap.containsKey("accessToken")) { - argMap.put("accessToken", "FabricMC"); - } - - if (!argMap.containsKey("version")) { - argMap.put("version", "Fabric"); - } - - String versionType = ""; - - if (argMap.containsKey("versionType") && !argMap.get("versionType").equalsIgnoreCase("release")) { - versionType = argMap.get("versionType") + "/"; - } - - argMap.put("versionType", versionType + "Fabric"); - - if (!argMap.containsKey("gameDir")) { - argMap.put("gameDir", getLaunchDirectory(argMap).getAbsolutePath()); - } - - break; - case SERVER: - argMap.remove("version"); - argMap.remove("gameDir"); - argMap.remove("assetsDir"); - break; - } + @Override + public EnvType getEnvironmentType() { + return FabricLoader.getInstance().getEnvironmentType(); } - protected static void setProperties(Map propertiesA) { - if (properties != null && properties != propertiesA) { - throw new RuntimeException("Duplicate setProperties call!"); - } - - properties = propertiesA; + @Override + public boolean isClassLoaded(String name) { + return parent.isClassLoaded(name); } - private static void setLauncher(FabricLauncher launcherA) { - if (launcher != null && launcher != launcherA) { - throw new RuntimeException("Duplicate setLauncher call!"); - } - - launcher = launcherA; + @Override + public InputStream getResourceAsStream(String name) { + return parent.getResourceAsStream(name); } - public static FabricLauncher getLauncher() { - return launcher; + @Override + public ClassLoader getTargetClassLoader() { + return parent.getTargetClassLoader(); } - public static Map getProperties() { - return properties; + @Override + public byte[] getClassByteArray(String name, boolean runTransformers) throws IOException { + return parent.getClassByteArray(name, runTransformers); } - protected static void finishMixinBootstrapping() { - if (mixinReady) { - throw new RuntimeException("Must not call FabricLauncherBase.finishMixinBootstrapping() twice!"); - } - - try { - Method m = MixinEnvironment.class.getDeclaredMethod("gotoPhase", MixinEnvironment.Phase.class); - m.setAccessible(true); - m.invoke(null, MixinEnvironment.Phase.INIT); - m.invoke(null, MixinEnvironment.Phase.DEFAULT); - } catch (Exception e) { - throw new RuntimeException(e); - } - - mixinReady = true; + @Override + public boolean isDevelopment() { + return FabricLoader.getInstance().isDevelopmentEnvironment(); } - public static boolean isMixinReady() { - return mixinReady; + @Override + public Collection getLoadTimeDependencies() { + return parent.getLoadTimeDependencies(); } } diff --git a/src/main/java/net/fabricmc/loader/launch/common/MappingConfiguration.java b/src/main/java/net/fabricmc/loader/launch/common/MappingConfiguration.java index a01b6b1de..715e7fd7c 100644 --- a/src/main/java/net/fabricmc/loader/launch/common/MappingConfiguration.java +++ b/src/main/java/net/fabricmc/loader/launch/common/MappingConfiguration.java @@ -16,60 +16,15 @@ package net.fabricmc.loader.launch.common; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.fabricmc.mapping.tree.TinyMappingFactory; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; import net.fabricmc.mapping.tree.TinyTree; +/** + * @deprecated Internal API, do not use + */ +@Deprecated public class MappingConfiguration { - protected static Logger LOGGER = LogManager.getFormatterLogger("FabricLoader"); - - private static TinyTree mappings; - private static boolean checkedMappings; - public TinyTree getMappings() { - if (!checkedMappings) { - InputStream mappingStream = FabricLauncherBase.class.getClassLoader().getResourceAsStream("mappings/mappings.tiny"); - - if (mappingStream != null) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(mappingStream))) { - long time = System.currentTimeMillis(); - mappings = TinyMappingFactory.loadWithDetection(reader); - LOGGER.debug("Loading mappings took " + (System.currentTimeMillis() - time) + " ms"); - } catch (IOException ee) { - ee.printStackTrace(); - } - - try { - mappingStream.close(); - } catch (IOException ee) { - ee.printStackTrace(); - } - } - - if (mappings == null) { - LOGGER.info("Mappings not present!"); - mappings = TinyMappingFactory.EMPTY_TREE; - } - - checkedMappings = true; - } - - return mappings; - } - - public String getTargetNamespace() { - return FabricLauncherBase.getLauncher().isDevelopment() ? "named" : "intermediary"; - } - - public boolean requiresPackageAccessHack() { - // TODO - return getTargetNamespace().equals("named"); + return FabricLauncherBase.getLauncher().getMappingConfiguration().getMappings(); } } diff --git a/src/main/java/net/fabricmc/loader/launch/knot/KnotClient.java b/src/main/java/net/fabricmc/loader/launch/knot/KnotClient.java index 5b04512b1..a5526a4f6 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/KnotClient.java +++ b/src/main/java/net/fabricmc/loader/launch/knot/KnotClient.java @@ -16,15 +16,15 @@ package net.fabricmc.loader.launch.knot; -import java.io.File; - import net.fabricmc.api.EnvType; -import net.fabricmc.loader.util.SystemProperties; +import net.fabricmc.loader.impl.launch.knot.Knot; -public class KnotClient { +/** + * @deprecated Use {@link net.fabricmc.loader.impl.launch.knot.KnotClient} instead + */ +@Deprecated +public final class KnotClient { public static void main(String[] args) { - String gameJarPath = System.getProperty(SystemProperties.GAME_JAR_PATH); - Knot knot = new Knot(EnvType.CLIENT, gameJarPath != null ? new File(gameJarPath) : null); - knot.launch(knot.init(args)); + Knot.launch(args, EnvType.CLIENT); } } diff --git a/src/main/java/net/fabricmc/loader/launch/knot/KnotServer.java b/src/main/java/net/fabricmc/loader/launch/knot/KnotServer.java index 972238bfd..b6dd3d422 100644 --- a/src/main/java/net/fabricmc/loader/launch/knot/KnotServer.java +++ b/src/main/java/net/fabricmc/loader/launch/knot/KnotServer.java @@ -16,15 +16,15 @@ package net.fabricmc.loader.launch.knot; -import java.io.File; - import net.fabricmc.api.EnvType; -import net.fabricmc.loader.util.SystemProperties; +import net.fabricmc.loader.impl.launch.knot.Knot; -public class KnotServer { +/** + * @deprecated Use {@link net.fabricmc.loader.impl.launch.knot.KnotServer} instead + */ +@Deprecated +public final class KnotServer { public static void main(String[] args) { - String gameJarPath = System.getProperty(SystemProperties.GAME_JAR_PATH); - Knot knot = new Knot(EnvType.SERVER, gameJarPath != null ? new File(gameJarPath) : null); - knot.launch(knot.init(args)); + Knot.launch(args, EnvType.SERVER); } } diff --git a/src/main/java/net/fabricmc/loader/metadata/EntrypointMetadata.java b/src/main/java/net/fabricmc/loader/metadata/EntrypointMetadata.java index 8d6d4e655..46cdc46b1 100644 --- a/src/main/java/net/fabricmc/loader/metadata/EntrypointMetadata.java +++ b/src/main/java/net/fabricmc/loader/metadata/EntrypointMetadata.java @@ -16,6 +16,10 @@ package net.fabricmc.loader.metadata; +/** + * @deprecated Internal API, do not use + */ +@Deprecated public interface EntrypointMetadata { String getAdapter(); String getValue(); diff --git a/src/main/java/net/fabricmc/loader/metadata/LoaderModMetadata.java b/src/main/java/net/fabricmc/loader/metadata/LoaderModMetadata.java index 881abb33e..676db3086 100644 --- a/src/main/java/net/fabricmc/loader/metadata/LoaderModMetadata.java +++ b/src/main/java/net/fabricmc/loader/metadata/LoaderModMetadata.java @@ -18,33 +18,16 @@ import java.util.Collection; import java.util.List; -import java.util.Map; - -import org.apache.logging.log4j.Logger; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.metadata.ModMetadata; /** - * Internal variant of the ModMetadata interface. + * @deprecated Use {@link ModMetadata} instead */ +@Deprecated public interface LoaderModMetadata extends ModMetadata { - int getSchemaVersion(); - - default String getOldStyleLanguageAdapter() { - return "net.fabricmc.loader.language.JavaLanguageAdapter"; - } - - Map getLanguageAdapterDefinitions(); - Collection getJars(); - Collection getMixinConfigs(EnvType type); - /* @Nullable */ - String getAccessWidener(); boolean loadsInEnvironment(EnvType type); - - Collection getOldInitializers(); - List getEntrypoints(String type); + List getEntrypoints(String type); Collection getEntrypointKeys(); - - void emitFormatWarnings(Logger logger); } diff --git a/src/main/java/net/fabricmc/loader/metadata/MapBackedContactInformation.java b/src/main/java/net/fabricmc/loader/metadata/MapBackedContactInformation.java index 7f86381fc..b3d38f88a 100644 --- a/src/main/java/net/fabricmc/loader/metadata/MapBackedContactInformation.java +++ b/src/main/java/net/fabricmc/loader/metadata/MapBackedContactInformation.java @@ -22,6 +22,10 @@ import net.fabricmc.loader.api.metadata.ContactInformation; +/** + * @deprecated Use {@link ContactInformation} instead + */ +@Deprecated public class MapBackedContactInformation implements ContactInformation { private final Map map; diff --git a/src/main/java/net/fabricmc/loader/util/DefaultLanguageAdapter.java b/src/main/java/net/fabricmc/loader/util/DefaultLanguageAdapter.java index c50213baa..eddb8e9d1 100644 --- a/src/main/java/net/fabricmc/loader/util/DefaultLanguageAdapter.java +++ b/src/main/java/net/fabricmc/loader/util/DefaultLanguageAdapter.java @@ -16,126 +16,19 @@ package net.fabricmc.loader.util; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandleProxies; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; - import net.fabricmc.loader.api.LanguageAdapter; import net.fabricmc.loader.api.LanguageAdapterException; import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.launch.common.FabricLauncherBase; +/** + * @deprecated Use {@link LanguageAdapter} instead. + */ +@Deprecated public final class DefaultLanguageAdapter implements LanguageAdapter { public static final DefaultLanguageAdapter INSTANCE = new DefaultLanguageAdapter(); - private DefaultLanguageAdapter() { } - - @SuppressWarnings("unchecked") @Override public T create(ModContainer mod, String value, Class type) throws LanguageAdapterException { - String[] methodSplit = value.split("::"); - - if (methodSplit.length >= 3) { - throw new LanguageAdapterException("Invalid handle format: " + value); - } - - Class c; - - try { - c = Class.forName(methodSplit[0], true, FabricLauncherBase.getLauncher().getTargetClassLoader()); - } catch (ClassNotFoundException e) { - throw new LanguageAdapterException(e); - } - - if (methodSplit.length == 1) { - if (type.isAssignableFrom(c)) { - try { - return (T) c.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - throw new LanguageAdapterException(e); - } - } else { - throw new LanguageAdapterException("Class " + c.getName() + " cannot be cast to " + type.getName() + "!"); - } - } else /* length == 2 */ { - List methodList = new ArrayList<>(); - - for (Method m : c.getDeclaredMethods()) { - if (!(m.getName().equals(methodSplit[1]))) { - continue; - } - - methodList.add(m); - } - - try { - Field field = c.getDeclaredField(methodSplit[1]); - Class fType = field.getType(); - - if ((field.getModifiers() & Modifier.STATIC) == 0) { - throw new LanguageAdapterException("Field " + value + " must be static!"); - } - - if (!methodList.isEmpty()) { - throw new LanguageAdapterException("Ambiguous " + value + " - refers to both field and method!"); - } - - if (!type.isAssignableFrom(fType)) { - throw new LanguageAdapterException("Field " + value + " cannot be cast to " + type.getName() + "!"); - } - - return (T) field.get(null); - } catch (NoSuchFieldException e) { - // ignore - } catch (IllegalAccessException e) { - throw new LanguageAdapterException("Field " + value + " cannot be accessed!", e); - } - - if (!type.isInterface()) { - throw new LanguageAdapterException("Cannot proxy method " + value + " to non-interface type " + type.getName() + "!"); - } - - if (methodList.isEmpty()) { - throw new LanguageAdapterException("Could not find " + value + "!"); - } else if (methodList.size() >= 2) { - throw new LanguageAdapterException("Found multiple method entries of name " + value + "!"); - } - - final Method targetMethod = methodList.get(0); - Object object = null; - - if ((targetMethod.getModifiers() & Modifier.STATIC) == 0) { - try { - object = c.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - throw new LanguageAdapterException(e); - } - } - - MethodHandle handle; - - try { - handle = MethodHandles.lookup() - .unreflect(targetMethod); - } catch (Exception ex) { - throw new LanguageAdapterException(ex); - } - - if (object != null) { - handle = handle.bindTo(object); - } - - // uses proxy as well, but this handles default and object methods - try { - return MethodHandleProxies.asInterfaceInstance(type, handle); - } catch (Exception ex) { - throw new LanguageAdapterException(ex); - } - } + return LanguageAdapter.getDefault().create(mod, value, type); } } diff --git a/src/main/java/net/fabricmc/loader/util/UrlConversionException.java b/src/main/java/net/fabricmc/loader/util/UrlConversionException.java index f058b5111..969017f37 100644 --- a/src/main/java/net/fabricmc/loader/util/UrlConversionException.java +++ b/src/main/java/net/fabricmc/loader/util/UrlConversionException.java @@ -16,7 +16,11 @@ package net.fabricmc.loader.util; +/** + * @deprecated Internal API, do not use + */ @SuppressWarnings("serial") +@Deprecated public class UrlConversionException extends Exception { public UrlConversionException() { super(); diff --git a/src/main/java/net/fabricmc/loader/util/UrlUtil.java b/src/main/java/net/fabricmc/loader/util/UrlUtil.java index 1b941bee5..5d0c0ce3c 100644 --- a/src/main/java/net/fabricmc/loader/util/UrlUtil.java +++ b/src/main/java/net/fabricmc/loader/util/UrlUtil.java @@ -16,76 +16,17 @@ package net.fabricmc.loader.util; -import java.io.File; -import java.net.JarURLConnection; -import java.net.MalformedURLException; -import java.net.URISyntaxException; import java.net.URL; -import java.net.URLConnection; import java.nio.file.Path; -import java.nio.file.Paths; +/** + * @deprecated Internal API, do not use + */ +@Deprecated public final class UrlUtil { private UrlUtil() { } - public static URL getSource(String filename, URL resourceURL) throws UrlConversionException { - URL codeSourceURL; - - try { - URLConnection connection = resourceURL.openConnection(); - - if (connection instanceof JarURLConnection) { - codeSourceURL = ((JarURLConnection) connection).getJarFileURL(); - } else { - String path = resourceURL.getPath(); - - if (path.endsWith(filename)) { - codeSourceURL = new URL(resourceURL.getProtocol(), resourceURL.getHost(), resourceURL.getPort(), path.substring(0, path.length() - filename.length())); - } else { - throw new UrlConversionException("Could not figure out code source for file '" + filename + "' and URL '" + resourceURL + "'!"); - } - } - } catch (Exception e) { - throw new UrlConversionException(e); - } - - return codeSourceURL; - } - - public static File asFile(URL url) throws UrlConversionException { - try { - return new File(url.toURI()); - } catch (URISyntaxException e) { - throw new UrlConversionException(e); - } - } - public static Path asPath(URL url) throws UrlConversionException { - if (url.getProtocol().equals("file")) { - // TODO: Is this required? - return asFile(url).toPath(); - } else { - try { - return Paths.get(url.toURI()); - } catch (URISyntaxException e) { - throw new UrlConversionException(e); - } - } - } - - public static URL asUrl(File file) throws UrlConversionException { - try { - return file.toURI().toURL(); - } catch (MalformedURLException e) { - throw new UrlConversionException(e); - } - } - - public static URL asUrl(Path path) throws UrlConversionException { - try { - return new URL(null, path.toUri().toString()); - } catch (MalformedURLException e) { - throw new UrlConversionException(e); - } + return net.fabricmc.loader.impl.util.UrlUtil.asPath(url); } } diff --git a/src/main/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService b/src/main/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService index 8e1d79d1f..43780be2c 100644 --- a/src/main/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService +++ b/src/main/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService @@ -1 +1 @@ -net.fabricmc.loader.launch.knot.FabricGlobalPropertyService \ No newline at end of file +net.fabricmc.loader.impl.launch.knot.FabricGlobalPropertyService \ No newline at end of file diff --git a/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinService b/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinService index 5af564377..d810591e5 100644 --- a/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinService +++ b/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinService @@ -1 +1 @@ -net.fabricmc.loader.launch.knot.MixinServiceKnot \ No newline at end of file +net.fabricmc.loader.impl.launch.knot.MixinServiceKnot \ No newline at end of file diff --git a/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap b/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap index 7bd3aaac8..3057481b1 100644 --- a/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap +++ b/src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap @@ -1 +1 @@ -net.fabricmc.loader.launch.knot.MixinServiceKnotBootstrap \ No newline at end of file +net.fabricmc.loader.impl.launch.knot.MixinServiceKnotBootstrap \ No newline at end of file diff --git a/src/main/resources/fabric-installer.json b/src/main/resources/fabric-installer.json index 8902e0384..884d122dc 100644 --- a/src/main/resources/fabric-installer.json +++ b/src/main/resources/fabric-installer.json @@ -59,7 +59,7 @@ ] }, "mainClass": { - "client": "net.fabricmc.loader.launch.knot.KnotClient", - "server": "net.fabricmc.loader.launch.knot.KnotServer" + "client": "net.fabricmc.loader.impl.launch.knot.KnotClient", + "server": "net.fabricmc.loader.impl.launch.knot.KnotServer" } } diff --git a/src/main/resources/fabric-installer.launchwrapper.json b/src/main/resources/fabric-installer.launchwrapper.json index 66fe02c09..fcb8e1162 100644 --- a/src/main/resources/fabric-installer.launchwrapper.json +++ b/src/main/resources/fabric-installer.launchwrapper.json @@ -76,12 +76,12 @@ "launchwrapper": { "tweakers": { "client": [ - "net.fabricmc.loader.launch.FabricClientTweaker" + "net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricClientTweaker" ], "common": [ ], "server": [ - "net.fabricmc.loader.launch.FabricServerTweaker" + "net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricServerTweaker" ] } } diff --git a/src/test/java/net/fabricmc/test/McVersionLookupTest.java b/src/test/java/net/fabricmc/test/McVersionLookupTest.java index 7262e8977..6bcbd3580 100644 --- a/src/test/java/net/fabricmc/test/McVersionLookupTest.java +++ b/src/test/java/net/fabricmc/test/McVersionLookupTest.java @@ -27,8 +27,8 @@ import java.util.List; import java.util.regex.Pattern; -import net.fabricmc.loader.minecraft.McVersionLookup; -import net.fabricmc.loader.minecraft.McVersion; +import net.fabricmc.loader.impl.game.minecraft.McVersion; +import net.fabricmc.loader.impl.game.minecraft.McVersionLookup; public final class McVersionLookupTest { public static void main(String[] args) throws IOException { diff --git a/src/test/java/net/fabricmc/test/TestMod.java b/src/test/java/net/fabricmc/test/TestMod.java index 0dcf71c09..b469537f6 100644 --- a/src/test/java/net/fabricmc/test/TestMod.java +++ b/src/test/java/net/fabricmc/test/TestMod.java @@ -26,7 +26,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; -import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.fabricmc.loader.impl.launch.FabricLauncherBase; public class TestMod implements PreLaunchEntrypoint, ModInitializer { private static final Logger LOGGER = LogManager.getFormatterLogger("TestMod"); diff --git a/src/test/java/net/fabricmc/test/V1ModJsonParsingTests.java b/src/test/java/net/fabricmc/test/V1ModJsonParsingTests.java index bad80be08..134526389 100644 --- a/src/test/java/net/fabricmc/test/V1ModJsonParsingTests.java +++ b/src/test/java/net/fabricmc/test/V1ModJsonParsingTests.java @@ -34,9 +34,9 @@ import net.fabricmc.loader.api.SemanticVersion; import net.fabricmc.loader.api.metadata.CustomValue; -import net.fabricmc.loader.metadata.LoaderModMetadata; -import net.fabricmc.loader.metadata.ModMetadataParser; -import net.fabricmc.loader.metadata.ParseMetadataException; +import net.fabricmc.loader.impl.metadata.LoaderModMetadata; +import net.fabricmc.loader.impl.metadata.ModMetadataParser; +import net.fabricmc.loader.impl.metadata.ParseMetadataException; final class V1ModJsonParsingTests { private static final Logger LOGGER = LogManager.getLogger(); @@ -69,12 +69,12 @@ public void testRequiredValues() throws IOException, ParseMetadataException { // Required fields final LoaderModMetadata metadata = ModMetadataParser.parseMetadata(LOGGER, specPath.resolve("required.json")); assertNotNull(metadata, "Failed to read mod metadata!"); - this.validateRequiredValues(metadata); + validateRequiredValues(metadata); // Required fields in different order to verify we don't have ordering issues final LoaderModMetadata reversedMetadata = ModMetadataParser.parseMetadata(LOGGER, specPath.resolve("required_reversed.json")); assertNotNull(reversedMetadata, "Failed to read mod metadata!"); - this.validateRequiredValues(reversedMetadata); + validateRequiredValues(reversedMetadata); } @Test diff --git a/src/test/java/net/fabricmc/test/VersionParsingTests.java b/src/test/java/net/fabricmc/test/VersionParsingTests.java index f47c51d52..93d959a8c 100644 --- a/src/test/java/net/fabricmc/test/VersionParsingTests.java +++ b/src/test/java/net/fabricmc/test/VersionParsingTests.java @@ -21,8 +21,8 @@ import org.jetbrains.annotations.Nullable; import net.fabricmc.loader.api.VersionParsingException; -import net.fabricmc.loader.util.version.SemanticVersionImpl; -import net.fabricmc.loader.util.version.SemanticVersionPredicateParser; +import net.fabricmc.loader.impl.util.version.SemanticVersionImpl; +import net.fabricmc.loader.impl.util.version.SemanticVersionPredicateParser; public class VersionParsingTests { private static Exception tryParseSemantic(String s, boolean storeX) {