Skip to content

Commit e22e38b

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 e22e38b

File tree

14 files changed

+211
-55
lines changed

14 files changed

+211
-55
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: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import net.minecraftforge.gradleutils.PomUtils
2-
31
plugins {
42
id 'idea'
53
id 'eclipse'
@@ -8,10 +6,12 @@ plugins {
86
alias libs.plugins.license
97
//alias libs.plugins.versions
108
alias libs.plugins.gradleutils
9+
alias libs.plugins.gitversion
10+
alias libs.plugins.changelog
1111
}
1212

1313
group = 'net.minecraftforge'
14-
version = gradleutils.tagOffsetVersion
14+
version = gitversion.tagOffset
1515
println "Version: $version"
1616

1717
java {
@@ -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,22 +61,24 @@ 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'
6668
name = 'Core Mods'
6769
description = 'JavaScript based core modding framework for use with Forge'
68-
url = 'https://github.com/MinecraftForge/CoreMods'
69-
PomUtils.setGitHubDetails(pom, 'CoreMods')
70-
license PomUtils.Licenses.LGPLv2_1
71-
70+
url = 'https://github.com/MinecraftForge/coremods'
71+
72+
gradleutils.pom.addRemoteDetails(pom)
73+
license gradleutils.pom.licenses.LGPLv2_1
74+
7275
developers {
73-
developer PomUtils.Developers.LexManos
74-
developer PomUtils.Developers.cpw
76+
developer gradleutils.pom.developers.LexManos
77+
developer gradleutils.pom.developers.cpw
7578
}
7679
}
7780
}
78-
81+
7982
repositories {
8083
maven gradleutils.publishingForgeMaven
8184
}

coremods-api/build.gradle

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

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-rc-2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)