From: Ben Soares Date: Tue, 5 Apr 2022 11:25:37 +0000 (+0100) Subject: JAL-3989 slight refactor of build.gradle, add more metadata to JSON file. Added some... X-Git-Tag: Release_2_11_2_6~64^2~22 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=db198a0eadd949de630aeef94c98321ffb6473f9 JAL-3989 slight refactor of build.gradle, add more metadata to JSON file. Added some commented out path changes to gradle.properties for future gathering of built files into more sensible places --- diff --git a/build.gradle b/build.gradle index 09efce1..4d2c350 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ import groovy.transform.ExternalizeMethods import groovy.util.XmlParser import groovy.xml.XmlUtil import groovy.json.JsonBuilder +import org.gradle.internal.hash.HashUtil import com.vladsch.flexmark.util.ast.Node import com.vladsch.flexmark.html.HtmlRenderer import com.vladsch.flexmark.parser.Parser @@ -44,6 +45,8 @@ plugins { id 'com.install4j.gradle' version '9.0.6' id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree id 'com.palantir.git-version' version '0.13.0' apply false +// id 'org.gradle.crypto.checksum' version '1.4.0' + } repositories { @@ -196,6 +199,7 @@ ext { getdownFullArchiveDir = null getdownTextLines = [] getdownLaunchJvl = null + getdownVersionLaunchJvl = null buildDist = true buildProperties = null @@ -1804,7 +1808,8 @@ task getdownArchiveBuild() { def v = "v${JALVIEW_VERSION_UNDERSCORES}" def vDir = "${getdownArchiveDir}/${v}" getdownFullArchiveDir = "${vDir}/getdown" - def vLaunchVersionJvl = "${vDir}/jalview-${v}.jvl" + getdownVersionLaunchJvl = "${vDir}/jalview-${v}.jvl" + def vAltDir = "alt_${v}" def archiveImagesDir = "${jalviewDir}/${channel_properties_dir}/old/images" @@ -1851,7 +1856,7 @@ task getdownArchiveBuild() { getdownArchiveTxt.write(getdownArchiveTextLines.join("\n")) - def vLaunchJvl = file(vLaunchVersionJvl) + def vLaunchJvl = file(getdownVersionLaunchJvl) vLaunchJvl.getParentFile().mkdirs() vLaunchJvl.write("appbase=${getdownFullArchiveAppBase}\n") def vLaunchJvlPath = vLaunchJvl.toPath().toAbsolutePath() @@ -2012,11 +2017,11 @@ 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") + def hugoDataJsonFile = file("${jalviewDir}/${install4jBuildDir}/installers-${VERSION_UNDERSCORES}.json") doFirst { delete installersOutputTxt delete installersSha256 - delete installersJsonFile + delete hugoDataJsonFile } } @@ -2132,7 +2137,17 @@ task installerFiles(type: com.install4j.gradle.Install4jTask) { outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}") } -def writeInstallersJsonFile(File installersOutputTxt, File installersSha256, File installersJsonFile) { +def getDataHash(File myFile) { + return myFile.exists() + ? [ + "filename" : myFile.getName(), + "filesize" : myFile.length(), + "sha256" : HashUtil.createHash(myFile, "SHA-256").asHexString() + ] + : null +} + +def writeDataJsonFile(File installersOutputTxt, File installersSha256, File hugoDataJsonFile) { if (!installersOutputTxt.exists()) { throw new GradleException("Required input file '${installersOutputTxt.getPath()}' doesn't exist.") return null; @@ -2141,7 +2156,12 @@ def writeInstallersJsonFile(File installersOutputTxt, File installersSha256, Fil throw new GradleException("Required input file '${installersSha256.getPath()}' doesn't exist.") return null; } - def hash = ["channel":getdownChannelName,"date":getDate("yyyy-MM-dd HH:mm:ss")] + def hash = [ + "channel" : getdownChannelName, + "date" : getDate("yyyy-MM-dd HH:mm:ss"), + "git-commit" : "${gitHash} [${gitBranch}]", + "version" : JALVIEW_VERSION + ] def idHash = [:] installersOutputTxt.readLines().each { def line -> if (line.startsWith("#")) { @@ -2166,36 +2186,26 @@ def writeInstallersJsonFile(File installersOutputTxt, File installersSha256, Fil def innerHash = (hash.(idHash."${filename}"))."sha256" = vals[0] } } - return installersJsonFile.write(new JsonBuilder(hash).toPrettyString()) -} - - -/* -ALSO COMPILE AND ADD IN TO THE JSON FILE INFO FOR EXECUTABLE JAR, VERSION JVL FILE, SOURCE TAR FILE -*/ + // executable JAR + def jarHash = getDataHash(file(shadowJar.archiveFile)) + if (jarHash != null) { + hash."JAR" = jarHash; + } - - - - -task makeInstallersJsonFile { - dependsOn installerFiles - - 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) - if (install4jCheckSums) { - inputs.file(installersSha256) + // version JVL + def jvlHash =getDataHash(file(getdownVersionLaunchJvl)) + if (jvlHash != null) { + hash."JVL" = jvlHash; } - outputs.file(installersJsonFile) - doFirst { - writeInstallersJsonFile(installersOutputTxt, installersSha256, installersJsonFile) + // source TGZ + def tarHash = getDataHash(file(sourceDist.archiveFile)) + if (tarHash != null) { + hash."SOURCE" = tarHash; } + + return hugoDataJsonFile.write(new JsonBuilder(hash).toPrettyString()) } task staticMakeInstallersJsonFile { @@ -2206,13 +2216,12 @@ task staticMakeInstallersJsonFile { 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)) + writeDataJsonFile(file(output), file(sha256), file(json)) } } task installers { dependsOn installerFiles - dependsOn makeInstallersJsonFile } @@ -2350,6 +2359,27 @@ task sourceDist(type: Tar) { } } +task makeDataJsonFile { + dependsOn installerFiles + dependsOn sourceDist + dependsOn getdownArchive + dependsOn shadowJar + + def installersOutputTxt = file("${jalviewDir}/${install4jBuildDir}/output.txt") + def installersSha256 = file("${jalviewDir}/${install4jBuildDir}/sha256sums") + def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_") + def hugoDataJsonFile = file("${jalviewDir}/${hugo_build_dir}/data/installers-${VERSION_UNDERSCORES}.json") + + inputs.file(installersOutputTxt) + if (install4jCheckSums) { + inputs.file(installersSha256) + } + outputs.file(hugoDataJsonFile) + + doFirst { + writeDataJsonFile(installersOutputTxt, installersSha256, hugoDataJsonFile) + } +} task helppages { dependsOn copyHelp diff --git a/gradle.properties b/gradle.properties index 2db8989..64790d0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -58,6 +58,12 @@ shadow_jar_main_class = jalview.bin.Launcher jalview_name = Jalview +hugo_build_dir = build/hugo +# these are going to be used in the future to gather website release files together +# getdown_website_dir = build/website/getdown/release +# getdown_archive_dir = build/website/old +# getdown_files_dir = build/getdown/files + getdown_local = false getdown_website_dir = getdown/website getdown_archive_dir = getdown/old