diff options
| author | Leitwolf11 | 2026-11-05 16:49:57 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-11-05 16:49:57 +0300 |
| commit | 4a00a68309a3605dafedbc522569fc1b2c8aca1e (patch) | |
| tree | e643401461646dc1ef6f134c2348914f97756232 /apps/api/ViGet/TazelPluginDescriptor.cs | |
| parent | 35e09214817585007308bdbc26d877791843ab29 (diff) | |
| download | progmaweb-4a00a68309a3605dafedbc522569fc1b2c8aca1e.tar.gz | |
Take who a Tazel plugin is from the publish command
Tazel no longer puts a publisher, a name or a version into the
descriptor of a plugin JAR (plugin API 3): who a plugin is comes from
ViGet, which records it when the plugin is pushed, or from the path of
a localPlugin.
- viget publish-tazel-plugin takes <Publisher> <Name> <Version> <jar>.
- TazelPluginDescriptor.TryRead and TazelPluginPublishing.PublishAsync
take the three from the caller and check them as before: one
identifier each for publisher and name, an exact version of three to
five numbers.
- A descriptor that holds publisher, name or version is refused, with
the keys it names.
- ops/README.md shows the new command line.
Diffstat (limited to 'apps/api/ViGet/TazelPluginDescriptor.cs')
| -rw-r--r-- | apps/api/ViGet/TazelPluginDescriptor.cs | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/apps/api/ViGet/TazelPluginDescriptor.cs b/apps/api/ViGet/TazelPluginDescriptor.cs index 2433cc7..7cf3ca1 100644 --- a/apps/api/ViGet/TazelPluginDescriptor.cs +++ b/apps/api/ViGet/TazelPluginDescriptor.cs @@ -8,8 +8,9 @@ using System.Text.RegularExpressions; namespace Progmasoft.Progmaweb.Api.ViGet; /// <summary> -/// The descriptor of a Tazel plugin, <c>META-INF/tazel-plugin.properties</c> of its JAR, as Tazel reads it, with the -/// fields ViGet shows on the page of the plugin. +/// A Tazel plugin as ViGet publishes it: who it is, which the command that publishes it names, and the descriptor of +/// its JAR, <c>META-INF/tazel-plugin.properties</c>, as Tazel reads it, with the fields ViGet shows on the page of the +/// plugin. The descriptor names neither the publisher, the name nor the version. /// </summary> /// <param name="Publisher">The Progmasoft Account the plugin is published under.</param> /// <param name="Name">The name of the plugin; one identifier.</param> @@ -37,19 +38,41 @@ internal sealed partial record TazelPluginDescriptor( /// <summary>The service entry that names the class Tazel loads.</summary> public const string ServiceEntry = "META-INF/services/com.progmasoft.api.tazel.dsl.plugin.ProjectPlugin"; + /// <summary>The keys of who a plugin is, which its descriptor may not hold.</summary> + private static readonly string[] IdentityKeys = ["publisher", "name", "version"]; + /// <summary>Whether a text is one identifier, as Tazel requires of a publisher and a plugin name.</summary> public static bool IsIdentifier(string value) => IdentifierPattern().IsMatch(value); /// <summary>Whether a text is an exact version of three to five numbers, as Tazel requires of a plugin version.</summary> public static bool IsVersion(string value) => VersionPattern().IsMatch(value); - /// <summary>Reads and checks the descriptor of a plugin JAR.</summary> + /// <summary>Reads and checks the descriptor of a plugin JAR, published as the plugin the command names.</summary> /// <param name="jar">The bytes of the JAR.</param> + /// <param name="publisher">The publisher the command names.</param> + /// <param name="name">The name of the plugin the command names.</param> + /// <param name="version">The version the command names.</param> /// <param name="descriptor">The descriptor, when the JAR is a valid plugin.</param> /// <returns>Why the JAR is refused, or <see langword="null"/> when it is valid.</returns> - public static string? TryRead(byte[] jar, out TazelPluginDescriptor? descriptor) + public static string? TryRead( + byte[] jar, string publisher, string name, string version, out TazelPluginDescriptor? descriptor) { descriptor = null; + if (!IsIdentifier(publisher)) + { + return "The publisher must be one identifier."; + } + + if (!IsIdentifier(name)) + { + return "The name of the plugin must be one identifier."; + } + + if (!IsVersion(version)) + { + return "The version must be exact, of three to five numbers."; + } + IReadOnlyDictionary<string, string> properties; try { @@ -81,22 +104,11 @@ internal sealed partial record TazelPluginDescriptor( string? Text(string key) => properties.TryGetValue(key, out string? value) && !string.IsNullOrWhiteSpace(value) ? value.Trim() : null; - string? publisher = Text("publisher"); - string? name = Text("name"); - string? version = Text("version"); - if (publisher is null || !IsIdentifier(publisher)) - { - return "The descriptor needs a publisher that is one identifier."; - } - - if (name is null || !IsIdentifier(name)) - { - return "The descriptor needs a name that is one identifier."; - } - - if (version is null || !IsVersion(version)) + string[] identity = [.. IdentityKeys.Where(properties.ContainsKey)]; + if (identity.Length > 0) { - return "The descriptor needs an exact version of three to five numbers."; + return $"The descriptor names {string.Join(", ", identity)}; " + + "ViGet takes who a plugin is from the command that publishes it, so its JAR names none."; } if (!int.TryParse(Text("apiVersion"), out int apiVersion) || apiVersion < 1) |