JAL-3553 now creating a json file for use on website. It's easier to parse all the...
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 19 Nov 2021 14:55:31 +0000 (14:55 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 19 Nov 2021 14:55:31 +0000 (14:55 +0000)
build.gradle
utils/install4j/install4j8_template.install4j

index c60c88a..89af47c 100644 (file)
@@ -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
 }
 
 
index 21d6d1a..cf427c6 100644 (file)
@@ -1255,7 +1255,7 @@ return console.askYesNo(message, true);
     </styles>
   </installerGui>
   <mediaSets>
-    <windows name="Windows x64 EXE Installer" id="743" customizedId="WINDOWS-X64-EXE" mediaFileName="${compiler:APPLICATION_FOLDER}-${compiler:JALVIEW_VERSION}-${compiler:sys.platform}-java_${compiler:JAVA_INTEGER_VERSION}" installDir="${compiler:APPLICATION_FOLDER}" runPostProcessor="true" postProcessor="${compiler:JSIGN_SH} $EXECUTABLE" customInstallBaseDir="~/AppData/Local">
+    <windows name="Windows x64 Installer" id="743" customizedId="WINDOWS-X64-EXE" mediaFileName="${compiler:APPLICATION_FOLDER}-${compiler:JALVIEW_VERSION}-${compiler:sys.platform}-java_${compiler:JAVA_INTEGER_VERSION}" installDir="${compiler:APPLICATION_FOLDER}" runPostProcessor="true" postProcessor="${compiler:JSIGN_SH} $EXECUTABLE" customInstallBaseDir="~/AppData/Local">
       <excludedComponents>
         <component id="1155" />
         <component id="1156" />