From 65fb757e198066b0166c5957b7f6eea66854ea57 Mon Sep 17 00:00:00 2001 From: Max Weber Date: Mon, 25 Jan 2021 20:24:56 -0700 Subject: [PATCH] package: add a default support url --- README.md | 6 ++-- .../runelite/pluginhub/packager/Plugin.java | 32 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 11f23a846..02aa8905f 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,12 @@ There are two methods to create an external plugin, you can either: ``` displayName=Helmet check author=dekvall - support=https://github.com/dekvall/helmet-check + support= description=Alerts you when you have nothing equipped in your head slot tags=hint,gear,head plugins=com.helmetcheck.HelmetCheckPlugin ``` - `support` is the URL you want players to use to leave feedback for your plugin; you can just use your repository for that. `tags` will make it easier to find your plugin when searching for related words. If you want to add multiple plugin files, the `plugins` field allows for comma separated values, but this is not usually needed. + `support` is the URL you want players to use to leave feedback for your plugin; by default this links to your repository. `tags` will make it easier to find your plugin when searching for related words. If you want to add multiple plugin files, the `plugins` field allows for comma separated values, but this is not usually needed. 11. Optionally, you can add an icon to be displayed alongside with your plugin. Place a file with the name `icon.png` no larger than 48x72 px at the root of the repository. @@ -69,7 +69,7 @@ There are two methods to create an external plugin, you can either: ![run-test](https://i.imgur.com/tKSQH5e.png) - 5. Edit `runelite-plugin.properties` with a support link and tags. `support` is the URL you want players to use to leave feedback for your plugin; you can just use your repository for that. `tags` will make it easier to find your plugin when searching for related words. If you want to add multiple plugin files, the `plugins` field allows for comma separated values, but this is not usually needed. + 5. Edit `runelite-plugin.properties` with a support link and tags. `support` is the URL you want players to use to leave feedback for your plugin; by default this links to your repository. `tags` will make it easier to find your plugin when searching for related words. If you want to add multiple plugin files, the `plugins` field allows for comma separated values, but this is not usually needed. 6. Optionally, you can add an icon to be displayed alongside with your plugin. Place a file with the name `icon.png` no larger than 48x72 px at the root of the repository. diff --git a/package/package/src/main/java/net/runelite/pluginhub/packager/Plugin.java b/package/package/src/main/java/net/runelite/pluginhub/packager/Plugin.java index 30ed57aa6..b8bd35bbe 100644 --- a/package/package/src/main/java/net/runelite/pluginhub/packager/Plugin.java +++ b/package/package/src/main/java/net/runelite/pluginhub/packager/Plugin.java @@ -65,6 +65,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -96,7 +97,7 @@ public class Plugin implements Closeable private static final long MAX_SRC_SIZE = 10 * MIB; private static final Pattern PLUGIN_INTERNAL_NAME_TEST = Pattern.compile("^[a-z0-9-]+$"); - private static final Pattern REPOSITORY_TEST = Pattern.compile("^https://github\\.com/.*\\.git$"); + private static final Pattern REPOSITORY_TEST = Pattern.compile("^(https://github\\.com/.*)\\.git$"); private static final Pattern COMMIT_TEST = Pattern.compile("^[a-fA-F0-9]{40}$"); private static final File TMP_ROOT; @@ -148,6 +149,7 @@ public class Plugin implements Closeable private final String repositoryURL; private final String commit; + private final String defaultSupportURL; @Getter private final ExternalPluginManifest manifest = new ExternalPluginManifest(); @@ -183,7 +185,8 @@ public class Plugin implements Closeable .withFile(pluginCommitDescriptor); } - if (!REPOSITORY_TEST.matcher(repositoryURL).matches()) + Matcher repoMatcher = REPOSITORY_TEST.matcher(repositoryURL); + if (!repoMatcher.matches()) { throw PluginBuildException.of(internalName, "repository is not an accepted url") .withFileLine(pluginCommitDescriptor, "repository=" + repositoryURL) @@ -204,6 +207,7 @@ public class Plugin implements Closeable return null; }); } + String repoRoot = repoMatcher.group(1); commit = (String) cd.remove("commit"); if (!COMMIT_TEST.matcher(commit).matches()) @@ -212,6 +216,8 @@ public class Plugin implements Closeable .withFileLine(pluginCommitDescriptor, "commit=" + commit); } + defaultSupportURL = repoRoot + "/tree/" + commit; + warning = (String) cd.remove("warning"); for (Map.Entry extra : cd.entrySet()) @@ -567,17 +573,19 @@ public class Plugin implements Closeable { String supportStr = (String) props.remove("support"); - if (!Strings.isNullOrEmpty(supportStr)) + if (Strings.isNullOrEmpty(supportStr)) { - try - { - manifest.setSupport(new URL(supportStr)); - } - catch (MalformedURLException e) - { - throw PluginBuildException.of(this, "support url is malformed", e) - .withFileLine(propFile, "support=" + supportStr); - } + supportStr = this.defaultSupportURL; + } + + try + { + manifest.setSupport(new URL(supportStr)); + } + catch (MalformedURLException e) + { + throw PluginBuildException.of(this, "support url is malformed", e) + .withFileLine(propFile, "support=" + supportStr); } }