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
}
}
+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
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
}