/* Convention for properties. Read from gradle.properties, use lower_case_underlines for property names. * For properties set within build.gradle, use camelCaseNoSpace. */ import org.apache.tools.ant.filters.ReplaceTokens 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 { dependencies { classpath "com.vladsch.flexmark:flexmark-all:0.62.0" } } plugins { id 'java' id 'application' id 'com.palantir.git-version' version '0.12.3' } // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use def string(Object o) { return o == null ? "" : o.toString() } def overrideProperties(String propsFileName, boolean output = false) { if (propsFileName == null) { return } def propsFile = file(propsFileName) if (propsFile != null && propsFile.exists()) { println("Using properties from file '${propsFileName}'") try { def p = new Properties() def localPropsFIS = new FileInputStream(propsFile) p.load(localPropsFIS) localPropsFIS.close() p.each { key, val -> def oldval if (project.hasProperty(key)) { oldval = project.findProperty(key) project.setProperty(key, val) if (output) { println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'") } } else { ext.setProperty(key, val) if (output) { println("Setting ext property '${key}' with ${file(propsFile).getName()}s value '${val}'") } } } } catch (Exception e) { println("Exception reading local.properties") e.printStackTrace() } } } ext { jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath() jalviewDirRelativePath = jalviewDir propertiesChannelName = "release" channelDir = string("${jalviewDir}/${channel_properties_dir}/${propertiesChannelName}") channelGradleProperties = string("${channelDir}/channel_gradle.properties") overrideProperties(channelGradleProperties, false) //// // Import releaseProps from the RELEASE file // or a file specified via JALVIEW_RELEASE_FILE if defined // Expect jalview.version and target release branch in jalview.release def releaseProps = new Properties(); def releasePropFile = findProperty("JALVIEW_RELEASE_FILE"); def defaultReleasePropFile = "${jalviewDirAbsolutePath}/RELEASE"; try { (new File(releasePropFile!=null ? releasePropFile : defaultReleasePropFile)).withInputStream { releaseProps.load(it) } } catch (Exception fileLoadError) { throw new Error("Couldn't load release properties file "+(releasePropFile==null ? defaultReleasePropFile : "from custom location: releasePropFile"),fileLoadError); } //// // Set JALVIEW_VERSION if it is not already set if (findProperty("JALVIEW_VERSION")==null || "".equals(JALVIEW_VERSION)) { JALVIEW_VERSION = releaseProps.get("jalview.version") } // essentials bareSourceDir = string(source_dir) sourceDir = string("${jalviewDir}/${bareSourceDir}") resourceDir = string("${jalviewDir}/${resource_dir}") bareTestSourceDir = string(test_source_dir) testDir = string("${jalviewDir}/${bareTestSourceDir}") classesDir = string("${jalviewDir}/${classes_dir}") useClover = false resourceClassesDir = classesDir testSourceDir = testDir testClassesDir = "${jalviewDir}/${test_output_dir}" buildProperties = string("${classesDir}/${build_properties_file}") getdownSetAppBaseProperty = false // whether to pass the appbase and appdistdir to the application install4jApplicationName = "${jalview_name}" def details = versionDetails() gitHash = details.gitHash gitBranch = details.branchName println("Using a ${CHANNEL} profile.") additional_compiler_args = [] // configure classpath/args for j8/j11 compilation if (JAVA_VERSION.equals("1.8")) { JAVA_INTEGER_VERSION = string("8") //libDir = j8libDir libDir = j11libDir libDistDir = j8libDir compile_source_compatibility = 1.8 compile_target_compatibility = 1.8 } else if (JAVA_VERSION.equals("11")) { JAVA_INTEGER_VERSION = string("11") libDir = j11libDir libDistDir = j11libDir compile_source_compatibility = 11 compile_target_compatibility = 11 } else { throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview") } resourceBuildDir = string("${buildDir}/resources") resourcesBuildDir = string("${resourceBuildDir}/resources_build") helpBuildDir = string("${resourceBuildDir}/help_build") docBuildDir = string("${resourceBuildDir}/doc_build") if (buildProperties == null) { buildProperties = string("${resourcesBuildDir}/${build_properties_file}") } buildingHTML = string("${jalviewDir}/${doc_dir}/building.html") helpParentDir = string("${jalviewDir}/${help_parent_dir}") helpSourceDir = string("${helpParentDir}/${help_dir}") helpFile = string("${helpBuildDir}/${help_dir}/help.jhm") // ENDEXT } sourceSets { main { java { srcDirs sourceDir outputDir = file(classesDir) } resources { srcDirs = [ resourcesBuildDir, docBuildDir, helpBuildDir ] } compileClasspath = files(sourceSets.main.java.outputDir) compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"]) compileClasspath = files(sourceSets.main.java.outputDir) compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"]) runtimeClasspath = compileClasspath runtimeClasspath += files(sourceSets.main.resources.srcDirs) } test { java { srcDirs testSourceDir outputDir = file(testClassesDir) } resources { srcDirs = useClover ? sourceSets.clover.resources.srcDirs : sourceSets.main.resources.srcDirs } compileClasspath = files( sourceSets.test.java.outputDir ) compileClasspath += useClover ? sourceSets.clover.compileClasspath : sourceSets.main.compileClasspath compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"]) runtimeClasspath = compileClasspath runtimeClasspath += files(sourceSets.test.resources.srcDirs) } /* test { java { srcDirs testSourceDir outputDir = file(testClassesDir) } resources { srcDirs = sourceSets.main.resources.srcDirs } compileClasspath = files( sourceSets.test.java.outputDir ) compileClasspath += sourceSets.main.compileClasspath compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["** REMOVE_THIS_GAP /*.jar"]) runtimeClasspath = compileClasspath } */ } compileJava { sourceCompatibility = compile_source_compatibility targetCompatibility = compile_target_compatibility options.compilerArgs = additional_compiler_args doFirst { print ("Setting target compatibility to "+compile_target_compatibility+"\n") } } compileTestJava { doFirst { sourceCompatibility = compile_source_compatibility targetCompatibility = compile_target_compatibility options.compilerArgs = additional_compiler_args print ("Setting target compatibility to "+targetCompatibility+"\n") } } clean { doFirst { delete sourceSets.main.java.outputDir } } cleanTest { doFirst { delete sourceSets.test.java.outputDir } } // format is a string like date.format("dd MMMM yyyy") def getDate(format) { def date = new Date() return date.format(format) } 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) ? "