From c81d0f24b5d9f05f0c663f708f7379f944b31f06 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Wed, 2 Mar 2022 10:43:51 -0700 Subject: [PATCH] Temporarily generate manifest for update site until v0.8.1 for the Gradle JOSM plugin is released Signed-off-by: Taylor Smock --- build.gradle | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 21e0037..54474b9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,11 @@ import groovy.xml.XmlParser import net.ltgt.gradle.errorprone.CheckSeverity +import org.openstreetmap.josm.gradle.plugin.config.JosmManifest import org.openstreetmap.josm.gradle.plugin.task.GeneratePluginList import java.nio.file.Files import java.nio.file.Paths +import java.util.stream.Collectors plugins { id "com.diffplug.spotless" version "6.3.0" @@ -275,6 +277,47 @@ spotbugsMain { } } +/** + * Create a manifest map + * @param manifest The manifest to convert + * @return The map + * @deprecated In v0.8.1 there will be a GenerateJarManifest class + */ +@Deprecated +Map createUpdateManifest(JosmManifest manifest) { + def returnMap = new TreeMap(); + // Required fields first + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_MIN_JOSM_VERSION, manifest.minJosmVersion, false) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_VERSION, project.version.toString(), false) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_MAIN_CLASS, manifest.mainClass, false) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_DESCRIPTION, manifest.description, false) + putIfNotNull(returnMap, JosmManifest.Attribute.AUTHOR, manifest.author) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_MIN_JAVA_VERSION, manifest.minJavaVersion) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_PLATFORM, manifest.platform) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_PROVIDES, manifest.provides) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_EARLY, manifest.loadEarly) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_ICON, manifest.iconPath) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_DEPENDENCIES, manifest.pluginDependencies) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_LOAD_PRIORITY, manifest.loadPriority) + putIfNotNull(returnMap, JosmManifest.Attribute.PLUGIN_CAN_LOAD_AT_RUNTIME, manifest.canLoadAtRuntime) + + return returnMap +} + +static putIfNotNull(Map map, JosmManifest.Attribute attribute, Object value, boolean optional = true) { + if (value instanceof Provider) { + value = value.getOrNull() + } + if (value instanceof Collection) { + value = (value as Collection).stream().map(Object::toString).collect(Collectors.joining(";")) + } + if (value != null && !value.toString().trim().isEmpty()) { + map.put(attribute.manifestKey, value.toString()); + } else if (!optional) { + throw new IllegalArgumentException("Attribute " + attribute.manifestKey + " cannot be null or empty"); + } +} + task generateSnapshotUpdateSite(type: GeneratePluginList) { dependsOn(tasks.processResources) @@ -289,7 +332,12 @@ task generateSnapshotUpdateSite(type: GeneratePluginList) { return "data:image/" + contentType + ";base64," + Base64.getEncoder().encodeToString(Files.readAllBytes(Paths.get(file.toURI()))); } } - it.addPlugin("$archivesBaseName-dev.jar", project.josm.manifest.createJosmPluginJarManifest(), new URL(pluginDownloadUrl)) + /** + * Generate a plugin jar manifest map + * @deprecated GenerateJarManifest.kt was added after v0.8.0 + */ + def manifest = createUpdateManifest(project.josm.manifest as JosmManifest) + it.addPlugin("$archivesBaseName-dev.jar", manifest, new URL(pluginDownloadUrl)) } }