diff --git a/build.gradle b/build.gradle index 7715ee3..4c91146 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ repositories { changelog { from '1.0.0' + publishAll = false } license { @@ -40,7 +41,7 @@ dependencies { compileOnly(libs.log4j.api) compileOnly(libs.nulls) compileOnly(libs.forgespi) - + api(libs.bundles.asm) implementation(libs.nashorn) } @@ -60,6 +61,7 @@ tasks.named('jar', Jar) { publishing { publications.register('mavenJava', MavenPublication) { + changelog.publish(it) pom { from components.java artifactId = 'coremods' @@ -68,14 +70,14 @@ publishing { url = 'https://github.com/MinecraftForge/CoreMods' PomUtils.setGitHubDetails(pom, 'CoreMods') license PomUtils.Licenses.LGPLv2_1 - + developers { developer PomUtils.Developers.LexManos developer PomUtils.Developers.cpw } } } - + repositories { maven gradleutils.publishingForgeMaven } diff --git a/coremods-api/build.gradle b/coremods-api/build.gradle new file mode 100644 index 0000000..8b79304 --- /dev/null +++ b/coremods-api/build.gradle @@ -0,0 +1,81 @@ +import net.minecraftforge.gradleutils.PomUtils + +plugins { + id 'idea' + id 'eclipse' + id 'java-library' + id 'maven-publish' + alias libs.plugins.license + //alias libs.plugins.versions + alias libs.plugins.gradleutils +} + +group = 'net.minecraftforge' +version = rootProject.version +println "Version: $version" + +java { + toolchain.languageVersion = JavaLanguageVersion.of(17) + withSourcesJar() +} + +repositories { + mavenCentral() + maven gradleutils.forgeMaven + mavenLocal() +} + +license { + header = rootProject.file('LICENSE-header.txt') + newLine = false +} + +dependencies { + compileOnly(libs.modlauncher) + compileOnly(libs.securemodules) // Needed by Modlauncher + + compileOnly(libs.nulls) + compileOnly(rootProject) + + api(libs.bundles.asm) +} + +tasks.named('jar', Jar) { + manifest { + attributes([ + 'Specification-Title': 'coremods-api', + 'Specification-Vendor': 'Forge Development LLC', + 'Specification-Version': '1', // TODO: Use the tag + 'Implementation-Title': project.name, + 'Implementation-Version': project.version, + 'Implementation-Vendor' :'Forge Development LLC' + ], 'net/minecraftforge/coremod/api/') + } +} + +publishing { + publications.register('mavenJava', MavenPublication) { + pom { + from components.java + artifactId = 'coremods-api' + name = 'Core Mods API' + description = 'API that is useful for Minecraft Transformers' + url = 'https://github.com/MinecraftForge/CoreMods' + PomUtils.setGitHubDetails(pom, 'CoreMods') + license PomUtils.Licenses.LGPLv2_1 + + developers { + developer PomUtils.Developers.LexManos + developer PomUtils.Developers.cpw + } + } + } + + repositories { + maven gradleutils.publishingForgeMaven + } +} + +idea.module { + downloadJavadoc = downloadSources = true +} diff --git a/coremods-api/src/main/java/module-info.java b/coremods-api/src/main/java/module-info.java new file mode 100644 index 0000000..9141844 --- /dev/null +++ b/coremods-api/src/main/java/module-info.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) Forge Development LLC + * SPDX-License-Identifier: LGPL-2.1-only + */ +module net.minecraftforge.coremod.api { + // ASMAPI + exports net.minecraftforge.coremod.api; + + requires cpw.mods.modlauncher; + + requires static org.jetbrains.annotations; + requires org.objectweb.asm.util; + + // JavaScript specific helpers. + requires static net.minecraftforge.coremod; +} diff --git a/src/main/java/net/minecraftforge/coremod/api/ASMAPI.java b/coremods-api/src/main/java/net/minecraftforge/coremod/api/ASMAPI.java similarity index 96% rename from src/main/java/net/minecraftforge/coremod/api/ASMAPI.java rename to coremods-api/src/main/java/net/minecraftforge/coremod/api/ASMAPI.java index b046368..07d48bd 100644 --- a/src/main/java/net/minecraftforge/coremod/api/ASMAPI.java +++ b/coremods-api/src/main/java/net/minecraftforge/coremod/api/ASMAPI.java @@ -6,8 +6,9 @@ import cpw.mods.modlauncher.Launcher; import cpw.mods.modlauncher.api.INameMappingService; -import net.minecraftforge.coremod.CoreModEngine; +import cpw.mods.modlauncher.api.TypesafeMap; import net.minecraftforge.coremod.CoreModTracker; + import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; @@ -15,7 +16,6 @@ import org.objectweb.asm.util.TraceClassVisitor; import org.objectweb.asm.util.TraceMethodVisitor; -import javax.script.ScriptException; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -31,7 +31,7 @@ * to prevent boilerplate code, excessive imports, unnecessary loops, and to provide a more user-friendly API for * coremod developers. */ -@SuppressWarnings({"unused", "exports"}) // annoying IDE warnings +@SuppressWarnings({"exports"}) // annoying IDE warnings public class ASMAPI { /* BUILDING INSTRUCTION LISTS */ @@ -473,7 +473,7 @@ public int get() { * {@link #findFirstInstructionBefore(MethodNode, int, InsnType, int, boolean)}. */ public static @Nullable AbstractInsnNode findFirstInstructionBefore(MethodNode method, int opCode, @Nullable InsnType type, int startIndex) { - return findFirstInstructionBefore(method, opCode, type, startIndex, !CoreModEngine.DO_NOT_FIX_INSNBEFORE); + return findFirstInstructionBefore(method, opCode, type, startIndex, !DO_NOT_FIX_INSNBEFORE); } /** @@ -1121,6 +1121,7 @@ public static void redirectFieldToMethod(final ClassNode classNode, final String * still work for sake of backwards-compatibility, you should not be using this method if you are on 1.20.4 or * later. */ + @Deprecated(forRemoval = true, since = "5.2") public static String mapMethod(String name) { return map(name, INameMappingService.Domain.METHOD); } @@ -1135,6 +1136,7 @@ public static String mapMethod(String name) { * still work for sake of backwards-compatibility, you should not be using this method if you are on 1.20.4 or * later. */ + @Deprecated(forRemoval = true, since = "5.2") public static String mapField(String name) { return map(name, INameMappingService.Domain.FIELD); } @@ -1171,8 +1173,11 @@ public static boolean getSystemPropertyFlag(final String propertyName) { * * @throws ScriptException If the script engine encounters an error, usually due to a syntax error in the script * @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file + * + * @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine. + * If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown. */ - public static boolean loadFile(String file) throws ScriptException, IOException { + public static boolean loadFile(String file) throws IOException { return CoreModTracker.loadFileByName(file); } @@ -1184,10 +1189,13 @@ public static boolean loadFile(String file) throws ScriptException, IOException * {@code initializeCoreMod()} or any of the transformer functions returned by it. * * @throws ScriptException If the parsed JSON data is malformed - * @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file + * @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file. + * + * @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine. + * If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown. */ @Nullable - public static Object loadData(String file) throws ScriptException, IOException { + public static Object loadData(String file) throws IOException { return CoreModTracker.loadDataByName(file); } @@ -1202,6 +1210,9 @@ public static Object loadData(String file) throws ScriptException, IOException { * @param message The message * @param args Any formatting arguments * @see CoreModTracker#log(String, String, Object[]) + * + * @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine. + * If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown. */ public static void log(String level, String message, Object... args) { CoreModTracker.log(level, message, args); @@ -1293,4 +1304,29 @@ private static String toString(Textifier text) { private static int clamp(int value, int min, int max) { return Math.max(min, Math.min(max, value)); } + + // INTERNAL + /** + * Whether to preserve the legacy behavior of + * {@link net.minecraftforge.coremod.api.ASMAPI#findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode, int, + * int)} for backwards-compatibility. + *
+ * In Forge's case, this is set by FML in Minecraft 1.21.1 and earlier, but not in 1.21.3 and later.
+ *
+ * @see net.minecraftforge.coremod.api.ASMAPI#findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode, int,
+ * int)
+ */
+ private static final boolean DO_NOT_FIX_INSNBEFORE = shouldntFixInsnBefore();
+
+ private static final boolean shouldntFixInsnBefore() {
+ try {
+ if (Launcher.INSTANCE == null)
+ return false;
+
+ var blackboardVar = Launcher.INSTANCE.blackboard().get(TypesafeMap.Key.getOrCreate(Launcher.INSTANCE.blackboard(), "coremods.use_old_findFirstInstructionBefore", Boolean.class));
+ return blackboardVar.isPresent() && blackboardVar.get();
+ } catch (Throwable t) { // If ModLauncher doesn't exist.
+ return false;
+ }
+ }
}
diff --git a/coremods-test/build.gradle b/coremods-test/build.gradle
index 50e0d17..943d043 100644
--- a/coremods-test/build.gradle
+++ b/coremods-test/build.gradle
@@ -2,7 +2,6 @@ plugins {
id 'eclipse'
id 'java-library'
alias libs.plugins.license
- alias libs.plugins.modules
//alias libs.plugins.versions
alias libs.plugins.gradleutils
}
@@ -58,11 +57,6 @@ dependencies {
testCompileOnly(libs.nulls)
}
-extraJavaModuleInfo {
- failOnMissingModuleInfo = false
- automaticModule('jopt-simple-5.0.4.jar', 'jopt.simple')
-}
-
// If we are being told a specific vendor then we are probably being run in parallel
if (project.hasProperty('javaVendor') && project.hasProperty('javaVersion')) {
test.javaLauncher.set(javaToolchains.launcherFor {
diff --git a/coremods-test/src/test/resources/log4j2.xml b/coremods-test/src/test/resources/log4j2.xml
index 7eec6f7..b98efbd 100644
--- a/coremods-test/src/test/resources/log4j2.xml
+++ b/coremods-test/src/test/resources/log4j2.xml
@@ -1,9 +1,8 @@
-