- def PROCESS_FILES=[
- "AUTHORS",
- "CITATION",
- "FEATURETODO",
- "JAVA-11-README",
- "FEATURETODO",
- "LICENSE",
- "**/README",
- "THIRDPARTYLIBS",
- "TESTNG",
- "build.gradle",
- "gradle.properties",
- "**/*.java",
- "**/*.html",
- "**/*.xml",
- "**/*.gradle",
- "**/*.groovy",
- "**/*.properties",
- "**/*.perl",
- "**/*.sh",
- ]
- def INCLUDE_FILES=[
- ".classpath",
- ".settings/org.eclipse.buildship.core.prefs",
- ".settings/org.eclipse.jdt.core.prefs"
- ]
-
- from(jalviewDir) {
- exclude (EXCLUDE_FILES)
- include (PROCESS_FILES)
- filter(ReplaceTokens,
- beginToken: '$$',
- endToken: '$$',
- tokens: [
- 'Version-Rel': JALVIEW_VERSION,
- 'Year-Rel': getDate("yyyy")
- ]
- )
- }
- from(jalviewDir) {
- exclude (EXCLUDE_FILES)
- exclude (PROCESS_FILES)
- exclude ("appletlib")
- exclude ("**/*locales")
- exclude ("*locales/**")
- exclude ("utils/InstallAnywhere")
-
- exclude (getdown_files_dir)
- // getdown_website_dir and getdown_archive_dir moved to build/website/docroot/getdown
- //exclude (getdown_website_dir)
- //exclude (getdown_archive_dir)
-
- // exluding these as not using jars as modules yet
- exclude ("${j11modDir}/**/*.jar")
- }
- from(jalviewDir) {
- include(INCLUDE_FILES)
- }
-// from (jalviewDir) {
-// // explicit includes for stuff that seemed to not get included
-// include(fileTree("test/**/*."))
-// exclude(EXCLUDE_FILES)
-// exclude(PROCESS_FILES)
-// }
-
- from(file(buildProperties).getParent()) {
- include(file(buildProperties).getName())
- rename(file(buildProperties).getName(), "build_properties")
- filter({ line ->
- line.replaceAll("^INSTALLATION=.*\$","INSTALLATION=Source Release"+" git-commit\\\\:"+gitHash+" ["+gitBranch+"]")
- })
- }
-
- def sourceTarBuildDir = "${buildDir}/sourceTar"
- from(sourceTarBuildDir) {
- // this includes the appended RELEASE properties file
- }
-}
-
-task dataInstallersJson {
- group "website"
- description "Create the installers-VERSION.json data file for installer files created"
-
- mustRunAfter installers
- mustRunAfter shadowJar
- mustRunAfter sourceDist
- mustRunAfter getdownArchive
-
- def installersOutputTxt = file("${jalviewDir}/${install4jBuildDir}/output.txt")
- def installersSha256 = file("${jalviewDir}/${install4jBuildDir}/sha256sums")
-
- if (installersOutputTxt.exists()) {
- inputs.file(installersOutputTxt)
- }
- if (install4jCheckSums && installersSha256.exists()) {
- inputs.file(installersSha256)
- }
- [
- shadowJar.archiveFile, // executable JAR
- getdownVersionLaunchJvl, // version JVL
- sourceDist.archiveFile // source TGZ
- ].each { fileName ->
- if (file(fileName).exists()) {
- inputs.file(fileName)
- }
- }
-
- outputs.file(hugoDataJsonFile)
-
- doFirst {
- writeDataJsonFile(installersOutputTxt, installersSha256, hugoDataJsonFile)
- }
-}
-
-def hugoTemplateSubstitutions(String input, Map extras=null) {
- def replacements = [
- DATE: getDate("yyyy-MM-dd"),
- CHANNEL: propertiesChannelName,
- APPLICATION_NAME: applicationName,
- GIT_HASH: gitHash,
- GIT_BRANCH: gitBranch,
- VERSION: JALVIEW_VERSION,
- JAVA_VERSION: JAVA_VERSION,
- VERSION_UNDERSCORES: JALVIEW_VERSION_UNDERSCORES,
- DRAFT: "false",
- JVL_HEADER: ""
- ]
- def output = input
- if (extras != null) {
- extras.each{ k, v ->
- output = output.replaceAll("__${k}__", ((v == null)?"":v))
- }
- }
- replacements.each{ k, v ->
- output = output.replaceAll("__${k}__", ((v == null)?"":v))
- }
- return output
-}
-
-def mdFileComponents(File mdFile, def dateOnly=false) {
- def map = [:]
- def content = ""
- if (mdFile.exists()) {
- def inFrontMatter = false
- def firstLine = true
- mdFile.eachLine { line ->
- if (line.matches("---")) {
- def prev = inFrontMatter
- inFrontMatter = firstLine
- if (inFrontMatter != prev)
- return false
- }
- if (inFrontMatter) {
- def m = null
- if (m = line =~ /^date:\s*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/) {
- map["date"] = new Date().parse("yyyy-MM-dd HH:mm:ss", m[0][1])
- } else if (m = line =~ /^date:\s*(\d{4}-\d{2}-\d{2})/) {
- map["date"] = new Date().parse("yyyy-MM-dd", m[0][1])
- } else if (m = line =~ /^channel:\s*(\S+)/) {
- map["channel"] = m[0][1]
- } else if (m = line =~ /^version:\s*(\S+)/) {
- map["version"] = m[0][1]
- } else if (m = line =~ /^\s*([^:]+)\s*:\s*(\S.*)/) {
- map[ m[0][1] ] = m[0][2]
- }
- if (dateOnly && map["date"] != null) {
- return false
- }
- } else {
- if (dateOnly)
- return false
- content += line+"\n"
- }
- firstLine = false
- }
- }
- return dateOnly ? map["date"] : [map, content]
-}
-
-task hugoTemplates {
- group "website"
- description "Create partially populated md pages for hugo website build"
-
- def hugoTemplatesDir = file("${jalviewDir}/${hugo_templates_dir}")
- def hugoBuildDir = "${jalviewDir}/${hugo_build_dir}"
- def templateFiles = fileTree(dir: hugoTemplatesDir)
- def releaseMdFile = file("${jalviewDir}/${releases_dir}/release-${JALVIEW_VERSION_UNDERSCORES}.md")
- def whatsnewMdFile = file("${jalviewDir}/${whatsnew_dir}/whatsnew-${JALVIEW_VERSION_UNDERSCORES}.md")
- def oldJvlFile = file("${jalviewDir}/${hugo_old_jvl}")
- def jalviewjsFile = file("${jalviewDir}/${hugo_jalviewjs}")
-
- doFirst {
- // specific release template for version archive
- def changes = ""
- def whatsnew = null
- def givenDate = null
- def givenChannel = null
- def givenVersion = null
- if (CHANNEL == "RELEASE") {
- def (map, content) = mdFileComponents(releaseMdFile)
- givenDate = map.date
- givenChannel = map.channel
- givenVersion = map.version
- changes = content
- if (givenVersion != null && givenVersion != JALVIEW_VERSION) {
- throw new GradleException("'version' header (${givenVersion}) found in ${releaseMdFile} does not match JALVIEW_VERSION (${JALVIEW_VERSION})")
- }
-
- if (whatsnewMdFile.exists())
- whatsnew = whatsnewMdFile.text
- }
-
- def oldJvl = oldJvlFile.exists() ? oldJvlFile.collect{it} : []
- def jalviewjsLink = jalviewjsFile.exists() ? jalviewjsFile.collect{it} : []
-
- def changesHugo = null
- if (changes != null) {
- changesHugo = '<div class="release_notes">\n\n'
- def inSection = false
- changes.eachLine { line ->
- def m = null
- if (m = line =~ /^##([^#].*)$/) {
- if (inSection) {
- changesHugo += "</div>\n\n"
- }
- def section = m[0][1].trim()
- section = section.toLowerCase()
- section = section.replaceAll(/ +/, "_")
- section = section.replaceAll(/[^a-z0-9_\-]/, "")
- changesHugo += "<div class=\"${section}\">\n\n"
- inSection = true
- } else if (m = line =~ /^(\s*-\s*)<!--([^>]+)-->(.*?)(<br\/?>)?\s*$/) {
- def comment = m[0][2].trim()
- if (comment != "") {
- comment = comment.replaceAll('"', """)
- def issuekeys = []
- comment.eachMatch(/JAL-\d+/) { jal -> issuekeys += jal }
- def newline = m[0][1]
- if (comment.trim() != "")
- newline += "{{<comment>}}${comment}{{</comment>}} "
- newline += m[0][3].trim()
- if (issuekeys.size() > 0)
- newline += " {{< jal issue=\"${issuekeys.join(",")}\" alt=\"${comment}\" >}}"
- if (m[0][4] != null)
- newline += m[0][4]
- line = newline
- }
- }
- changesHugo += line+"\n"
- }
- if (inSection) {
- changesHugo += "\n</div>\n\n"
- }
- changesHugo += '</div>'
- }
-
- templateFiles.each{ templateFile ->
- def newFileName = string(hugoTemplateSubstitutions(templateFile.getName()))
- def relPath = hugoTemplatesDir.toPath().relativize(templateFile.toPath()).getParent()
- def newRelPathName = hugoTemplateSubstitutions( relPath.toString() )
-
- def outPathName = string("${hugoBuildDir}/$newRelPathName")
-
- copy {
- from templateFile
- rename(templateFile.getName(), newFileName)
- into outPathName
- }
-
- def newFile = file("${outPathName}/${newFileName}".toString())
- def content = newFile.text
- newFile.text = hugoTemplateSubstitutions(content,
- [
- WHATSNEW: whatsnew,
- CHANGES: changesHugo,
- DATE: givenDate == null ? "" : givenDate.format("yyyy-MM-dd"),
- DRAFT: givenDate == null ? "true" : "false",
- JALVIEWJSLINK: jalviewjsLink.contains(JALVIEW_VERSION) ? "true" : "false",
- JVL_HEADER: oldJvl.contains(JALVIEW_VERSION) ? "jvl: true" : ""
- ]
- )
- }