From fd403e2f5a01957797d93eef0dd2cd7bbe817064 Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Sat, 4 Jun 2022 15:39:44 +0200 Subject: [PATCH 1/2] Add SPI interface for the different loading and parsing stages in forge. Removes a bunch of casts in forge and allows JIJ to work much more smoothly. --- .../language/IModFileInfoWithLicense.java | 22 ++++++++++ .../IModFileWithAccessTransformer.java | 18 +++++++++ .../language/IModFileWithCoreMods.java | 20 ++++++++++ .../language/IModFileWithJarVersion.java | 17 ++++++++ .../IModFileWithModDiscoveryCapabilities.java | 21 ++++++++++ .../language/IModFileWithProperties.java | 27 +++++++++++++ .../forgespi/language/IScannableModFile.java | 40 +++++++++++++++++++ 7 files changed, 165 insertions(+) create mode 100644 src/main/java/net/minecraftforge/forgespi/language/IModFileInfoWithLicense.java create mode 100644 src/main/java/net/minecraftforge/forgespi/language/IModFileWithAccessTransformer.java create mode 100644 src/main/java/net/minecraftforge/forgespi/language/IModFileWithCoreMods.java create mode 100644 src/main/java/net/minecraftforge/forgespi/language/IModFileWithJarVersion.java create mode 100644 src/main/java/net/minecraftforge/forgespi/language/IModFileWithModDiscoveryCapabilities.java create mode 100644 src/main/java/net/minecraftforge/forgespi/language/IModFileWithProperties.java create mode 100644 src/main/java/net/minecraftforge/forgespi/language/IScannableModFile.java diff --git a/src/main/java/net/minecraftforge/forgespi/language/IModFileInfoWithLicense.java b/src/main/java/net/minecraftforge/forgespi/language/IModFileInfoWithLicense.java new file mode 100644 index 0000000..9c21adf --- /dev/null +++ b/src/main/java/net/minecraftforge/forgespi/language/IModFileInfoWithLicense.java @@ -0,0 +1,22 @@ +package net.minecraftforge.forgespi.language; + +/** + * Represents mod files which have an included license. + * Ensure that the forge license validation code can check for a valid license on mod files which support it. + */ +public interface IModFileInfoWithLicense extends IModFileInfo +{ + /** + * Returns the license name of the mod file. + * + * @return The license name of the mod file. + */ + String getLicense(); + + /** + * Indicates if the mod file has a license, or not. + * + * @return {@code true} if the mod file has a license, {@code false} otherwise. + */ + boolean isMissingLicense(); +} diff --git a/src/main/java/net/minecraftforge/forgespi/language/IModFileWithAccessTransformer.java b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithAccessTransformer.java new file mode 100644 index 0000000..34adc0e --- /dev/null +++ b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithAccessTransformer.java @@ -0,0 +1,18 @@ +package net.minecraftforge.forgespi.language; + +import net.minecraftforge.forgespi.locating.IModFile; + +import java.nio.file.Path; +import java.util.Optional; + +/** + * Represents a mod file which has an access transformer embedded in it. + */ +public interface IModFileWithAccessTransformer extends IModFile +{ + /** + * Gets the access transformer file path for this mod file. + * @return The access transformer file path for this mod file. + */ + Optional getAccessTransformer(); +} diff --git a/src/main/java/net/minecraftforge/forgespi/language/IModFileWithCoreMods.java b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithCoreMods.java new file mode 100644 index 0000000..3b4f322 --- /dev/null +++ b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithCoreMods.java @@ -0,0 +1,20 @@ +package net.minecraftforge.forgespi.language; + +import net.minecraftforge.forgespi.coremod.ICoreModFile; +import net.minecraftforge.forgespi.locating.IModFile; + +import java.util.List; + +/** + * Represents a mod file that has a list of core mods that are required to be loaded. + */ +public interface IModFileWithCoreMods extends IModFile +{ + + /** + * Gets the list of core mods that are required to be loaded. + * + * @return The list of core mods that are required to be loaded. + */ + List getCoreMods(); +} diff --git a/src/main/java/net/minecraftforge/forgespi/language/IModFileWithJarVersion.java b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithJarVersion.java new file mode 100644 index 0000000..7841785 --- /dev/null +++ b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithJarVersion.java @@ -0,0 +1,17 @@ +package net.minecraftforge.forgespi.language; + +import net.minecraftforge.forgespi.locating.IModFile; +import org.apache.maven.artifact.versioning.ArtifactVersion; + +/** + * Represents a mod file that has a version in the jar. + */ +public interface IModFileWithJarVersion extends IModFile +{ + /** + * Gets the version of the mod file. + * + * @return The version of the mod file. + */ + ArtifactVersion getJarVersion(); +} diff --git a/src/main/java/net/minecraftforge/forgespi/language/IModFileWithModDiscoveryCapabilities.java b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithModDiscoveryCapabilities.java new file mode 100644 index 0000000..56107a8 --- /dev/null +++ b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithModDiscoveryCapabilities.java @@ -0,0 +1,21 @@ +package net.minecraftforge.forgespi.language; + +/** + * Represents a mod file that can be discovered by the mod discovery system. + */ +public interface IModFileWithModDiscoveryCapabilities extends IModFileWithCoreMods, IModFileWithAccessTransformer, IScannableModFile, IModFileWithProperties, IModFileWithJarVersion +{ + /** + * Invoked by the discovery system to identify the mods that are located in this file and populate their metadata. + * Note: this can be called from any thread. + * + * @return {@code true} when a mod was found, {@code false} otherwise. + */ + boolean identifyMods(); + + /** + * Invoked by the discovery system to identify the runtime languages and flavors which are needed to potentially run mods in this file. + * Note: this can be called from any thread. + */ + void identifyLanguage(); +} diff --git a/src/main/java/net/minecraftforge/forgespi/language/IModFileWithProperties.java b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithProperties.java new file mode 100644 index 0000000..1f42e2b --- /dev/null +++ b/src/main/java/net/minecraftforge/forgespi/language/IModFileWithProperties.java @@ -0,0 +1,27 @@ +package net.minecraftforge.forgespi.language; + +import net.minecraftforge.forgespi.locating.IModFile; + +import java.util.Map; + +/** + * Interface for mod files that have properties. + * Allows for both the reading and the writing of the associated properties of the mod file. + */ +public interface IModFileWithProperties extends IModFile +{ + /** + * The current properties of the mod file. + * Note: Might be immutable. + * + * @return The properties of the mod file. + */ + Map getFileProperties(); + + /** + * Sets the properties of the mod file. + * + * @param fileProperties The properties of the mod file. + */ + void setFileProperties(Map fileProperties); +} diff --git a/src/main/java/net/minecraftforge/forgespi/language/IScannableModFile.java b/src/main/java/net/minecraftforge/forgespi/language/IScannableModFile.java new file mode 100644 index 0000000..698c7b2 --- /dev/null +++ b/src/main/java/net/minecraftforge/forgespi/language/IScannableModFile.java @@ -0,0 +1,40 @@ +package net.minecraftforge.forgespi.language; + +import net.minecraftforge.forgespi.locating.IModFile; + +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; + +/** + * Represents a mod file that can be scanned for annotation data. + */ +public interface IScannableModFile extends IModFile +{ + /** + * Invoked to scan the mod file for annotation data. + * + * @param pathConsumer The path consumer which can scan a class file for annotation data. + */ + void scanFile(Consumer pathConsumer); + + /** + * Run in an executor thread to harvest the class and annotation list. + */ + ModFileScanData compileContent(); + + /** + * Invoked to set the scan result which is potentially being computed off-thread. + * + * @param future The future to complete when the scan is complete. + */ + void setFutureScanResult(CompletableFuture future); + + /** + * Invoked to set the scan result after it has been computed, and optionally an exception if the scan failed. + * + * @param modFileScanData The scan result. + * @param throwable The exception if the scan failed. + */ + void setScanResult(ModFileScanData modFileScanData, Throwable throwable); +} From f26f048271a1e1ab84cae7b14934ac0680d99761 Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Sat, 4 Jun 2022 16:09:01 +0200 Subject: [PATCH 2/2] Add `IConfigurable` as an extension to the `IModFileInfo` object. --- .../forgespi/language/IModFileInfo.java | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraftforge/forgespi/language/IModFileInfo.java b/src/main/java/net/minecraftforge/forgespi/language/IModFileInfo.java index 94dfc0e..e4a0ce0 100644 --- a/src/main/java/net/minecraftforge/forgespi/language/IModFileInfo.java +++ b/src/main/java/net/minecraftforge/forgespi/language/IModFileInfo.java @@ -25,27 +25,81 @@ import java.util.List; import java.util.Map; -public interface IModFileInfo +/** + * Represents the collected info on a mod file. + */ +public interface IModFileInfo extends IConfigurable { + /** + * Returns the mods which can be found in the mod file. + * + * @return The information on the mods that can be found in the file. + */ List getMods(); + /** + * Defines the combination of required language and supported version range. + * Used during loading to determine if the mod file is compatible with the current environment. + * + * @param languageName The name of the runtime language that is needed. + * @param acceptedVersions The accepted version range. + */ record LanguageSpec(String languageName, VersionRange acceptedVersions) {} + /** + * Returns the languages that are required by the mod file. + * + * @return The required languages. + */ List requiredLanguageLoaders(); + /** + * Indicates if this mod file should be shown as a resource pack or not. + * + * @return {@code true} if the mod file should be shown as a resource pack, {@code false} otherwise. + */ boolean showAsResourcePack(); + /** + * Returns the mod files own properties. + * + * @return The custom properties of the mod file. + */ Map getFileProperties(); - String getLicense(); - + /** + * The java module name of the file. + * Note: This needs to adhere to the JVM specification. + * + * @return The module name. + */ String moduleName(); + /** + * The version of this module as a string. + * + * @return The version of this module. + */ String versionString(); + /** + * Indicates which services this mod file requires. + * + * @return The services that this mod file requires. + */ List usesServices(); + /** + * The underlying mod file. + * + * @return The mod file. + */ IModFile getFile(); + /** + * The underlying configuration of this mod file info object. + * + * @return The configuration of this mod file info object. + */ IConfigurable getConfig(); }