Search in sources :

Example 1 with JVMPluginResource

use of org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource 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)

Example 2 with JVMPluginResource

use of org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource in project SpongeCommon by SpongePowered.

the class PluginRepositorySource method loadPacks.

@Override
public void loadPacks(final Consumer<Pack> callback, final Pack.PackConstructor constructor) {
    final VanillaPluginManager pluginManager = (VanillaPluginManager) Launch.instance().pluginManager();
    // For each plugin, we create a pack. That pack might be empty.
    for (final PluginContainer pluginContainer : pluginManager.plugins()) {
        // The pack ID is prepended with "plugin-", as this will be the namespace we have to use a valid
        // character as a separator
        final String id = "plugin-" + pluginContainer.metadata().id();
        final PluginResource resource = pluginManager.resource(pluginContainer);
        // TODO: provide hook in the resource to return the file system for all resource types?
        // Also -- can we fake a FileSystem for a non-Jar (needs thinking about)....
        @Nullable Supplier<FileSystem> fileSystemSupplier = null;
        if (resource instanceof JVMPluginResource) {
            final String extension = FilenameUtils.getExtension(resource.path().getFileName().toString());
            if ("jar".equals(extension)) {
                fileSystemSupplier = ((JVMPluginResource) resource)::fileSystem;
            }
        }
        final PluginPackResources packResources = new PluginPackResources(id, pluginContainer, fileSystemSupplier);
        final Pack pack = Pack.create(id, true, () -> packResources, constructor, Pack.Position.BOTTOM, PackSource.DEFAULT);
        ((PackRepositoryBridge_Vanilla) this.repository).bridge$registerResourcePack(pluginContainer, pack);
        callback.accept(pack);
    }
}
Also used : PluginContainer(org.spongepowered.plugin.PluginContainer) JVMPluginResource(org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource) JVMPluginResource(org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource) PluginResource(org.spongepowered.plugin.PluginResource) PackRepositoryBridge_Vanilla(org.spongepowered.vanilla.bridge.server.packs.repository.PackRepositoryBridge_Vanilla) FileSystem(java.nio.file.FileSystem) VanillaPluginManager(org.spongepowered.vanilla.launch.plugin.VanillaPluginManager) Pack(net.minecraft.server.packs.repository.Pack) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

PluginResource (org.spongepowered.plugin.PluginResource)2 JVMPluginResource (org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource)2 ILaunchPluginService (cpw.mods.modlauncher.serviceapi.ILaunchPluginService)1 MalformedURLException (java.net.MalformedURLException)1 FileSystem (java.nio.file.FileSystem)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Pack (net.minecraft.server.packs.repository.Pack)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 PluginContainer (org.spongepowered.plugin.PluginContainer)1 AccessWidenerTransformationService (org.spongepowered.transformers.modlauncher.AccessWidenerTransformationService)1 SuperclassChanger (org.spongepowered.transformers.modlauncher.SuperclassChanger)1 PackRepositoryBridge_Vanilla (org.spongepowered.vanilla.bridge.server.packs.repository.PackRepositoryBridge_Vanilla)1 VanillaPluginManager (org.spongepowered.vanilla.launch.plugin.VanillaPluginManager)1