use of org.spongepowered.plugin.meta.PluginMetadata in project SpongeVanilla by SpongePowered.
the class PluginScanner method scanClassFile.
private PluginCandidate scanClassFile(InputStream in, PluginSource source) throws IOException {
ClassReader reader = new ClassReader(in);
PluginClassVisitor visitor = new PluginClassVisitor();
try {
reader.accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
PluginMetadata metadata = visitor.getMetadata();
if (metadata == null) {
// Not a plugin class
return null;
}
return new PluginCandidate(visitor.getClassName().replace('/', '.'), source, metadata);
} catch (InvalidPluginException e) {
logger.error("Skipping invalid plugin {} from {}", visitor.getClassName(), source, e);
}
return null;
}
use of org.spongepowered.plugin.meta.PluginMetadata in project SpongeAPI by SpongePowered.
the class PluginProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
if (!roundEnv.errorRaised()) {
finish();
}
return false;
}
if (!ProcessorUtils.contains(annotations, Plugin.class)) {
return false;
}
for (Element e : roundEnv.getElementsAnnotatedWith(Plugin.class)) {
if (e.getKind() != ElementKind.CLASS) {
getMessager().printMessage(ERROR, "Invalid element of type " + e.getKind() + " annotated with @Plugin", e);
continue;
}
final TypeElement pluginElement = (TypeElement) e;
AnnotationWrapper<Plugin> annotation = AnnotationWrapper.of(pluginElement, Plugin.class);
final String id = annotation.get().id();
if (id.isEmpty()) {
getMessager().printMessage(ERROR, "Plugin ID cannot be empty", pluginElement, annotation.getMirror(), annotation.getValue("id"));
continue;
}
PluginMetadata meta = this.meta.remove(id);
if (meta == null) {
meta = new PluginMetadata(id);
}
PluginElement plugin = new PluginElement(pluginElement, annotation, meta);
// Check for conflicting plugin IDs
if (this.duplicates.contains(id) || this.plugins.containsKey(id)) {
PluginElement otherPlugin = this.plugins.remove(id);
if (otherPlugin != null) {
reportDuplicatePlugin(id, otherPlugin);
this.duplicates.add(id);
}
reportDuplicatePlugin(id, plugin);
continue;
}
this.plugins.put(id, plugin);
plugin.apply(getMessager());
}
return false;
}
use of org.spongepowered.plugin.meta.PluginMetadata in project LanternServer by LanternPowered.
the class InternalPluginContainer method readPluginInfo.
private static PluginMetadata readPluginInfo(String id, @Nullable String version) {
try {
final URL url = LanternClassLoader.get().getResource("data/" + id + "/plugin.info");
checkNotNull(url, "Missing plugin.info file for internal plugin %s", id);
final PluginMetadata metadata = InfoPluginContainer.readPluginInfo(id, url);
// Allow the version to be overwritten
if (version != null) {
metadata.setVersion(version);
}
return metadata;
} catch (IOException e) {
throw new RuntimeException("Failed to read plugin.info files for the internal plugins.");
}
}
use of org.spongepowered.plugin.meta.PluginMetadata in project LanternServer by LanternPowered.
the class AbstractAssetRepository method registerAsset.
Asset registerAsset(Object plugin, String id, URL url, Path file) {
final Optional<Asset> optAsset = this.loadedAssets.get(id);
if (optAsset != null) {
return optAsset.get();
}
PluginContainer pluginContainer;
if (plugin instanceof String) {
final String pluginId = (String) plugin;
// Attempt to find a plugin container that is assigned to the id,
// if not, create a plugin container that represents the plugin
// with the id.
pluginContainer = this.pluginManager.getPlugin(pluginId).orElse(null);
if (pluginContainer == null) {
// don't register a plugin in this case, just return a asset with a dummy one.
if (INFO_FILE_PATTERN.matcher(id).matches()) {
return new LanternAsset(new SimplePluginContainer(pluginId), id, url, file);
}
// Attempt to get plugin info from the repository, and use
// that to define the plugin container
final URL infoUrl = getAssetURL(Paths.get(DEFAULT_ASSET_DIR).resolve(pluginId).resolve("plugin.info"));
if (infoUrl != null) {
try {
final PluginMetadata pluginMetadata = InfoPluginContainer.readPluginInfo(pluginId, infoUrl);
// Construct a plugin container
pluginContainer = new InfoPluginContainer(pluginId, pluginMetadata);
} catch (IOException e) {
Lantern.getLogger().error("Failed to read plugin.info");
}
}
if (pluginContainer == null) {
// Generate a simple plugin container
pluginContainer = new SimplePluginContainer(pluginId);
}
// Register the plugin container
this.pluginManager.registerPlugin(pluginContainer);
Lantern.getLogger().info("Registered data pack plugin: {} {}", pluginContainer.getName(), pluginContainer.getVersion().orElse("unknown"));
}
} else {
// Search for the plugin container based on the instance
pluginContainer = this.pluginManager.fromInstance(plugin).get();
}
checkNotNull(pluginContainer);
final LanternAsset asset = new LanternAsset(pluginContainer, id, url, file);
this.loadedAssets.put(id, Optional.of(asset));
return asset;
}
Aggregations