use of org.spongepowered.plugin.metadata.PluginMetadata in project SpongeCommon by SpongePowered.
the class VanillaLaunch method createPlatformPlugins.
protected final void createPlatformPlugins() {
final String metadataFileLocation = this.pluginPlatform.metadataFilePath();
try {
// This is a bit nasty, but allows Sponge to detect builtin platform plugins when it's not the first entry on the classpath.
final URL classUrl = VanillaLaunch.class.getResource("/" + VanillaLaunch.class.getName().replace('.', '/') + ".class");
MetadataContainer read = null;
// In production, let's try to ensure we can find our descriptor even if we're not first on the classpath
if (classUrl.getProtocol().equals("jar")) {
// Extract the path of the underlying jar file, and parse it as a path to normalize it
final String[] classUrlSplit = classUrl.getPath().split("!");
final Path expectedFile = Paths.get(new URL(classUrlSplit[0]).toURI());
// Then go through every possible resource
final Enumeration<URL> manifests = VanillaLaunch.class.getClassLoader().getResources("/" + metadataFileLocation);
while (manifests.hasMoreElements()) {
final URL next = manifests.nextElement();
if (!next.getProtocol().equals("jar")) {
continue;
}
// And stop when the normalized jar in that resource matches the URL of the jar that loaded VanillaLaunch?
final String[] pathSplit = next.getPath().split("!");
if (pathSplit.length == 2) {
final Path vanillaPath = Paths.get(new URL(pathSplit[0]).toURI());
if (vanillaPath.equals(expectedFile)) {
try (final Reader reader = new InputStreamReader(next.openStream(), StandardCharsets.UTF_8)) {
read = MetadataParser.read(reader);
}
break;
}
}
}
}
if (read == null) {
// other measures failed, fall back to directly querying the classpath
final Path vanillaPath = Paths.get(VanillaLaunch.class.getResource("/" + metadataFileLocation).toURI());
try (final Reader reader = Files.newBufferedReader(vanillaPath, StandardCharsets.UTF_8)) {
read = MetadataParser.read(reader);
}
}
if (read == null) {
throw new RuntimeException("Could not determine location for implementation metadata!");
}
for (final PluginMetadata metadata : read.metadata()) {
this.pluginManager().addPlugin(new VanillaDummyPluginContainer(metadata, this.logger(), this));
}
} catch (final IOException | URISyntaxException e) {
throw new RuntimeException("Could not load metadata information for the implementation! This should be impossible!");
}
}
use of org.spongepowered.plugin.metadata.PluginMetadata in project SpongeCommon by SpongePowered.
the class CrashReportMixin_Vanilla method vanilla$addPluginsToEnvironment.
@Inject(method = "initDetails", at = @At("RETURN"))
private void vanilla$addPluginsToEnvironment(final CallbackInfo ci) {
this.systemDetails.setDetail("Plugins", () -> {
final StringBuilder result = new StringBuilder(64);
for (final PluginContainer container : Sponge.pluginManager().plugins()) {
final PluginMetadata metadata = container.metadata();
final String name = metadata.name().orElse(metadata.id());
result.append("\n\t\t").append(name).append(" (").append(metadata.id()).append(") ").append(metadata.version());
}
return result.toString();
});
}
use of org.spongepowered.plugin.metadata.PluginMetadata in project SpongeCommon by SpongePowered.
the class PluginFileConfigurable method getConfigList.
@Override
public List<? extends IConfigurable> getConfigList(final String... key) {
if (key.length < 1) {
return Collections.emptyList();
}
final String query = key[0];
if (key.length != this.requiredConfigElements(query)) {
return Collections.emptyList();
}
if ("mods".equals(query)) {
final Set<PluginMetadata> metadataById = this.container.metadata();
if (metadataById.isEmpty()) {
return Collections.emptyList();
}
final List<IConfigurable> metadataConfigurables = new ArrayList<>();
metadataById.forEach((metadata) -> metadataConfigurables.add(new PluginMetadataConfigurable(metadata)));
return metadataConfigurables;
}
if (key.length != 2) {
return Collections.emptyList();
}
final String plugin = key[1];
final PluginMetadata metadata = this.container.metadata(plugin).orElse(null);
if (metadata == null) {
return Collections.emptyList();
}
if ("dependencies".equals(query)) {
// TODO Should we inject a dependency on SpongeForge?
final Set<PluginDependency> dependencies = metadata.dependencies();
if (dependencies.isEmpty()) {
return Collections.emptyList();
}
final List<IConfigurable> depConfigurables = new ArrayList<>();
for (final PluginDependency dependency : dependencies) {
depConfigurables.add(new PluginDependencyConfigurable(metadata, dependency));
}
return depConfigurables;
}
return Collections.emptyList();
}
use of org.spongepowered.plugin.metadata.PluginMetadata in project SpongeCommon by SpongePowered.
the class PluginFileConfigurable method getConfigElement.
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> getConfigElement(final String... key) {
if (key.length < 1) {
return Optional.empty();
}
final String query = key[0];
if (key.length != this.requiredConfigElements(query)) {
return Optional.empty();
}
if ("modLoader".equals(query)) {
return (Optional<T>) Optional.of(this.container.loader().name());
}
if ("loaderVersion".equals(query)) {
return (Optional<T>) Optional.of(this.container.loader().version().toString());
}
if ("license".equals(query)) {
return (Optional<T>) Optional.of(this.container.license());
}
if (key.length == 2) {
final String plugin = key[1];
final PluginMetadata metadata = this.container.metadata(plugin).orElse(null);
if (metadata == null) {
return Optional.empty();
}
if ("modproperties".equals(query)) {
return (Optional<T>) Optional.of(metadata.properties());
}
}
return Optional.empty();
}
use of org.spongepowered.plugin.metadata.PluginMetadata in project SpongeCommon by SpongePowered.
the class SpongeCommand method versionExecutor.
@NonNull
private CommandResult versionExecutor(final CommandContext context) {
if (this.versionText == null) {
final PluginContainer platformPlugin = Launch.instance().platformPlugin();
final TextComponent.Builder builder = Component.text().append(Component.text(platformPlugin.metadata().name().get(), Style.style(NamedTextColor.YELLOW, TextDecoration.BOLD)));
final Component colon = Component.text(": ", NamedTextColor.GRAY);
for (final PluginContainer container : Launch.instance().launcherPlugins()) {
final PluginMetadata metadata = container.metadata();
builder.append(Component.newline(), SpongeCommand.INDENT_COMPONENT, Component.text(metadata.name().orElseGet(metadata::id), NamedTextColor.GRAY), colon, Component.text(container.metadata().version().toString()));
}
final String arch = System.getProperty("sun.arch.data.model");
final String javaArch = arch != null ? arch + "-bit" : "UNKNOWN";
final String javaVendor = System.getProperty("java.vendor");
final String javaVersion = System.getProperty("java.version");
final String osName = System.getProperty("os.name");
final String osVersion = System.getProperty("os.version");
final String osArch = System.getProperty("os.arch");
builder.append(Component.newline(), SpongeCommand.INDENT_COMPONENT, Component.text("JVM", NamedTextColor.GRAY), colon, Component.text(javaVersion + "/" + javaArch + " (" + javaVendor + ")"), Component.newline(), SpongeCommand.INDENT_COMPONENT, Component.text("OS", NamedTextColor.GRAY), colon, Component.text(osName + "/" + osVersion + " (" + osArch + ")"));
this.versionText = builder.build();
}
context.sendMessage(Identity.nil(), this.versionText);
return CommandResult.success();
}
Aggregations