GIT_BRANCH: gitBranch,
VERSION: JALVIEW_VERSION,
JAVA_VERSION: JAVA_VERSION,
- VERSION_UNDERSCORES: JALVIEW_VERSION_UNDERSCORES
+ VERSION_UNDERSCORES: JALVIEW_VERSION_UNDERSCORES,
+ DRAFT: "false",
+ JVL_HEADER: ""
]
def output = input
if (extras != null) {
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 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 releaseTemplateFile = file("${jalviewDir}/${releases_template}")
- def releasesTemplateFile = file("${jalviewDir}/${releases_template}")
- def whatsnewTemplateFile = file("${jalviewDir}/${whatsnew_template}")
+ def oldJvlFile = file("${jalviewDir}/${hugo_old_jvl}")
doFirst {
// specific release template for version archive
def givenChannel = null
def givenVersion = null
if (CHANNEL == "RELEASE") {
- def releasesHtmlFile = file("${helpSourceDir}/${releases_html}")
- //MD_PARSE
- if (releaseMdFile.exists()) {
- def inFrontMatter = false
- def itemComment = null
- def firstLine = true
- releaseMdFile.eachLine { line ->
- if (line.matches("---")) {
- def prev = inFrontMatter
- inFrontMatter = firstLine
- if (inFrontMatter != prev)
- return
- }
- if (inFrontMatter) {
- def m = null
- if (m = line =~ /^date:\s*([0-9\-]+)/) {
- givenDate = new Date().parse("yyyy-MM-dd", m[0][1])
- } else if (m = line =~ /^channel:\s*(\S+)/) {
- givenChannel = m[0][1]
- } else if (m = line =~ /^version:\s*(\S+)/) {
- givenVersion = m[0][1]
- }
- } else {
- changes += line+"\n"
- }
- firstLine = false
- }
- 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 content = releaseMdFile.text
+ 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 changesHugo = null
if (changes != null) {
changesHugo = '<div class="release_notes">\n\n'
section = section.replaceAll(/[^a-z0-9_\-]/, "")
changesHugo += "<div class=\"${section}\">\n\n"
inSection = true
- } else if (m = line =~ /^(\s*-\s*)<!--([^>]+)-->(.*)/) {
+ } else if (m = line =~ /^(\s*-\s*)<!--([^>]+)-->(.*?)(<br\/?>)?\s*$/) {
def comment = m[0][2].trim()
if (comment != "") {
comment = comment.replaceAll('"', """)
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
}
}
[
WHATSNEW: whatsnew,
CHANGES: changesHugo,
- DATE: givenDate.format("yyyy-MM-dd")
+ DATE: givenDate == null ? "" : givenDate.format("yyyy-MM-dd"),
+ DRAFT: givenDate == null ? "true" : "false",
+ JVL_HEADER: oldJvl.contains(JALVIEW_VERSION) ? "jvl: true" : ""
]
)
}
}
+ inputs.file(oldJvlFile)
inputs.dir(hugoTemplatesDir)
- inputs.file(releaseTemplateFile)
- inputs.file(releasesTemplateFile)
- inputs.file(whatsnewTemplateFile)
inputs.property("JALVIEW_VERSION", { JALVIEW_VERSION })
inputs.property("CHANNEL", { CHANNEL })
}
+def getMdDate(File mdFile) {
+ return mdFileComponents(mdFile, true)
+}
+
+def getMdSections(String content) {
+ def sections = [:]
+ def sectionContent = ""
+ def sectionName = null
+ content.eachLine { line ->
+ def m = null
+ if (m = line =~ /^##([^#].*)$/) {
+ if (sectionName != null) {
+ sections[sectionName] = sectionContent
+ sectionName = null
+ sectionContent = ""
+ }
+ sectionName = m[0][1].trim()
+ sectionName = sectionName.toLowerCase()
+ sectionName = sectionName.replaceAll(/ +/, "_")
+ sectionName = sectionName.replaceAll(/[^a-z0-9_\-]/, "")
+ } else if (sectionName != null) {
+ sectionContent += line+"\n"
+ }
+ }
+ return sections
+}
+
+task releasesTemplates {
+ def releasesTemplateFile = file("${jalviewDir}/${releases_template}")
+ def whatsnewTemplateFile = file("${jalviewDir}/${whatsnew_template}")
+ def releasesHtmlFile = file("${helpSourceDir}/${releases_html}")
+ def whatsnewHtmlFile = file("${helpSourceDir}/${whatsnew_html}")
+ def releasesMdDir = "${jalviewDir}/${releases_dir}"
+ def whatsnewMdDir = "${jalviewDir}/${whatsnew_dir}"
+
+ doFirst {
+ def releaseFiles = fileTree(dir: releasesMdDir, include: "release-*.md")
+ def releaseFilesDates = releaseFiles.collectEntries {
+ [(it): getMdDate(it)]
+ }
+ releaseFiles = releaseFiles.sort { a,b -> releaseFilesDates[a].compareTo(releaseFilesDates[b]) }
+
+ def releasesTemplate = releasesTemplateFile.text
+ def m = releasesTemplate =~ /(?s)__VERSION_LOOP_START__(.*)__VERSION_LOOP_END__/
+ def versionTemplate = m[0][1]
+
+ def versions = ""
+ releaseFiles.each { rFile ->
+ def (rMap, rContent) = mdFileComponents(rFile)
+
+ def vm = JALVIEW_VERSION =~ /^(.+)\.(\d+)$/
+ def branchVersion = m[0][1]
+ def minorVersion = m[0][2]
+ def displayDate = releaseFilesDates[rFile].format("d MMMMM yyyy")
+
+ def rContentSections = getMdSections(rContent)
+
+ def rVersion = versionTemplate
+ if (rVersion != "") {
+ rVersion = hugoTemplateSubstitutions(rVersion,
+ [
+ BRANCH_VERSION: branchVersion,
+ MINOR_VERSION: minorVersion,
+ DISPLAY_DATE: displayDate,
+ NEW_FEATURES: rContentSections["new_features"],
+ KNOWN_ISSUES: rContentSections["known_issues"]
+ ]
+ )
+ }
+
+ println("RVERSION='$rVersion'")
+
+
+ }
+ }
+
+ inputs.file(releasesTemplateFile)
+ inputs.file(whatsnewTemplateFile)
+ inputs.dir(releasesMdDir)
+ inputs.dir(whatsnewMdDir)
+ outputs.file(releasesHtmlFile)
+ outputs.file(whatsnewHtmlFile)
+}
+
task helppages {
dependsOn copyHelp