use of org.spongepowered.plugin.meta.PluginMetadata in project SpongeVanilla by SpongePowered.
the class MetadataContainer method load.
public static MetadataContainer load(String path) {
List<PluginMetadata> meta;
path = path + '/' + McModInfo.STANDARD_FILENAME;
try (InputStream in = MetadataContainer.class.getResourceAsStream(path)) {
if (in == null) {
if (VanillaLaunch.ENVIRONMENT != DEVELOPMENT) {
throw new LaunchException("Unable to find metadata file at " + path);
}
return new MetadataContainer(ImmutableMap.of());
}
meta = McModInfo.DEFAULT.read(in);
} catch (IOException e) {
throw new LaunchException("Failed to load metadata", e);
}
ImmutableMap.Builder<String, PluginMetadata> builder = ImmutableMap.builder();
for (PluginMetadata m : meta) {
builder.put(m.getId(), m);
}
return new MetadataContainer(builder.build());
}
use of org.spongepowered.plugin.meta.PluginMetadata in project SpongeVanilla by SpongePowered.
the class MetadataContainer method get.
public PluginMetadata get(String id, String name) {
PluginMetadata meta = this.metadata.get(id);
if (meta == null) {
if (VanillaLaunch.ENVIRONMENT != DEVELOPMENT) {
throw new RuntimeException("Unable to find metadata for " + id);
}
meta = new PluginMetadata(id);
meta.setName(name);
}
return meta;
}
use of org.spongepowered.plugin.meta.PluginMetadata in project SpongeVanilla by SpongePowered.
the class MinecraftPluginContainer method create.
private static PluginContainer create() {
MetadataContainer metadata = MetadataContainer.load("/net/minecraft");
PluginMetadata meta = metadata.get(SpongeImpl.GAME_ID, SpongeImpl.GAME_NAME);
meta.setVersion(SpongeImpl.MINECRAFT_VERSION.getName());
return new MetaPluginContainer(meta, PluginSource.find(MinecraftServer.class));
}
use of org.spongepowered.plugin.meta.PluginMetadata in project SpongeVanilla by SpongePowered.
the class VanillaPluginManager method loadPlugin.
private void loadPlugin(PluginCandidate candidate) {
final String id = candidate.getId();
candidate.getSource().addToClasspath();
final PluginMetadata metadata = candidate.getMetadata();
final String name = firstNonNull(metadata.getName(), id);
final String version = firstNonNull(metadata.getVersion(), "unknown");
try {
Class<?> pluginClass = Class.forName(candidate.getPluginClass());
Optional<Path> source = candidate.getSource().getPath();
if (!source.isPresent()) {
source = PluginSource.find(pluginClass);
}
PluginContainer container = new VanillaPluginContainer(this.rootInjector, pluginClass, metadata, source);
registerPlugin(container);
Sponge.getEventManager().registerListeners(container, container.getInstance().get());
SpongeImpl.getLogger().info("Loaded plugin: {} {} (from {})", name, version, candidate.getSource());
} catch (Throwable e) {
SpongeImpl.getLogger().error("Failed to load plugin: {} {} (from {})", name, version, candidate.getSource(), e);
}
}
use of org.spongepowered.plugin.meta.PluginMetadata in project SpongeVanilla by SpongePowered.
the class PluginScanner method scanJar.
void scanJar(Path path, boolean classpath) {
logger.trace("Scanning {} for plugins", path);
Set<String> annotationProcessors = Collections.emptySet();
List<PluginCandidate> candidates = new ArrayList<>();
List<PluginMetadata> metadata = null;
Set<String> mixinConfigs = null;
Set<String> mixinTokenProviders = null;
PluginSource source = new PluginSource(path);
// Open the zip file so we can scan it for plugins
try (JarInputStream jar = new JarInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
ZipEntry entry = jar.getNextEntry();
if (entry == null) {
return;
}
Manifest manifest = jar.getManifest();
if (manifest == null) {
// Try harder to find it anyway - Wtf Java?
try (JarFile jarFile = new JarFile(path.toFile())) {
manifest = jarFile.getManifest();
}
}
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
annotationProcessors = PluginAccessTransformers.find(attributes);
mixinConfigs = PluginTweakers.findMixinConfigs(path, attributes);
if (mixinConfigs != null) {
mixinTokenProviders = PluginTweakers.findTokenProviders(attributes);
}
} else if (!classpath) {
logger.warn("Missing JAR manifest in {}", path);
}
do {
if (entry.isDirectory()) {
continue;
}
final String name = entry.getName();
if (!name.endsWith(CLASS_EXTENSION)) {
if (name.equals(METADATA_FILE)) {
try {
metadata = McModInfo.DEFAULT.read(jar);
} catch (IOException e) {
logger.error("Failed to read plugin metadata from " + METADATA_FILE + " in {}", path, e);
return;
}
} else if (annotationProcessors.remove(name)) {
try {
AccessTransformers.register(jar);
} catch (IOException e) {
logger.warn("Failed to read access transformer from: {}!{}", path, name, e);
}
}
continue;
}
PluginCandidate candidate = scanClassFile(jar, source);
if (candidate != null) {
candidates.add(candidate);
}
} while ((entry = jar.getNextEntry()) != null);
} catch (IOException e) {
logger.error("Failed to scan plugin JAR: {}", path, e);
return;
}
// There are some annotation processors left we haven't read yet
if (!annotationProcessors.isEmpty()) {
logger.warn("Found non-existent access transformers in plugin manifest of {}: {}", path, annotationProcessors);
}
if (mixinConfigs != null) {
logger.warn("Plugin from {} uses Mixins to modify the Minecraft Server. If something breaks, remove it before reporting the " + "problem to Sponge!", source);
// If the plugin wants to apply Mixins we need to add it to the classpath earlier
source.addToClasspath();
for (String config : mixinConfigs) {
logger.debug("Registering Mixin config '{}' from {}", config, source);
PluginTweakers.registerConfig(config);
}
if (mixinTokenProviders != null) {
for (String provider : mixinTokenProviders) {
logger.debug("Registering Mixin token provider '{}' from {}", provider, source);
PluginTweakers.registerTokenProvider(provider);
}
}
}
if (!candidates.isEmpty()) {
boolean success = false;
for (PluginCandidate candidate : candidates) {
success |= addCandidate(candidate);
// Find matching plugin metadata
if (metadata != null) {
boolean found = false;
for (PluginMetadata meta : metadata) {
if (candidate.getId().equals(meta.getId())) {
found = true;
candidate.setMetadata(meta);
break;
}
}
if (!found) {
logger.warn("No matching metadata found for plugin '{}' in " + METADATA_FILE + " from {}", candidate.getId(), path);
}
}
}
if (success) {
if (metadata == null) {
logger.warn("{} is missing a valid " + METADATA_FILE + " file." + "This is not a problem when testing plugins, however it is recommended to include one in public plugins.\n" + "Please see https://docs.spongepowered.org/master/en/plugin/plugin-meta.html for details.", path);
}
}
} else if (!classpath && mixinConfigs == null) {
logger.error("No valid plugins found in {}. Is the file actually a plugin JAR? Please keep in mind Forge mods can be only loaded on " + "SpongeForge servers, SpongeVanilla supports only Sponge plugins.", path);
}
}
Aggregations