Search in sources :

Example 1 with SuperclassChanger

use of org.spongepowered.transformers.modlauncher.SuperclassChanger in project SpongeCommon by SpongePowered.

the class VanillaPlatformService method runScan.

@Override
public List<Map.Entry<String, Path>> runScan(final IEnvironment environment) {
    VanillaPlatformService.pluginPlatform.locatePluginResources();
    VanillaPlatformService.pluginPlatform.createPluginCandidates();
    final AccessWidenerTransformationService accessWidener = environment.getProperty(AccessWidenerTransformationService.INSTANCE.get()).orElse(null);
    final SuperclassChanger superclassChanger = environment.getProperty(SuperclassChanger.INSTANCE.get()).orElse(null);
    final ILaunchPluginService mixin = environment.findLaunchPlugin(MixinLaunchPluginLegacy.NAME).orElse(null);
    final List<Map.Entry<String, Path>> launchResources = new ArrayList<>();
    for (final Map.Entry<String, Set<PluginResource>> resourcesEntry : VanillaPlatformService.pluginPlatform.getResources().entrySet()) {
        final Set<PluginResource> resources = resourcesEntry.getValue();
        for (final PluginResource resource : resources) {
            // Handle Access Transformers
            if ((accessWidener != null || mixin != null || superclassChanger != null) && resource instanceof JVMPluginResource) {
                if (mixin != null) {
                    // Offer jar to the Mixin service
                    mixin.offerResource(((JVMPluginResource) resource).path(), ((JVMPluginResource) resource).path().getFileName().toString());
                }
                // Offer jar to the AW service
                ((JVMPluginResource) resource).manifest().ifPresent(manifest -> {
                    if (accessWidener != null) {
                        final String atFiles = manifest.getMainAttributes().getValue(Constants.ManifestAttributes.ACCESS_WIDENER);
                        if (atFiles != null) {
                            for (final String atFile : atFiles.split(",")) {
                                if (!atFile.endsWith(AccessWidenerTransformationService.ACCESS_WIDENER_EXTENSION)) {
                                    continue;
                                }
                                try {
                                    accessWidener.offerResource(((JVMPluginResource) resource).fileSystem().getPath(atFile).toUri().toURL(), atFile);
                                } catch (final MalformedURLException ex) {
                                    VanillaPlatformService.pluginPlatform.logger().warn("Failed to read declared access widener {}, from {}:", atFile, resource.locator());
                                }
                            }
                        }
                    }
                    if (mixin != null && manifest.getMainAttributes().getValue(org.spongepowered.asm.util.Constants.ManifestAttributes.MIXINCONFIGS) != null) {
                        if (!VanillaPlatformService.isSponge((JVMPluginResource) resource)) {
                            VanillaPlatformService.pluginPlatform.logger().warn("Plugin from {} uses Mixins to modify the Minecraft Server. If something breaks, remove it before reporting the " + "problem to Sponge!", ((JVMPluginResource) resource).path());
                        }
                    }
                    if (superclassChanger != null) {
                        final String superclassChangeFiles = manifest.getMainAttributes().getValue(Constants.ManifestAttributes.SUPERCLASS_CHANGE);
                        if (superclassChangeFiles != null) {
                            for (final String superclassChangeFile : superclassChangeFiles.split(",")) {
                                if (!superclassChangeFile.endsWith(SuperclassChanger.SUPER_CLASS_EXTENSION)) {
                                    continue;
                                }
                                try {
                                    superclassChanger.offerResource(((JVMPluginResource) resource).fileSystem().getPath(superclassChangeFile).toUri().toURL(), superclassChangeFile);
                                } catch (final MalformedURLException ex) {
                                    VanillaPlatformService.pluginPlatform.logger().warn("Failed to read declared superclass changer {}, from {}:", superclassChangeFile, resource.locator());
                                }
                            }
                        }
                    }
                });
                final Map.Entry<String, Path> entry = Maps.immutableEntry(((JVMPluginResource) resource).path().getFileName().toString(), ((JVMPluginResource) resource).path());
                launchResources.add(entry);
            }
        }
    }
    return launchResources;
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) Set(java.util.Set) SuperclassChanger(org.spongepowered.transformers.modlauncher.SuperclassChanger) ArrayList(java.util.ArrayList) ILaunchPluginService(cpw.mods.modlauncher.serviceapi.ILaunchPluginService) JVMPluginResource(org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource) JVMPluginResource(org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource) PluginResource(org.spongepowered.plugin.PluginResource) AccessWidenerTransformationService(org.spongepowered.transformers.modlauncher.AccessWidenerTransformationService) Map(java.util.Map)

Aggregations

ILaunchPluginService (cpw.mods.modlauncher.serviceapi.ILaunchPluginService)1 MalformedURLException (java.net.MalformedURLException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 PluginResource (org.spongepowered.plugin.PluginResource)1 JVMPluginResource (org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource)1 AccessWidenerTransformationService (org.spongepowered.transformers.modlauncher.AccessWidenerTransformationService)1 SuperclassChanger (org.spongepowered.transformers.modlauncher.SuperclassChanger)1