use of org.spongepowered.transformers.modlauncher.AccessWidenerTransformationService 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;
}
Aggregations