JAL-3449 Work in progress improving XML replacements by gradle
authorBen Soares <bsoares@dundee.ac.uk>
Sun, 8 Dec 2019 21:09:10 +0000 (21:09 +0000)
committerBen Soares <bsoares@dundee.ac.uk>
Sun, 8 Dec 2019 21:09:10 +0000 (21:09 +0000)
build.gradle
utils/install4j/install4j8_template.install4j

index 37f1ad3..32816f3 100644 (file)
@@ -3,8 +3,10 @@ import org.gradle.internal.os.OperatingSystem
 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
 
 buildscript {
   dependencies {
@@ -1214,21 +1216,7 @@ install4j {
 task copyInstall4jTemplate(type: Copy) {
   dependsOn setGitVals
 
-  def install4jTemplateMd5 = ""
-  def digest = MessageDigest.getInstance("MD5")
-  digest.update(
-    (file("${install4jDir}/${install4j_template}").text + 
-    file("${install4jDir}/${install4j_info_plist_file_associations}").text +
-    file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
-  def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
-  if (filesMd5.length() >= 8) {
-    filesMd5 = filesMd5.substring(0,8)
-  }
-  install4jTemplateMd5 += filesMd5
-  install4jTemplateMd5 += "_${gitHash}"
-
   inputs.file("${install4jDir}/${install4j_template}")
-  inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
   inputs.file("${install4jDir}/${install4j_installer_file_associations}")
   outputs.files(install4jConfFile)
 
@@ -1236,6 +1224,8 @@ task copyInstall4jTemplate(type: Copy) {
     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
+
+    /*
     if (OSX_KEYPASS == "") {
       filter(ReplaceTokens,
         beginToken: 'codeSigning macEnabled="',
@@ -1252,19 +1242,61 @@ task copyInstall4jTemplate(type: Copy) {
         ]
       )
     }
+    */
   }
   into install4jDir
 
   doLast {
     // include file associations in installer
-    def installerFileAssociationsXml = file("${install4jDir}/${install4j_installer_file_associations}").text
+    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: installerFileAssociationsXml,
+      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)
+
+    if (OSX_KEYPASS == "") {
+      install4j.application.codeSigning.each { codeSigning ->
+        codeSigning.'@macEnabled' = "false"
+      }
+      install4j.mediaSets.windows.each { windows ->
+        windows.'@runPostProcessor' = "false"
+      }
+    }
+    // reparse
+    //install4j = new XmlSlurper().parseText(XmlUtil.serialize(install4j))
+
+    install4j.'**'.action.each { a ->
+      if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
+        //a.replaceNode(install4jFileAssociationsXml.action[0])
+      }
+    }
+    // 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
@@ -1307,28 +1339,30 @@ task installers(type: com.install4j.gradle.Install4jTask) {
   install4jTemplateMd5 += filesMd5
   install4jTemplateMd5 += "_${gitHash}"
   def install4jTemplateVersion = "${JALVIEW_VERSION}_${install4jTemplateMd5}"
+  def infoPlistFileAssociations = file("${install4jDir}/${install4j_info_plist_file_associations}").text
 
   variables = [
-   'OSX_KEYSTORE': OSX_KEYSTORE,
-   'JSIGN_SH': JSIGN_SH,
-   'JALVIEW_VERSION': JALVIEW_VERSION,
-   'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
-   'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
-   'JAVA_VERSION': JAVA_VERSION,
-   'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
-   'VERSION': JALVIEW_VERSION,
-   'MACOS_JAVA_VM_DIR': macosJavaVMDir,
-   'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
-   'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
-   'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
-   'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4j_info_plist_file_associations,
-   'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
-   'COPYRIGHT_MESSAGE': install4j_copyright_message,
-   'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
-   'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
-   'GETDOWN_DIST_DIR': getdown_app_dir,
-   'GETDOWN_ALT_DIR': getdown_app_dir_alt,
-   'GETDOWN_INSTALL_DIR': getdown_install_dir
+    'OSX_KEYSTORE': OSX_KEYSTORE,
+    'JSIGN_SH': JSIGN_SH,
+    'JALVIEW_VERSION': JALVIEW_VERSION,
+    'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
+    'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
+    'JAVA_VERSION': JAVA_VERSION,
+    'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
+    'VERSION': JALVIEW_VERSION,
+    'MACOS_JAVA_VM_DIR': macosJavaVMDir,
+    'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
+    'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
+    'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
+    'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4j_info_plist_file_associations,
+    'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
+    'COPYRIGHT_MESSAGE': install4j_copyright_message,
+    'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
+    'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
+    'GETDOWN_DIST_DIR': getdown_app_dir,
+    'GETDOWN_ALT_DIR': getdown_app_dir_alt,
+    'GETDOWN_INSTALL_DIR': getdown_install_dir,
+    'INFO_PLIST_FILE_ASSOCIATIONS': infoPlistFileAssociations
   ]
   destination = "${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}"
   buildSelected = true
@@ -1349,6 +1383,7 @@ task installers(type: com.install4j.gradle.Install4jTask) {
 
   inputs.dir(getdownWebsiteDir)
   inputs.file(install4jConfFile)
+  inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
   inputs.dir(macosJavaVMDir)
   inputs.dir(windowsJavaVMDir)
   outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
index de8b133..bd504f3 100644 (file)
@@ -29,6 +29,7 @@
       <variable name="GETDOWN_DIST_DIR" />
       <variable name="GETDOWN_ALT_DIR" />
       <variable name="GETDOWN_INSTALL_DIR" />
+      <variable name="INFO_PLIST_FILE_ASSOCIATIONS" />
     </variables>
     <codeSigning macEnabled="true" macPkcs12File="${compiler:OSX_KEYSTORE}" />
   </application>
           <scanDirectory location="${compiler:GETDOWN_INSTALL_DIR}" failOnError="false" />
         </classPath>
       </java>
+      <macStaticAssociationActions mode="selected" />
+      <infoPlist>${compiler:INFO_PLIST_FILE_ASSOCIATIONS}</infoPlist>
       <iconImageFiles>
         <file path="../../resources/images/JalviewLogo_Huge.png" />
       </iconImageFiles>
           <scanDirectory location="${compiler:GETDOWN_INSTALL_DIR}" failOnError="false" />
         </classPath>
       </java>
+      <macStaticAssociationActions mode="selected" />
+      <infoPlist>${compiler:INFO_PLIST_FILE_ASSOCIATIONS}</infoPlist>
       <iconImageFiles>
         <file path="../../resources/images/JalviewLogo_Huge.png" />
       </iconImageFiles>
         </classPath>
       </java>
       <macStaticAssociationActions mode="selected" />
+      <infoPlist>${compiler:INFO_PLIST_FILE_ASSOCIATIONS}</infoPlist>
       <iconImageFiles>
         <file path="../../resources/images/JalviewLogo_Huge.png" />
       </iconImageFiles>