Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate userdev launch targets and merge them into the dev launch targets #215

Merged
merged 7 commits into from
Nov 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@

package net.neoforged.fml.loading.targets;

import java.nio.file.Files;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.neoforged.fml.loading.VersionInfo;
import net.neoforged.fml.loading.moddiscovery.locators.NeoForgeDevProvider;
import net.neoforged.fml.loading.moddiscovery.locators.UserdevLocator;
import net.neoforged.fml.util.DevEnvUtils;
import net.neoforged.neoforgespi.locating.IModFileCandidateLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* For the NeoForge development environment.
*/
public abstract class CommonDevLaunchHandler extends CommonLaunchHandler {
private static final Logger LOG = LoggerFactory.getLogger(CommonDevLaunchHandler.class);

/**
* A file we expect to find in the classpath entry that contains the Minecraft code.
*/
private static final String MINECRAFT_CLASS_PATH = "net/minecraft/server/MinecraftServer.class";

@Override
public boolean isProduction() {
return false;
Expand All @@ -26,13 +38,30 @@ public boolean isProduction() {
public void collectAdditionalModFileLocators(VersionInfo versionInfo, Consumer<IModFileCandidateLocator> output) {
super.collectAdditionalModFileLocators(versionInfo, output);

NeoForgeDevProvider neoForgeProvider = null;
var groupedModFolders = getGroupedModFolders();
var minecraftFolders = groupedModFolders.get("minecraft");
if (minecraftFolders == null) {
throw new IllegalStateException("Expected paths to minecraft classes to be passed via environment");
if (minecraftFolders != null) {
// A user can theoretically also pass a minecraft folder group when we're in userdev,
// we have to make sure the folder group actually contains a Minecraft class.
for (var candidateFolder : minecraftFolders) {
if (Files.isRegularFile(candidateFolder.resolve(MINECRAFT_CLASS_PATH))) {
LOG.debug("Launching with NeoForge from {}", minecraftFolders);
neoForgeProvider = new NeoForgeDevProvider(minecraftFolders);
break;
}
}
}

if (neoForgeProvider == null) {
// Userdev is similar to neoforge dev with the only real difference being that the combined
// output of the neoforge and patched mincraft sources are combined into a jar file
var classesRoot = DevEnvUtils.findFileSystemRootOfFileOnClasspath(MINECRAFT_CLASS_PATH);
LOG.debug("Launching with NeoForge from {}", classesRoot);
neoForgeProvider = new NeoForgeDevProvider(List.of(classesRoot));
}

output.accept(new NeoForgeDevProvider(minecraftFolders));
output.accept(neoForgeProvider);
output.accept(new UserdevLocator(groupedModFolders));
}

Expand All @@ -51,7 +80,7 @@ protected String[] preLaunch(String[] arguments, ModuleLayer layer) {
String username = args.get("username");
if (username != null) { // Replace '#' placeholders with random numbers
Matcher m = Pattern.compile("#+").matcher(username);
StringBuffer replaced = new StringBuffer();
var replaced = new StringBuilder();
while (m.find()) {
m.appendReplacement(replaced, getRandomNumbers(m.group().length()));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@
package net.neoforged.fml.loading.targets;

import net.neoforged.api.distmarker.Dist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A launch target for bootstrapping a slim Minecraft environment in userdev, to be used in JUnit tests.
*
* @deprecated Use {@link JUnitDevLaunchTarget} instead.
*/
public class JUnitUserDevLaunchTarget extends NeoForgeUserdevLaunchHandler {
@Deprecated(forRemoval = true)
public class JUnitUserDevLaunchTarget extends CommonDevLaunchHandler {
private static final Logger LOG = LoggerFactory.getLogger(JUnitUserDevLaunchTarget.class);

@Override
public Dist getDist() {
return Dist.DEDICATED_SERVER;
}

@Override
protected void runService(String[] arguments, ModuleLayer gameLayer) throws Throwable {
LOG.warn("Using deprecated launch target forgejunituserdev. Use forgejunitdev instead.");
Class.forName(gameLayer.findModule("neoforge").orElseThrow(), "net.neoforged.neoforge.junit.JUnitMain").getMethod("main", String[].class).invoke(null, (Object) arguments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
package net.neoforged.fml.loading.targets;

import net.neoforged.api.distmarker.Dist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @deprecated Use {@link NeoForgeClientDevLaunchHandler} instead.
*/
@Deprecated(forRemoval = true)
public class NeoForgeClientUserdevLaunchHandler extends CommonDevLaunchHandler {
private static final Logger LOG = LoggerFactory.getLogger(NeoForgeClientUserdevLaunchHandler.class);

public class NeoForgeClientUserdevLaunchHandler extends NeoForgeUserdevLaunchHandler {
@Override
public String name() {
return "forgeclientuserdev";
Expand All @@ -20,6 +28,7 @@ public Dist getDist() {

@Override
public void runService(String[] arguments, ModuleLayer layer) throws Throwable {
LOG.warn("Using deprecated launch target forgeclientuserdev. Use forgeclientdev instead.");
clientService(arguments, layer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public boolean isData() {

@Override
public void runService(String[] arguments, ModuleLayer layer) throws Throwable {
Class.forName(layer.findModule("minecraft").orElseThrow(), "net.minecraft.data.Main").getMethod("main", String[].class).invoke(null, (Object) arguments);
dataService(arguments, layer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
package net.neoforged.fml.loading.targets;

import net.neoforged.api.distmarker.Dist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @deprecated Use {@link NeoForgeDataDevLaunchHandler} instead.
*/
@Deprecated(forRemoval = true)
public class NeoForgeDataUserdevLaunchHandler extends CommonDevLaunchHandler {
private static final Logger LOG = LoggerFactory.getLogger(NeoForgeDataUserdevLaunchHandler.class);

public class NeoForgeDataUserdevLaunchHandler extends NeoForgeUserdevLaunchHandler {
@Override
public String name() {
return "forgedatauserdev";
Expand All @@ -25,6 +33,7 @@ public boolean isData() {

@Override
public void runService(String[] arguments, ModuleLayer layer) throws Throwable {
LOG.warn("Using deprecated launch target forgedatauserdev. Use forgedatadev instead.");
dataService(arguments, layer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
package net.neoforged.fml.loading.targets;

import net.neoforged.api.distmarker.Dist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @deprecated Use {@link NeoForgeServerDevLaunchHandler} instead.
*/
@Deprecated(forRemoval = true)
public class NeoForgeServerUserdevLaunchHandler extends CommonDevLaunchHandler {
private static final Logger LOG = LoggerFactory.getLogger(NeoForgeServerUserdevLaunchHandler.class);

public class NeoForgeServerUserdevLaunchHandler extends NeoForgeUserdevLaunchHandler {
@Override
public String name() {
return "forgeserveruserdev";
Expand All @@ -20,6 +28,7 @@ public Dist getDist() {

@Override
public void runService(String[] arguments, ModuleLayer layer) throws Throwable {
LOG.warn("Using deprecated launch target forgeserveruserdev. Use forgeserverdev instead.");
serverService(arguments, layer);
}
}

This file was deleted.