From f550a2851efac4677abd69087245a3e74d966e98 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 19 Nov 2021 14:55:31 +0000 Subject: [PATCH] JAL-3553 now creating a json file for use on website. It's easier to parse all the info here than on the website! --- build.gradle | 76 +++++++++++++++++++++---- utils/install4j/install4j8_template.install4j | 2 +- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index c60c88a..89af47c 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ import java.security.MessageDigest import groovy.transform.ExternalizeMethods import groovy.util.XmlParser import groovy.xml.XmlUtil +import groovy.json.JsonBuilder import com.vladsch.flexmark.util.ast.Node import com.vladsch.flexmark.html.HtmlRenderer import com.vladsch.flexmark.parser.Parser @@ -1866,11 +1867,24 @@ clean { } } +task cleanInstallersDataFiles { + def installersOutputTxt = file("${jalviewDir}/${install4jBuildDir}/output.txt") + def installersSha256 = file("${jalviewDir}/${install4jBuildDir}/sha256sums") + def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_") + def installersJsonFile = file("${jalviewDir}/${install4jBuildDir}/installers-${VERSION_UNDERSCORES}.json") + doFirst { + delete installersOutputTxt + delete installersSha256 + delete installersJsonFile + } +} + task installerFiles(type: com.install4j.gradle.Install4jTask) { group = "distribution" description = "Create the install4j installers" dependsOn getdown dependsOn copyInstall4jTemplate + dependsOn cleanInstallersDataFiles projectFile = install4jConfFile @@ -1977,32 +1991,72 @@ task installerFiles(type: com.install4j.gradle.Install4jTask) { outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}") } -task addVersionToInstallersDataFiles { +def writeInstallersJsonFile(File installersOutputTxt, File installersSha256, File installersJsonFile) { + if ((!installersOutputTxt.exists()) || (install4jCheckSums && (!installersSha256))) { + throw new GradleException("One of the required input files doesn't exist.") + return null; + } + def hash = [:] + def idHash = [:] + installersOutputTxt.readLines().each { def line -> + if (line.startsWith("#")) { + return; + } + line.replaceAll("\n","") + def vals = line.split("\t") + def filename = vals[3] + filename = filename.replaceAll(/^.*\//, "") + hash[vals[0]] = [ "id" : vals[0], "os" : vals[1], "name" : vals[2], "file" : filename ] + idHash."${filename}" = vals[0] + } + if (install4jCheckSums) { + installersSha256.readLines().each { def line -> + if (line.startsWith("#")) { + return; + } + line.replaceAll("\n","") + def vals = line.split(/\s+\*?/) + def filename = vals[1] + def innerHash = (hash.(idHash."${filename}"))."sha256" = vals[0] + } + } + return installersJsonFile.write(new JsonBuilder(hash).toPrettyString()) +} + +task makeInstallersJsonFile { dependsOn installerFiles - def installersOutputTxt = "${jalviewDir}/${install4jBuildDir}/output.txt" - def installersOutputVersionTxt = "${jalviewDir}/${install4jBuildDir}/output-${JALVIEW_VERSION}.txt" - def installersSha256 = "${jalviewDir}/${install4jBuildDir}/sha256sums" - def installersSha256Version = "${jalviewDir}/${install4jBuildDir}/sha256sums-${JALVIEW_VERSION}" + def installersOutputTxt = file("${jalviewDir}/${install4jBuildDir}/output.txt") + def installersSha256 = file("${jalviewDir}/${install4jBuildDir}/sha256sums") + def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_") + def installersJsonFile = file("${jalviewDir}/${install4jBuildDir}/installers-${VERSION_UNDERSCORES}.json") inputs.file(installersOutputTxt) - outputs.file(installersOutputVersionTxt) if (install4jCheckSums) { inputs.file(installersSha256) - outputs.file(installersSha256Version) } + outputs.file(installersJsonFile) + + doFirst { + writeInstallersJsonFile(installersOutputTxt, installersSha256, installersJsonFile) + } +} +task staticMakeInstallersJsonFile { doFirst { - file(installersOutputVersionTxt).write(file(installersOutputTxt).text) - if (install4jCheckSums) { - file(installersSha256Version).write(file(installersSha256).text) + def output = findProperty("i4j_output") + def sha256 = findProperty("i4j_sha256") + def json = findProperty("i4j_json") + if (output == null || sha256 == null || json == null) { + throw new GradleException("Must provide paths to all of output.txt, sha256sums, and output.json with '-Pi4j_output=... -Pi4j_sha256=... -Pi4j_json=...") } + writeInstallersJsonFile(file(output), file(sha256), file(json)) } } task installers { dependsOn installerFiles - dependsOn addVersionToInstallersDataFiles + dependsOn makeInstallersJsonFile } diff --git a/utils/install4j/install4j8_template.install4j b/utils/install4j/install4j8_template.install4j index 21d6d1a..cf427c6 100644 --- a/utils/install4j/install4j8_template.install4j +++ b/utils/install4j/install4j8_template.install4j @@ -1255,7 +1255,7 @@ return console.askYesNo(message, true); - + -- 1.7.10.2