X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=build.gradle;h=147c31ad165b3db3373ef61cfd674a2bfec04deb;hb=refs%2Fheads%2Fmerge%2FJalview-JS%2Fdevelop_feature%2FJAL-3690_callback-based-web-services;hp=39c8261c8bd4b2ec269de7ed842c1d7a99f55504;hpb=ea5ada7a0847e79e6e48d42284002dfe06672a23;p=jalview.git diff --git a/build.gradle b/build.gradle index 39c8261..147c31a 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" + } } @@ -98,7 +110,7 @@ ext { } //// // Set JALVIEW_VERSION if it is not already set - if (findProperty(JALVIEW_VERSION)==null || "".equals(JALVIEW_VERSION)) { + if (findProperty("JALVIEW_VERSION")==null || "".equals(JALVIEW_VERSION)) { JALVIEW_VERSION = releaseProps.get("jalview.version") } @@ -445,7 +457,6 @@ ext { jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs") jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core") jalviewjsJalviewCoreHtmlFile = string("") - jalviewjsJalviewCoreName = string(jalviewjs_core_name) jalviewjsCoreClasslists = [] jalviewjsJalviewTemplateName = string(jalviewjs_name) jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}") @@ -1049,47 +1060,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 - } @@ -1790,7 +1864,7 @@ task sourceDist(type: Tar) { group "distribution" description "Create a source .tar.gz file for distribution" - dependsOn convertBuildingMD + dependsOn convertMdFiles def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_") def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz" @@ -2448,10 +2522,6 @@ task jalviewjsBuildAllCores { ] } - // _jmol and _jalview cores. Add any other peculiar classlist.txt files here - //classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ] - classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ] - jalviewjsCoreClasslists = [] classlistFiles.each { @@ -2474,8 +2544,8 @@ task jalviewjsBuildAllCores { } def list = fileTree(dir: j2sDir, includes: filelist) - def jsfile = "${outputDir}/core${name}.js" - def zjsfile = "${outputDir}/core${name}.z.js" + def jsfile = "${outputDir}/core_${name}.js" + def zjsfile = "${outputDir}/core_${name}.z.js" jalviewjsCoreClasslists += [ 'jsfile': jsfile, @@ -2490,21 +2560,8 @@ task jalviewjsBuildAllCores { outputs.file(zjsfile) } - // _stevesoft core. add any cores without a classlist here (and the inputs and outputs) - def stevesoftClasslistName = "_stevesoft" - def stevesoftClasslist = [ - 'jsfile': "${outputDir}/core${stevesoftClasslistName}.js", - 'zjsfile': "${outputDir}/core${stevesoftClasslistName}.z.js", - 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js"), - 'name': stevesoftClasslistName - ] - jalviewjsCoreClasslists += stevesoftClasslist - inputs.files(stevesoftClasslist['list']) - outputs.file(stevesoftClasslist['jsfile']) - outputs.file(stevesoftClasslist['zjsfile']) - // _all core - def allClasslistName = "_all" + def allClasslistName = "all" def allJsFiles = fileTree(dir: j2sDir, include: "**/*.js") allJsFiles += fileTree( dir: libJ2sDir, @@ -2527,8 +2584,8 @@ task jalviewjsBuildAllCores { ] ) def allClasslist = [ - 'jsfile': "${outputDir}/core${allClasslistName}.js", - 'zjsfile': "${outputDir}/core${allClasslistName}.z.js", + 'jsfile': "${outputDir}/core_${allClasslistName}.js", + 'zjsfile': "${outputDir}/core_${allClasslistName}.z.js", 'list': allJsFiles, 'name': allClasslistName ] @@ -2786,10 +2843,25 @@ task jalviewjsIDE_checkJ2sPlugin { if (eclipseHome == null || ! IN_ECLIPSE) { throw new StopExecutionException("Cannot find running Eclipse home from System.properties['eclipse.home.location']. Skipping J2S Plugin Check.") } - def eclipseJ2sPlugin = "${eclipseHome}/dropins/${j2sPluginFile.getName()}" - def eclipseJ2sPluginFile = file(eclipseJ2sPlugin) - if (!eclipseJ2sPluginFile.exists()) { - def msg = "Eclipse J2S Plugin is not installed (could not find '${eclipseJ2sPlugin}')\nTry running task jalviewjsIDE_copyJ2sPlugin" + def eclipseJ2sPluginDirs = [ "${eclipseHome}/dropins" ] + def altPluginsDir = System.properties["org.eclipse.equinox.p2.reconciler.dropins.directory"] + if (altPluginsDir != null && file(altPluginsDir).exists()) { + eclipseJ2sPluginDirs += altPluginsDir + } + def foundPlugin = false + def j2sPluginFileName = j2sPluginFile.getName() + def eclipseJ2sPlugin + def eclipseJ2sPluginFile + eclipseJ2sPluginDirs.any { dir -> + eclipseJ2sPlugin = "${dir}/${j2sPluginFileName}" + eclipseJ2sPluginFile = file(eclipseJ2sPlugin) + if (eclipseJ2sPluginFile.exists()) { + foundPlugin = true + return true + } + } + if (!foundPlugin) { + def msg = "Eclipse J2S Plugin is not installed (could not find '${j2sPluginFileName}' in\n"+eclipseJ2sPluginDirs.join("\n")+"\n)\nTry running task jalviewjsIDE_copyJ2sPlugin" System.err.println(msg) throw new StopExecutionException(msg) } @@ -2807,7 +2879,7 @@ task jalviewjsIDE_checkJ2sPlugin { System.err.println(msg) throw new StopExecutionException(msg) } else { - def msg = "Eclipse J2S Plugin is the same as '${j2sPlugin}' (this is good)" + def msg = "Eclipse J2S Plugin '${eclipseJ2sPlugin}' is the same as '${j2sPlugin}' (this is good)" println(msg) } }