Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/apps/api
diff options
context:
space:
mode:
authorLeitwolf112026-11-05 16:49:57 +0300
committerLeitwolf112026-11-05 16:49:57 +0300
commit4a00a68309a3605dafedbc522569fc1b2c8aca1e (patch)
treee643401461646dc1ef6f134c2348914f97756232 /apps/api
parent35e09214817585007308bdbc26d877791843ab29 (diff)
downloadprogmaweb-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')
-rw-r--r--apps/api/ViGet/TazelPluginDescriptor.cs50
-rw-r--r--apps/api/ViGet/TazelPluginPublishing.cs11
-rw-r--r--apps/api/ViGet/ViGetCommand.cs10
3 files changed, 45 insertions, 26 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)
diff --git a/apps/api/ViGet/TazelPluginPublishing.cs b/apps/api/ViGet/TazelPluginPublishing.cs
index 02c1d6b..1c5cdee 100644
--- a/apps/api/ViGet/TazelPluginPublishing.cs
+++ b/apps/api/ViGet/TazelPluginPublishing.cs
@@ -53,18 +53,23 @@ internal sealed class TazelPluginPublishing(
public static string RelativePath(string publisher, string name, string version) =>
Path.Combine("dslplugins", "tazel", publisher, name, version, $"{name}-{version}.jar");
- /// <summary>Publishes the plugin in a JAR.</summary>
+ /// <summary>Publishes the plugin in a JAR as the version of a plugin of a publisher.</summary>
/// <param name="jar">The bytes of the JAR.</param>
+ /// <param name="publisher">The Progmasoft Account it is published under.</param>
+ /// <param name="name">The name of the plugin.</param>
+ /// <param name="version">The version it is published as.</param>
/// <param name="cancellationToken">Cancels the operation.</param>
/// <returns>The published descriptor, or why the JAR was refused.</returns>
- public async Task<PublishResult> PublishAsync(byte[] jar, CancellationToken cancellationToken)
+ public async Task<PublishResult> PublishAsync(
+ byte[] jar, string publisher, string name, string version, CancellationToken cancellationToken)
{
if (jar.LongLength > MaximumSize)
{
return Refused($"The JAR is larger than {MaximumSize / 1024 / 1024} MiB.");
}
- if (TazelPluginDescriptor.TryRead(jar, out TazelPluginDescriptor? descriptor) is { } invalid)
+ if (TazelPluginDescriptor.TryRead(jar, publisher, name, version, out TazelPluginDescriptor? descriptor) is
+ { } invalid)
{
return Refused(invalid);
}
diff --git a/apps/api/ViGet/ViGetCommand.cs b/apps/api/ViGet/ViGetCommand.cs
index ad99aee..f91f46f 100644
--- a/apps/api/ViGet/ViGetCommand.cs
+++ b/apps/api/ViGet/ViGetCommand.cs
@@ -7,7 +7,8 @@ namespace Progmasoft.Progmaweb.Api.ViGet;
/// <summary>
/// The commands that manage the Tazel plugin catalog on the server, while publishing is not open through the API:
-/// <c>viget publish-tazel-plugin &lt;jar&gt;</c> and <c>viget yank-tazel-plugin &lt;Publisher&gt; &lt;Name&gt;
+/// <c>viget publish-tazel-plugin &lt;Publisher&gt; &lt;Name&gt; &lt;Version&gt; &lt;jar&gt;</c>, which names who the
+/// plugin is because its JAR does not, and <c>viget yank-tazel-plugin &lt;Publisher&gt; &lt;Name&gt;
/// &lt;Version&gt; [--undo]</c>. They run with the configuration of the service, as its user.
/// </summary>
internal static class ViGetCommand
@@ -37,7 +38,7 @@ internal static class ViGetCommand
switch (args)
{
- case ["publish-tazel-plugin", string path]:
+ case ["publish-tazel-plugin", string publisher, string name, string version, string path]:
{
if (!File.Exists(path))
{
@@ -47,7 +48,8 @@ internal static class ViGetCommand
TazelPluginPublishing publishing = services.GetRequiredService<TazelPluginPublishing>();
PublishResult result = await publishing.PublishAsync(
- await File.ReadAllBytesAsync(path, cancellationToken), cancellationToken);
+ await File.ReadAllBytesAsync(path, cancellationToken), publisher, name, version,
+ cancellationToken);
if (!result.Published)
{
await errors.WriteLineAsync(result.Error);
@@ -77,7 +79,7 @@ internal static class ViGetCommand
}
default:
await errors.WriteLineAsync(
- "usage: viget publish-tazel-plugin <jar>\n" +
+ "usage: viget publish-tazel-plugin <Publisher> <Name> <Version> <jar>\n" +
" viget yank-tazel-plugin <Publisher> <Name> <Version> [--undo]");
return 2;
}