Skip to content

Commit

Permalink
Fix missing mixins during unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 6, 2024
1 parent 4e9c95f commit 0041ac6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.pf4j.JarPluginManager;
import org.pf4j.PluginManager;

import javax.annotation.Nullable;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -148,9 +149,14 @@ private void sendFlagsInfo() {
log.warn("If you already have those flags or want to disable this warning, only add the '-Dsf.flags.v1=true' to your JVM arguments");
}

private void injectMixinsAndRun(String[] args) {
public void injectMixinsAndRun(String[] args) {
injectMixins(pluginManager);
this.postMixinMain(args);
}

public static void injectMixins(@Nullable PluginManager pluginManager) {
var mixinPaths = new HashSet<String>();
Stream.concat(pluginManager
Stream.concat(pluginManager == null ? Stream.empty() : pluginManager
.getExtensions(MixinExtension.class)
.stream(),
Stream.of(new SFDefaultMixinExtension()))
Expand All @@ -167,9 +173,11 @@ private void injectMixinsAndRun(String[] args) {

var classLoaders = new ArrayList<ClassLoader>();
classLoaders.add(SoulFireAbstractBootstrap.class.getClassLoader());
pluginManager
.getPlugins()
.forEach(pluginWrapper -> classLoaders.add(pluginWrapper.getPluginClassLoader()));
if (pluginManager != null) {
pluginManager
.getPlugins()
.forEach(pluginWrapper -> classLoaders.add(pluginWrapper.getPluginClassLoader()));
}

var classProvider = new CustomClassProvider(classLoaders);
var transformerManager = new TransformerManager(classProvider);
Expand All @@ -179,11 +187,9 @@ private void injectMixinsAndRun(String[] args) {
try {
transformerManager.hookInstrumentation(Agents.getInstrumentation());
log.info("Used Runtime Agent to inject mixins");

this.postMixinMain(args);
} catch (IOException t) {
log.error("Failed to inject mixins", t);
System.exit(1);
throw new IllegalStateException("Failed to inject mixins", t);
}
}

Expand Down
2 changes: 2 additions & 0 deletions server/src/test/java/com/soulfiremc/test/LoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.soulfiremc.test;

import com.soulfiremc.launcher.SoulFireAbstractBootstrap;
import com.soulfiremc.server.SoulFireServer;
import com.soulfiremc.server.grpc.DefaultAuthSystem;
import com.soulfiremc.server.util.PortHelper;
Expand All @@ -38,6 +39,7 @@ public void testLoad() {

SFLogAppender.INSTANCE.start();

SoulFireAbstractBootstrap.injectMixins(null);
var server = new SoulFireServer("127.0.0.1", PortHelper.getRandomAvailablePort(), new DefaultPluginManager(), Instant.now(), new DefaultAuthSystem(), tempDir);

server.shutdownManager().shutdownSoftware(false);
Expand Down

0 comments on commit 0041ac6

Please sign in to comment.