X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=build.gradle;h=0f4ad16bd58329358e0f3433f1a188db6a36468e;hb=refs%2Fheads%2Ffeature%2FJAL-3692enaEndpoint;hp=bd0ae207edd798ab27cf287eb36a174e5c5c705f;hpb=a02114f9eb9665810b4c1d89c9806dabcb2b4fd7;p=jalview.git diff --git a/build.gradle b/build.gradle index bd0ae20..0f4ad16 100644 --- a/build.gradle +++ b/build.gradle @@ -12,13 +12,25 @@ import java.security.MessageDigest import groovy.transform.ExternalizeMethods import groovy.util.XmlParser import groovy.xml.XmlUtil - +import com.vladsch.flexmark.util.ast.Node +import com.vladsch.flexmark.html.HtmlRenderer +import com.vladsch.flexmark.parser.Parser +import com.vladsch.flexmark.util.data.MutableDataSet +import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension +import com.vladsch.flexmark.ext.tables.TablesExtension +import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension +import com.vladsch.flexmark.ext.autolink.AutolinkExtension +import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension +import com.vladsch.flexmark.ext.toc.TocExtension buildscript { repositories { mavenCentral() mavenLocal() } + dependencies { + classpath "com.vladsch.flexmark:flexmark-all:0.62.0" + } } @@ -30,6 +42,7 @@ plugins { id 'com.github.johnrengelman.shadow' version '4.0.3' id 'com.install4j.gradle' version '8.0.4' 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.12.3' } repositories { @@ -148,7 +161,7 @@ ext { cloverBuildDir = "${buildDir}/clover" cloverInstrDir = file("${cloverBuildDir}/clover-instr") cloverClassesDir = file("${cloverBuildDir}/clover-classes") - cloverReportDir = file("${buildDir}/reports") + cloverReportDir = file("${buildDir}/reports/clover") cloverTestInstrDir = file("${cloverBuildDir}/clover-test-instr") cloverTestClassesDir = file("${cloverBuildDir}/clover-test-classes") //cloverTestClassesDir = cloverClassesDir @@ -346,8 +359,9 @@ ext { modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"]) modules_runtimeClasspath = modules_compileClasspath */ - gitHash = string("") - gitBranch = string("") + def details = versionDetails() + gitHash = details.gitHash + gitBranch = details.branchName println("Using a ${CHANNEL} profile.") @@ -733,6 +747,7 @@ eclipseGroovyCorePreferences.mustRunAfter eclipseJdt task cleanClover { doFirst { delete cloverBuildDir + delete cloverReportDir } } @@ -855,7 +870,7 @@ task cloverHtmlReport(type: JavaExec) { file(cloverDb).exists() } - def cloverHtmlDir = "${cloverReportDir}/clover" + def cloverHtmlDir = cloverReportDir inputs.dir cloverClassesDir outputs.dir cloverHtmlDir @@ -893,7 +908,7 @@ task cloverXmlReport(type: JavaExec) { file(cloverDb).exists() } - def cloverXmlFile = "${cloverReportDir}/clover/clover.xml" + def cloverXmlFile = "${cloverReportDir}/clover.xml" inputs.dir cloverClassesDir outputs.file cloverXmlFile @@ -990,33 +1005,10 @@ def getDate(format) { } -task setGitVals { - def hashStdOut = new ByteArrayOutputStream() - exec { - commandLine "git", "rev-parse", "--short", "HEAD" - standardOutput = hashStdOut - ignoreExitValue true - } - - def branchStdOut = new ByteArrayOutputStream() - exec { - commandLine "git", "rev-parse", "--abbrev-ref", "HEAD" - standardOutput = branchStdOut - ignoreExitValue true - } - - gitHash = hashStdOut.toString().trim() - gitBranch = branchStdOut.toString().trim() - - outputs.upToDateWhen { false } -} - - task createBuildProperties(type: WriteProperties) { group = "build" description = "Create the ${buildProperties} file" - dependsOn setGitVals inputs.dir(sourceDir) inputs.dir(resourceDir) file(buildProperties).getParentFile().mkdirs() @@ -1045,47 +1037,110 @@ task cleanBuildingHTML(type: Delete) { } -task convertBuildingMD(type: Exec) { +def convertMdToHtml (FileTree mdFiles, File cssFile) { + MutableDataSet options = new MutableDataSet() + + def extensions = new ArrayList<>() + extensions.add(AnchorLinkExtension.create()) + extensions.add(AutolinkExtension.create()) + extensions.add(StrikethroughExtension.create()) + extensions.add(TaskListExtension.create()) + extensions.add(TablesExtension.create()) + extensions.add(TocExtension.create()) + + options.set(Parser.EXTENSIONS, extensions) + + // set GFM table parsing options + options.set(TablesExtension.WITH_CAPTION, false) + options.set(TablesExtension.COLUMN_SPANS, false) + options.set(TablesExtension.MIN_HEADER_ROWS, 1) + options.set(TablesExtension.MAX_HEADER_ROWS, 1) + options.set(TablesExtension.APPEND_MISSING_COLUMNS, true) + options.set(TablesExtension.DISCARD_EXTRA_COLUMNS, true) + options.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true) + // GFM anchor links + options.set(AnchorLinkExtension.ANCHORLINKS_SET_ID, false) + options.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "anchor") + options.set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true) + options.set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "") + + Parser parser = Parser.builder(options).build() + HtmlRenderer renderer = HtmlRenderer.builder(options).build() + + mdFiles.each { mdFile -> + // add table of contents + def mdText = "[TOC]\n"+mdFile.text + + // grab the first top-level title + def title = null + def titleRegex = /(?m)^#(\s+|([^#]))(.*)/ + def matcher = mdText =~ titleRegex + if (matcher.size() > 0) { + // matcher[0][2] is the first character of the title if there wasn't any whitespace after the # + title = (matcher[0][2] != null ? matcher[0][2] : "")+matcher[0][3] + } + // or use the filename if none found + if (title == null) { + title = mdFile.getName() + } + + Node document = parser.parse(mdText) + String htmlBody = renderer.render(document) + def htmlText = ''' + + + + + + +''' + htmlText += ((title != null) ? " ${title}" : '' ) + htmlText += ''' + +''' + htmlText += ((cssFile != null) ? cssFile.text : '') + htmlText += ''' + +''' + htmlText += htmlBody + htmlText += ''' + + +''' + + def htmlFilePath = mdFile.getPath().replaceAll(/\..*?$/, ".html") + def htmlFile = file(htmlFilePath) + htmlFile.text = htmlText + } +} + + +task convertMdFiles { dependsOn cleanBuildingHTML - def buildingMD = "${jalviewDir}/${doc_dir}/building.md" - def css = "${jalviewDir}/${doc_dir}/github.css" + def mdFiles = fileTree(dir: "${jalviewDir}/${doc_dir}", include: "*.md") + def cssFile = file("${jalviewDir}/${flexmark_css}") - def pandoc = null - pandoc_exec.split(",").each { - if (file(it.trim()).exists()) { - pandoc = it.trim() - return true - } + doLast { + convertMdToHtml(mdFiles, cssFile) } - def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc" - if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) { - pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc" - } + inputs.files(mdFiles) + inputs.file(cssFile) - doFirst { - if (pandoc != null && file(pandoc).exists()) { - commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD - } else { - println("Cannot find pandoc. Skipping convert building.md to HTML") - throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML") - } + def htmlFiles = [] + mdFiles.each { mdFile -> + def htmlFilePath = mdFile.getPath().replaceAll(/\..*?$/, ".html") + htmlFiles.add(file(htmlFilePath)) } - - ignoreExitValue true - - inputs.file(buildingMD) - inputs.file(css) - outputs.file(buildingHTML) + outputs.files(htmlFiles) } task syncDocs(type: Sync) { - dependsOn convertBuildingMD + dependsOn convertMdFiles def syncDir = "${classesDir}/${doc_dir}" from fileTree("${jalviewDir}/${doc_dir}") into syncDir - } @@ -1308,6 +1363,7 @@ task cleanDist { shadowJar { group = "distribution" + description = "Create a single jar file with all dependency libraries merged. Can be run with java -jar" if (buildDist) { dependsOn makeDist } @@ -1683,7 +1739,6 @@ clean { task installers(type: com.install4j.gradle.Install4jTask) { group = "distribution" description = "Create the install4j installers" - dependsOn setGitVals dependsOn getdown dependsOn copyInstall4jTemplate @@ -1782,7 +1837,11 @@ spotless { task sourceDist(type: Tar) { + group "distribution" + description "Create a source .tar.gz file for distribution" + dependsOn convertMdFiles + def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_") def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz" // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09] @@ -2858,7 +2917,7 @@ task jalviewjsIDE_PrepareSite { description "Sync libs and resources to site dir, but not closure cores" dependsOn jalviewjsIDE_SyncSiteAll - dependsOn cleanJalviewjsTransferSite + //dependsOn cleanJalviewjsTransferSite // not sure why this clean is here -- will slow down a re-run of this task }