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;
}
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);
}
}
Aggregations