JAL-3449 Now parsing install4j XML file to edit values. Should be safer
authorBen Soares <bsoares@dundee.ac.uk>
Mon, 9 Dec 2019 00:35:54 +0000 (00:35 +0000)
committerBen Soares <bsoares@dundee.ac.uk>
Mon, 9 Dec 2019 00:35:54 +0000 (00:35 +0000)
build.gradle

index 32816f3..1e2c719 100644 (file)
@@ -4,7 +4,6 @@ import org.gradle.plugins.ide.eclipse.model.Output
 import org.gradle.plugins.ide.eclipse.model.Library
 import java.security.MessageDigest
 import groovy.transform.ExternalizeMethods
-import groovy.util.XmlSlurper
 import groovy.util.XmlParser
 import groovy.xml.XmlUtil
 
@@ -291,8 +290,8 @@ ext {
   windowsJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/windows-jre${JAVA_VERSION}/jre")
   windowsJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/windows-jre${JAVA_VERSION}.tar.gz")
   install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
-  install4jConfFileName = string("jalview-installers-java${JAVA_VERSION}.install4j")
-  install4jConfFile = string("${install4jDir}/${install4jConfFileName}")
+  install4jConfFileName = string("jalview-install4j-conf.install4j")
+  install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
   install4jHomeDir = install4j_home_dir
   if (install4jHomeDir.startsWith("~/")) {
     install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
@@ -464,7 +463,7 @@ eclipse {
 
         HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
 
-        sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
+        sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
           //don't want to add outputDir as eclipse is using its own output dir in bin/main
           if (it.isDirectory() || ! it.exists()) {
             // don't add dirs to classpath, especially if they don't exist
@@ -484,7 +483,6 @@ eclipse {
           }
         }
 
-        //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
         sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
           //no longer want to add outputDir as eclipse is using its own output dir in bin/main
           if (it.isDirectory() || ! it.exists()) {
@@ -1213,101 +1211,44 @@ install4j {
 }
 
 
-task copyInstall4jTemplate(type: Copy) {
-  dependsOn setGitVals
-
-  inputs.file("${install4jDir}/${install4j_template}")
-  inputs.file("${install4jDir}/${install4j_installer_file_associations}")
-  outputs.files(install4jConfFile)
-
-  from (install4jDir) {
-    include install4j_template
-    rename (install4j_template, install4jConfFileName)
-    // TODO change these ReplaceTokens to something better.  Possibly ${compiler:variables} but also the ant.replaceregexp below, or perhaps a proper xmldom parse
+task copyInstall4jTemplate {
 
-    /*
-    if (OSX_KEYPASS == "") {
-      filter(ReplaceTokens,
-        beginToken: 'codeSigning macEnabled="',
-        endToken: '"',
-        tokens: [
-          'true': 'codeSigning macEnabled="false"'
-        ]
-      )
-      filter(ReplaceTokens,
-        beginToken: 'runPostProcessor="true" ',
-        endToken: 'Processor',
-        tokens: [
-          'post': 'runPostProcessor="false" postProcessor'
-        ]
-      )
-    }
-    */
-  }
-  into install4jDir
+  def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
+  def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
+  inputs.file(install4jTemplateFile)
+  inputs.file(install4jFileAssociationsFile)
+  outputs.file(install4jConfFile)
 
   doLast {
-    // include file associations in installer
-    def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
-    def install4jFileAssociationsText = install4jFileAssociationsFile.text
-/*
-    ant.replaceregexp(
-      byline: false,
-      flags: "s",
-      match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
-      replace: install4jFileAssociationsText,
-      file: install4jConfFile
-    )
-*/
-
-    def install4jFileAssociations = new XmlParser().parseText('''
-<install4jFileAssociations>
-${install4jFileAssociationsText}
-</install4jFileAssociations>
-'''
-    )
-
-println("TEXT=${install4jFileAssociationsText}")
-println("ACTIONS")
-install4jFileAssociationsXml.action.each { a ->
-  println("ACTION="+XmlUtil.serialize(a))
-}
-
-
-    def install4j = new XmlParser().parse(install4jConfFile)
+    def install4j = new XmlParser().parse(install4jTemplateFile)
 
+    // turn off code signing if no OSX_KEYPASS
     if (OSX_KEYPASS == "") {
-      install4j.application.codeSigning.each { codeSigning ->
+      install4j.'**'.codeSigning.each { codeSigning ->
         codeSigning.'@macEnabled' = "false"
       }
-      install4j.mediaSets.windows.each { windows ->
+      install4j.'**'.windows.each { windows ->
         windows.'@runPostProcessor' = "false"
       }
     }
-    // reparse
-    //install4j = new XmlSlurper().parseText(XmlUtil.serialize(install4j))
 
-    install4j.'**'.action.each { a ->
+    // put file association actions where placeholder action is
+    def install4jFileAssociationsText = install4jFileAssociationsFile.text
+    def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
+    install4j.'**'.action.any { a ->
       if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
-        //a.replaceNode(install4jFileAssociationsXml.action[0])
+        def parent = a.parent()
+        parent.remove(a)
+        fileAssociationActions.each { faa ->
+            parent.append(faa)
+        }
+        // don't need to continue in .any loop once replacements have been made
+        return true
       }
     }
-    // reparse
-    //install4j = new XmlSlurper().parseText(XmlUtil.serialize(install4j))
-
-    file(install4jConfFile).text = XmlUtil.serialize(install4j)
 
-    /*
-    // include uninstaller applescript app files in dmg
-    def installerDMGUninstallerXml = file("$install4jDir/$install4j_DMG_uninstaller_app_files").text
-    ant.replaceregexp(
-    byline: false,
-    flags: "s",
-    match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
-    replace: installerDMGUninstallerXml,
-    file: install4jConfFile
-    )
-     */
+    // write install4j file
+    install4jConfFile.text = XmlUtil.serialize(install4j)
   }
 }
 
@@ -1322,10 +1263,13 @@ clean {
 task installers(type: com.install4j.gradle.Install4jTask) {
   group = "distribution"
   description = "Create the install4j installers"
+  dependsOn setGitVals
   dependsOn getdown
   dependsOn copyInstall4jTemplate
-  projectFile = file(install4jConfFile)
 
+  projectFile = install4jConfFile
+
+  // create an md5 for the input files to use as version for install4j conf file
   def install4jTemplateMd5 = ""
   def digest = MessageDigest.getInstance("MD5")
   digest.update(
@@ -1374,7 +1318,7 @@ task installers(type: com.install4j.gradle.Install4jTask) {
   }
 
   if (OSX_KEYPASS) {
-    macKeystorePassword=OSX_KEYPASS
+    macKeystorePassword = OSX_KEYPASS
   }
 
   doFirst {
@@ -1390,7 +1334,7 @@ task installers(type: com.install4j.gradle.Install4jTask) {
 }
 
 
-task sourceDist (type: Tar) {
+task sourceDist(type: Tar) {
   
   def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
   def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
@@ -1468,7 +1412,7 @@ task sourceDist (type: Tar) {
 }
 
 
-task helppages  {
+task helppages {
   dependsOn copyHelp
   dependsOn pubhtmlhelp