Skip to content

Commit

Permalink
Respond to PR feedback
Browse files Browse the repository at this point in the history
- Throws if the SERVICE layer was not built instead of using a default layer
- Extracts the discoverer service type constants to a new shared class and
  adds the ImmediateWindowProvider to this list.
  • Loading branch information
FiniteReality committed Feb 24, 2024
1 parent 8d26fa6 commit 0c5243a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public static List<Path> allExcluded() {

private void scan(final Path gameDirectory) {
try {
locateTransformers("META-INF/services/cpw.mods.modlauncher.api.ITransformationService");
locateTransformers("META-INF/services/net.neoforged.neoforgespi.locating.IModLocator");
for (final String serviceClass : TransformerDiscovererConstants.SERVICES) {
locateTransformers("META-INF/services/" + serviceClass);
}
} catch (IOException e) {
LogManager.getLogger().error("Error during discovery of transform services from the classpath", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void load(final String launchTarget, final String[] arguments) {
LOGGER.info("Loading ImmediateWindowProvider {}", providername);
final var layer = Launcher.INSTANCE.findLayerManager()
.flatMap(manager -> manager.getLayer(Layer.SERVICE))
.orElse(ImmediateWindowHandler.class.getModule().getLayer()); // This will likely be the BOOT layer, but is a sensible fallback.
.orElseThrow(() -> new IllegalStateException("Couldn't find SERVICE layer to load immediate window handler"));
final var maybeProvider = ServiceLoader.load(layer, ImmediateWindowProvider.class)
.stream()
.map(ServiceLoader.Provider::get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class ModDirTransformerDiscoverer implements ITransformerDiscoveryService {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Set<String> SERVICES = Set.of(
"cpw.mods.modlauncher.api.ITransformationService",
"net.neoforged.neoforgespi.locating.IModLocator",
"net.neoforged.neoforgespi.locating.IDependencyLocator"
);
private UncheckedIOException alreadyFailed;

@Override
Expand Down Expand Up @@ -102,6 +96,6 @@ private static boolean shouldLoadInServiceLayer(Path path) {
JarMetadata metadata = JarMetadata.from(new JarContentsBuilder().paths(path).build());
return metadata.providers().stream()
.map(SecureJar.Provider::serviceName)
.anyMatch(SERVICES::contains);
.anyMatch(TransformerDiscovererConstants.SERVICES::contains);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.neoforged.fml.loading;


import cpw.mods.modlauncher.api.IModuleLayerManager.Layer;
import cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService;

import java.util.Set;

/**
* Defines a class containing constants which implementations of {@link ITransformerDiscoveryService}
* may use.
*/
public class TransformerDiscovererConstants {
private TransformerDiscovererConstants() { }

/**
* Defines the set of FML service types which should be loaded on the
* {@link Layer#SERVICE} module layer.
*/
public static final Set<String> SERVICES = Set.of(
"cpw.mods.modlauncher.api.ITransformationService",
"net.neoforged.neoforgespi.locating.IModLocator",
"net.neoforged.neoforgespi.locating.IDependencyLocator",
"net.neoforged.fml.loading.ImmediateWindowProvider"
);
}

0 comments on commit 0c5243a

Please sign in to comment.