Skip to content

Commit 505ccab

Browse files
committed
Split ASMAPI into it's own general utility artifact.
To keep binary compatibility consumers must ship both artifacts.
1 parent 298ff2f commit 505ccab

File tree

12 files changed

+196
-40
lines changed

12 files changed

+196
-40
lines changed

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ permissions:
99

1010
jobs:
1111
build:
12-
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@main
12+
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@v0
1313
with:
1414
java: 17
15-
gradle_tasks: "publish"
16-
artifact_name: "coremods"
15+
gradle_tasks: "publish coremods-api:publish"
16+
artifact_name: "coremods,coremods-api"
1717
secrets:
1818
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
1919
PROMOTE_ARTIFACT_WEBHOOK: ${{ secrets.PROMOTE_ARTIFACT_WEBHOOK }}

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ repositories {
2727

2828
changelog {
2929
from '1.0.0'
30+
publishAll = false
3031
}
3132

3233
license {
@@ -40,7 +41,7 @@ dependencies {
4041
compileOnly(libs.log4j.api)
4142
compileOnly(libs.nulls)
4243
compileOnly(libs.forgespi)
43-
44+
4445
api(libs.bundles.asm)
4546
implementation(libs.nashorn)
4647
}
@@ -60,6 +61,7 @@ tasks.named('jar', Jar) {
6061

6162
publishing {
6263
publications.register('mavenJava', MavenPublication) {
64+
changelog.publish(it)
6365
pom {
6466
from components.java
6567
artifactId = 'coremods'
@@ -68,14 +70,14 @@ publishing {
6870
url = 'https://github.com/MinecraftForge/CoreMods'
6971
PomUtils.setGitHubDetails(pom, 'CoreMods')
7072
license PomUtils.Licenses.LGPLv2_1
71-
73+
7274
developers {
7375
developer PomUtils.Developers.LexManos
7476
developer PomUtils.Developers.cpw
7577
}
7678
}
7779
}
78-
80+
7981
repositories {
8082
maven gradleutils.publishingForgeMaven
8183
}

coremods-api/build.gradle

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import net.minecraftforge.gradleutils.PomUtils
2+
3+
plugins {
4+
id 'idea'
5+
id 'eclipse'
6+
id 'java-library'
7+
id 'maven-publish'
8+
alias libs.plugins.license
9+
//alias libs.plugins.versions
10+
alias libs.plugins.gradleutils
11+
}
12+
13+
group = 'net.minecraftforge'
14+
version = rootProject.version
15+
println "Version: $version"
16+
17+
java {
18+
toolchain.languageVersion = JavaLanguageVersion.of(17)
19+
withSourcesJar()
20+
}
21+
22+
repositories {
23+
mavenCentral()
24+
maven gradleutils.forgeMaven
25+
mavenLocal()
26+
}
27+
28+
license {
29+
header = rootProject.file('LICENSE-header.txt')
30+
newLine = false
31+
}
32+
33+
dependencies {
34+
compileOnly(libs.modlauncher)
35+
compileOnly(libs.securemodules) // Needed by Modlauncher
36+
37+
compileOnly(libs.nulls)
38+
compileOnly(rootProject)
39+
40+
api(libs.bundles.asm)
41+
}
42+
43+
tasks.named('jar', Jar) {
44+
manifest {
45+
attributes([
46+
'Specification-Title': 'coremods-api',
47+
'Specification-Vendor': 'Forge Development LLC',
48+
'Specification-Version': '1', // TODO: Use the tag
49+
'Implementation-Title': project.name,
50+
'Implementation-Version': project.version,
51+
'Implementation-Vendor' :'Forge Development LLC'
52+
], 'net/minecraftforge/coremod/api/')
53+
}
54+
}
55+
56+
publishing {
57+
publications.register('mavenJava', MavenPublication) {
58+
pom {
59+
from components.java
60+
artifactId = 'coremods-api'
61+
name = 'Core Mods API'
62+
description = 'API that is useful for Minecraft Transformers'
63+
url = 'https://github.com/MinecraftForge/CoreMods'
64+
PomUtils.setGitHubDetails(pom, 'CoreMods')
65+
license PomUtils.Licenses.LGPLv2_1
66+
67+
developers {
68+
developer PomUtils.Developers.LexManos
69+
developer PomUtils.Developers.cpw
70+
}
71+
}
72+
}
73+
74+
repositories {
75+
maven gradleutils.publishingForgeMaven
76+
}
77+
}
78+
79+
idea.module {
80+
downloadJavadoc = downloadSources = true
81+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
module net.minecraftforge.coremod.api {
6+
// ASMAPI
7+
exports net.minecraftforge.coremod.api;
8+
9+
requires cpw.mods.modlauncher;
10+
11+
requires static org.jetbrains.annotations;
12+
requires org.objectweb.asm.util;
13+
14+
// JavaScript specific helpers.
15+
requires static net.minecraftforge.coremod;
16+
}

src/main/java/net/minecraftforge/coremod/api/ASMAPI.java renamed to coremods-api/src/main/java/net/minecraftforge/coremod/api/ASMAPI.java

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
import cpw.mods.modlauncher.Launcher;
88
import cpw.mods.modlauncher.api.INameMappingService;
9-
import net.minecraftforge.coremod.CoreModEngine;
9+
import cpw.mods.modlauncher.api.TypesafeMap;
1010
import net.minecraftforge.coremod.CoreModTracker;
11+
1112
import org.jetbrains.annotations.Nullable;
1213
import org.objectweb.asm.Opcodes;
1314
import org.objectweb.asm.tree.*;
1415
import org.objectweb.asm.util.Textifier;
1516
import org.objectweb.asm.util.TraceClassVisitor;
1617
import org.objectweb.asm.util.TraceMethodVisitor;
1718

18-
import javax.script.ScriptException;
1919
import java.io.IOException;
2020
import java.io.PrintWriter;
2121
import java.io.StringWriter;
@@ -31,7 +31,7 @@
3131
* to prevent boilerplate code, excessive imports, unnecessary loops, and to provide a more user-friendly API for
3232
* coremod developers.
3333
*/
34-
@SuppressWarnings({"unused", "exports"}) // annoying IDE warnings
34+
@SuppressWarnings({"exports"}) // annoying IDE warnings
3535
public class ASMAPI {
3636
/* BUILDING INSTRUCTION LISTS */
3737

@@ -473,7 +473,7 @@ public int get() {
473473
* {@link #findFirstInstructionBefore(MethodNode, int, InsnType, int, boolean)}.
474474
*/
475475
public static @Nullable AbstractInsnNode findFirstInstructionBefore(MethodNode method, int opCode, @Nullable InsnType type, int startIndex) {
476-
return findFirstInstructionBefore(method, opCode, type, startIndex, !CoreModEngine.DO_NOT_FIX_INSNBEFORE);
476+
return findFirstInstructionBefore(method, opCode, type, startIndex, !DO_NOT_FIX_INSNBEFORE);
477477
}
478478

479479
/**
@@ -1171,8 +1171,11 @@ public static boolean getSystemPropertyFlag(final String propertyName) {
11711171
*
11721172
* @throws ScriptException If the script engine encounters an error, usually due to a syntax error in the script
11731173
* @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file
1174+
*
1175+
* @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine.
1176+
* If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown.
11741177
*/
1175-
public static boolean loadFile(String file) throws ScriptException, IOException {
1178+
public static boolean loadFile(String file) throws IOException {
11761179
return CoreModTracker.loadFileByName(file);
11771180
}
11781181

@@ -1184,10 +1187,13 @@ public static boolean loadFile(String file) throws ScriptException, IOException
11841187
* {@code initializeCoreMod()} or any of the transformer functions returned by it.
11851188
*
11861189
* @throws ScriptException If the parsed JSON data is malformed
1187-
* @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file
1190+
* @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file.
1191+
*
1192+
* @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine.
1193+
* If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown.
11881194
*/
11891195
@Nullable
1190-
public static Object loadData(String file) throws ScriptException, IOException {
1196+
public static Object loadData(String file) throws IOException {
11911197
return CoreModTracker.loadDataByName(file);
11921198
}
11931199

@@ -1202,6 +1208,9 @@ public static Object loadData(String file) throws ScriptException, IOException {
12021208
* @param message The message
12031209
* @param args Any formatting arguments
12041210
* @see CoreModTracker#log(String, String, Object[])
1211+
*
1212+
* @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine.
1213+
* If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown.
12051214
*/
12061215
public static void log(String level, String message, Object... args) {
12071216
CoreModTracker.log(level, message, args);
@@ -1293,4 +1302,29 @@ private static String toString(Textifier text) {
12931302
private static int clamp(int value, int min, int max) {
12941303
return Math.max(min, Math.min(max, value));
12951304
}
1305+
1306+
// INTERNAL
1307+
/**
1308+
* Whether to preserve the legacy behavior of
1309+
* {@link net.minecraftforge.coremod.api.ASMAPI#findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode, int,
1310+
* int)} for backwards-compatibility.
1311+
* <p>
1312+
* In Forge's case, this is set by FML in Minecraft 1.21.1 and earlier, but not in 1.21.3 and later.
1313+
*
1314+
* @see net.minecraftforge.coremod.api.ASMAPI#findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode, int,
1315+
* int)
1316+
*/
1317+
private static final boolean DO_NOT_FIX_INSNBEFORE = shouldntFixInsnBefore();
1318+
1319+
private static final boolean shouldntFixInsnBefore() {
1320+
try {
1321+
if (Launcher.INSTANCE == null)
1322+
return false;
1323+
1324+
var blackboardVar = Launcher.INSTANCE.blackboard().get(TypesafeMap.Key.getOrCreate(Launcher.INSTANCE.blackboard(), "coremods.use_old_findFirstInstructionBefore", Boolean.class));
1325+
return blackboardVar.isPresent() && blackboardVar.get();
1326+
} catch (Throwable t) { // If ModLauncher doesn't exist.
1327+
return false;
1328+
}
1329+
}
12961330
}

coremods-test/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ plugins {
22
id 'eclipse'
33
id 'java-library'
44
alias libs.plugins.license
5-
alias libs.plugins.modules
65
//alias libs.plugins.versions
76
alias libs.plugins.gradleutils
87
}
@@ -58,11 +57,6 @@ dependencies {
5857
testCompileOnly(libs.nulls)
5958
}
6059

61-
extraJavaModuleInfo {
62-
failOnMissingModuleInfo = false
63-
automaticModule('jopt-simple-5.0.4.jar', 'jopt.simple')
64-
}
65-
6660
// If we are being told a specific vendor then we are probably being run in parallel
6761
if (project.hasProperty('javaVendor') && project.hasProperty('javaVersion')) {
6862
test.javaLauncher.set(javaToolchains.launcherFor {

coremods-test/src/test/resources/log4j2.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Copyright (c) Forge Development LLC
4-
SPDX-License-Identifier: LGPL-3.0-only
4+
SPDX-License-Identifier: LGPL-2.1-only
55
-->
6-
76
<Configuration status="OFF" packages="cpw.mods.modlauncher">
87
<filters>
98
<MarkerFilter marker="MODLAUNCHER" onMatch="DENY" onMismatch="DENY" />

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
org.gradle.caching=true
22
org.gradle.parallel=true
33
org.gradle.configuration-cache=true
4+
org.gradle.configuration-cache.problems=warn
45
org.gradle.configureondemand=true

settings.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ dependencyResolutionManagement {
1616
plugin('gradleutils', 'net.minecraftforge.gradleutils').version('[2.3,2.4)')
1717
plugin('modules', 'org.gradlex.extra-java-module-info').version('1.9')
1818
plugin('versions', 'com.github.ben-manes.versions').version('0.51.0')
19-
19+
2020
version('asm', '9.7.1')
2121
library('asm', 'org.ow2.asm', 'asm' ).versionRef('asm')
2222
library('asm-tree', 'org.ow2.asm', 'asm-tree' ).versionRef('asm')
2323
library('asm-commons', 'org.ow2.asm', 'asm-commons').versionRef('asm')
24-
bundle('asm', ['asm', 'asm-tree', 'asm-commons'])
25-
24+
library('asm-util', 'org.ow2.asm', 'asm-util' ).versionRef('asm')
25+
bundle('asm', ['asm', 'asm-tree', 'asm-commons', 'asm-util'])
26+
2627
version('junit', '5.11.4')
2728
library('junit-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
2829
library('junit-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
@@ -35,23 +36,24 @@ dependencyResolutionManagement {
3536
library('gson', 'com.google.code.gson:gson:2.10.1')
3637
library('jopt-simple', 'net.sf.jopt-simple:jopt-simple:5.0.4')
3738
*/
38-
39-
library('forgespi', 'net.minecraftforge:forgespi:7.1.0')
39+
40+
library('forgespi', 'net.minecraftforge:forgespi:7.1.0')
4041
library('modlauncher', 'net.minecraftforge:modlauncher:10.1.1') // Needs securemodules
4142
library('nulls', 'org.jetbrains:annotations:26.0.1')
4243
library('nashorn', 'org.openjdk.nashorn:nashorn-core:15.4') // Needed by coremods, because the JRE no longer ships JS
43-
44+
4445
// Used by our test aggrigator scripts
4546
library('ivy', 'org.apache.ivy:ivy:2.5.3')
4647
library('groovy', 'org.codehaus.groovy:groovy-all:3.0.23')
47-
48+
4849
version('log4j', '2.17.0') // Needs to be kept in step with modlauncher because of its config.. TODO: Figure out why?
4950
library('log4j-api', 'org.apache.logging.log4j', 'log4j-api' ).versionRef('log4j')
5051
library('log4j-core', 'org.apache.logging.log4j', 'log4j-core').versionRef('log4j')
5152
}
5253
}
5354
}
5455

55-
rootProject.name = 'CoreMods'
56+
rootProject.name = 'coremods'
57+
include 'coremods-api'
5658
include 'coremods-test'
5759
include 'coremods-test-jar'

src/main/java/module-info.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
module net.minecraftforge.coremod {
66
// CoreMods framework
77
exports net.minecraftforge.coremod;
8-
// ASMAPI
9-
exports net.minecraftforge.coremod.api;
108

119
requires cpw.mods.modlauncher;
1210
requires net.minecraftforge.forgespi;

0 commit comments

Comments
 (0)