Skip to content

Commit

Permalink
Update dependency Implement bootstrap as a proper service.
Browse files Browse the repository at this point in the history
Made ModuleLayer not care what type of classloader it is.
Code cleanup and better debug messages.
Also slightly better performance by getting rid of stream hell.
  • Loading branch information
LexManos committed Nov 8, 2023
1 parent c6a5990 commit 663cfc0
Show file tree
Hide file tree
Showing 34 changed files with 549 additions and 731 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/test_jvms.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
name: Test JVMs and publish Jmh results

on:
push:
branches:
- main
workflow_dispatch:
pull_request:
types: [opened, synchronize]

jobs:
testjdks:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@
**/logs/
**/profile.jfr
/jmh_results.md
/src/main/resources/META-INF/MANIFEST.MF
/test_results.html
/artifacts/
/test_artifacts.zip
59 changes: 37 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ plugins {
id 'java-library'
id 'eclipse'
id 'net.minecraftforge.gradleutils' version '2.+'
id 'de.jjohannes.extra-java-module-info' version '0.11'
id 'org.gradlex.extra-java-module-info' version '1.5'
id 'com.github.ben-manes.versions' version '0.49.0'
id 'maven-publish'
}

Expand All @@ -26,19 +27,20 @@ repositories {

dependencies {
api(libs.bundles.asm)

implementation(libs.securemodules)
implementation(libs.bundles.log4j.runtime)
implementation(libs.jopt.simple)

implementation(libs.bootstrap.api)

compileOnly(libs.nulls)

annotationProcessor(libs.log4j.core)
}

extraJavaModuleInfo {
failOnMissingModuleInfo = false
automaticModule('jopt-simple-5.0.4.jar', 'jopt.simple')
automaticModule('net.sf.jopt-simple:jopt-simple', 'jopt.simple')
}

license {
Expand All @@ -47,24 +49,27 @@ license {

jar {
manifest {
attributes([
attributes([
'Forge-Module-Layer': 'boot'
] as LinkedHashMap)
attributes([
'Specification-Title': 'modlauncher',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': gradleutils.gitInfo.tag,
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'Forge Development LLC'
] as LinkedHashMap, 'cpw/mods/modlauncher/api/')
attributes([
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': gradleutils.gitInfo.tag,
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'Forge Development LLC'
] as LinkedHashMap, 'cpw/mods/modlauncher/api/')

attributes([
'Specification-Title': 'modlauncherserviceapi',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': gradleutils.gitInfo.tag,
"Implementation-Title": project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'Forge Development LLC'
] as LinkedHashMap, 'cpw/mods/modlauncher/serviceapi/')
}
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': gradleutils.gitInfo.tag,
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'Forge Development LLC'
] as LinkedHashMap, 'cpw/mods/modlauncher/serviceapi/')
}
}

tasks.withType(JavaCompile) {
Expand All @@ -86,7 +91,7 @@ publishing {
description = 'Common ModLauncher framework'
url = 'https://github.com/MinecraftForge/ModLauncher'
PomUtils.setGitHubDetails(pom, 'ModLauncher')

license PomUtils.Licenses.LGPLv2_1
developers {
developer PomUtils.Developers.cpw
Expand All @@ -99,6 +104,16 @@ publishing {
}
}

tasks.register('writeManifest') {
doLast {
jar.manifest.writeTo(file('src/main/resources/META-INF/MANIFEST.MF'))
}
}

eclipse {
autoBuildTasks writeManifest
}

// Hack eclipse into knowing that the gradle deps are modules
eclipse.classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
Expand Down
18 changes: 9 additions & 9 deletions ml-jmh/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ plugins {
id 'org.cadixdev.licenser' version '0.6.1'
id 'eclipse'
id 'java-library'
id 'org.gradlex.extra-java-module-info' version '1.4.2'
id 'org.gradlex.extra-java-module-info' version '1.5'
id 'com.github.ben-manes.versions' version '0.49.0'
id 'net.minecraftforge.gradleutils' version '2.+'
id 'com.diffplug.eclipse.apt' version '3.43.0'
}

repositories {
mavenCentral()
maven gradleutils.forgeMaven
mavenLocal()
}

java {
Expand All @@ -20,22 +20,22 @@ java {
license {
header = rootProject.file("LICENSE-header.txt")
}

dependencies {
implementation(rootProject)
implementation(libs.securemodules)
implementation(project(':ml-test-jar'))
implementation(libs.bundles.powermock)
implementation('org.openjdk.jmh:jmh-core:1.35')
runtimeOnly('org.openjdk.jmh:jmh-generator-annprocess:1.35')
implementation(libs.jmh.core)
runtimeOnly(libs.jmh.ap)

annotationProcessor('org.openjdk.jmh:jmh-generator-annprocess:1.35')
annotationProcessor(libs.jmh.ap)
}

extraJavaModuleInfo {
failOnMissingModuleInfo = false
automaticModule('jmh-core-1.35.jar', 'jmh.core')
automaticModule('powermock-core-2.0.9.jar', 'powermock.core')
automaticModule('powermock-reflect-2.0.9.jar', 'powermock.reflect')
automaticModule('org.openjdk.jmh:jmh-core', 'jmh.core')
automaticModule('org.powermock:powermock-core', 'powermock.core')
automaticModule('org.powermock:powermock-reflect', 'powermock.reflect')
}

def jmhArgs = [
Expand Down
14 changes: 7 additions & 7 deletions ml-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'org.cadixdev.licenser' version '0.6.1'
id 'eclipse'
id 'java-library'
id 'org.gradlex.extra-java-module-info' version '1.4.2'
id 'eclipse'
id 'org.gradlex.extra-java-module-info' version '1.5'
id 'com.github.ben-manes.versions' version '0.49.0'
id 'net.minecraftforge.gradleutils' version '2.+'
}

repositories {
mavenCentral()
maven gradleutils.forgeMaven
mavenLocal()
}

java {
Expand Down Expand Up @@ -41,10 +41,10 @@ dependencies {

extraJavaModuleInfo {
failOnMissingModuleInfo = false
automaticModule('jmh-core-1.35.jar', 'jmh.core')
automaticModule('jopt-simple-5.0.4.jar', 'jopt.simple')
automaticModule('powermock-core-2.0.9.jar', 'powermock.core')
automaticModule('powermock-reflect-2.0.9.jar', 'powermock.reflect')
automaticModule('net.sf.jopt-simple:jopt-simple', 'jopt.simple')
automaticModule('org.openjdk.jmh:jmh-core', 'jmh.core')
automaticModule('org.powermock:powermock-core', 'powermock.core')
automaticModule('org.powermock:powermock-reflect', 'powermock.reflect')
}

// If we are being told a specific vendor then we are probably being run in parallel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ClassTransformerTests {
void testClassTransformer() throws Exception {
MarkerManager.getMarker("CLASSDUMP");
Configurator.setLevel(ClassTransformer.class.getName(), Level.TRACE);
UnsafeHacksUtil.hackPowermock();
final TransformStore transformStore = new TransformStore();
final ModuleLayerHandler layerHandler = Whitebox.invokeConstructor(ModuleLayerHandler.class);
final LaunchPluginHandler lph = new LaunchPluginHandler(layerHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ public List<ITransformer> transformers() {

Environment environment = Whitebox.invokeConstructor(Environment.class, new Class[]{ Launcher.class }, new Object[]{ null });
new TypesafeMap(IEnvironment.class);
Class<?> builderClass = Class.forName("cpw.mods.modlauncher.TransformingClassLoaderBuilder");
Constructor<TransformingClassLoader> constructor = Whitebox.getConstructor(TransformingClassLoader.class, TransformStore.class, LaunchPluginHandler.class, builderClass, Environment.class, Configuration.class, List.class);
Constructor<TransformingClassLoader> constructor = Whitebox.getConstructor(TransformingClassLoader.class,
String.class, ClassLoader.class, Configuration.class, List.class, List.class,
TransformStore.class, LaunchPluginHandler.class, Environment.class
);

Configuration configuration = createTestJarsConfiguration();
TransformingClassLoader tcl = constructor.newInstance(transformStore, lph, null, environment, configuration, List.of(ModuleLayer.boot()));
TransformingClassLoader tcl = constructor.newInstance(
"TRANSFORMER", null, configuration, List.of(ModuleLayer.boot()), List.of(),
transformStore, lph, environment
);
ModuleLayer.boot().defineModules(configuration, s -> tcl);

final Class<?> aClass = Class.forName(TARGET_CLASS, true, tcl);
Expand Down
2 changes: 1 addition & 1 deletion run_workflow_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ clear
#Remove last run just in case
rm -rf artifacts/

act --artifact-server-path ./artifacts
act --artifact-server-path ./artifacts --workflows ./.github/workflows/test_jvms.yml

# Uncompress all artifacts
find ./artifacts/ -name *.gz__ | while read filename; do gunzip --suffix=.gz__ "$filename"; done;
Expand Down
27 changes: 16 additions & 11 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,32 @@ dependencyResolutionManagement {
library('asm-tree', 'org.ow2.asm', 'asm-tree' ).versionRef('asm')
library('asm-commons', 'org.ow2.asm', 'asm-commons').versionRef('asm')
bundle('asm', ['asm', 'asm-tree', 'asm-commons'])
version('junit', '5.10.0')
library('junit-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
library('junit-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
library('junit-platform-launcher', 'org.junit.platform:junit-platform-launcher:1.10.0')
bundle('junit-runtime', ['junit-engine', 'junit-platform-launcher']) // Force Gradle to load the JUnit Platform Launcher from the module-path

version('junit', '5.10.1')
library('junit-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
library('junit-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
library('junit-platform-launcher', 'org.junit.platform:junit-platform-launcher:1.10.1')
bundle('junit-runtime', ['junit-engine', 'junit-platform-launcher']) // Force Gradle to load the JUnit Platform Launcher from the module-path

library('nulls', 'org.jetbrains:annotations:23.0.0')
library('unsafe', 'net.minecraftforge:unsafe:0.9.2')
library('securemodules', 'net.minecraftforge:securemodules:2.2.2')
library('unsafe', 'net.minecraftforge:unsafe:0.9.2')
library('securemodules', 'net.minecraftforge:securemodules:2.2.6')
library('jopt-simple', 'net.sf.jopt-simple:jopt-simple:5.0.4')

library('bootstrap-api', 'net.minecraftforge:bootstrap-api:2.0.0')

version('log4j', '2.17.1')
library('log4j-api', 'org.apache.logging.log4j', 'log4j-api' ).versionRef('log4j')
library('log4j-core', 'org.apache.logging.log4j', 'log4j-core').versionRef('log4j')
bundle('log4j-runtime', ['log4j-api', 'log4j-core'])

version('powermock', '2.0.9')
library('powermock-core', 'org.powermock', 'powermock-core').versionRef('powermock')
library('powermock-reflect', 'org.powermock', 'powermock-reflect').versionRef('powermock')
bundle('powermock', ['powermock-core', 'powermock-reflect'])

version('jmh', '1.37')
library('jmh-core', 'org.openjdk.jmh', 'jmh-core').versionRef('jmh')
library('jmh-ap', 'org.openjdk.jmh', 'jmh-generator-annprocess').versionRef('jmh')
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/cpw/mods/modlauncher/BootstrapEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) Forge Development LLC
* SPDX-License-Identifier: LGPL-3.0-only
*/

package cpw.mods.modlauncher;

import net.minecraftforge.bootstrap.api.BootstrapEntryPoint;

/**
* Internal Service so that Bootstrap can find us.
* Considered internal API, so may break at any time do not reference.
*/
public class BootstrapEntry implements BootstrapEntryPoint {
@Override
public void main(String... strings) {
Launcher.main(strings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.function.Consumer;

@Deprecated(forRemoval = true, since = "10.1") // Use proper Service type.
public class BootstrapLaunchConsumer implements Consumer<String[]> {
@Override
public void accept(final String[] strings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

import java.lang.reflect.*;
import java.nio.file.*;
import java.util.concurrent.*;

/**
* Default launch handler service - will launch minecraft
* This has not worked in years
*/
@Deprecated(forRemoval = true, since = "10.1")
public class DefaultLaunchHandlerService implements ILaunchHandlerService {
public static final String LAUNCH_PROPERTY = "minecraft.client.jar";
public static final String LAUNCH_PATH_STRING = System.getProperty(LAUNCH_PROPERTY);
Expand Down
Loading

0 comments on commit 663cfc0

Please sign in to comment.