| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| buildscript { |
| //have to apply here for this to be applied at the right time |
| apply from: file("gradle/deps.gradle") |
| initScript(buildscript) |
| } |
| apply from: file("gradle/utils.gradle") |
| apply plugin: 'org.jbake.site' |
| apply plugin: 'io.freefair.jsass-base' |
| |
| loadGlobals(globalsFile) |
| |
| //to build up content, assets, etc which JBake can process for us, we need to process: |
| //SASS files |
| //JS files |
| //Image files |
| //Any other content we want to preprocess |
| //Content files such as .html and .md and .asciidoc which just need metadata/front matter |
| //GSP content templates which allow programming and replacement with Groovy templates |
| //and we need to place all of these files in the appropriate location for JBake to do its job |
| //...this means in either the content or the assets folders, and this will be the |
| //generatedAssetsDir and generatedContentDir |
| |
| jsass { |
| indent = ' ' |
| linefeed = System.lineSeparator() |
| omitSourceMapUrl = false |
| outputStyle = io.bit3.jsass.OutputStyle.COMPRESSED |
| precision = 3 |
| sourceComments = false |
| sourceMapContents = false |
| sourceMapEmbed = false |
| sourceMapEnabled = true |
| } |
| |
| task compileContentSass(type: io.freefair.gradle.plugins.jsass.SassCompile, |
| description: "Compiles the projects SaSS files to the build directory.", |
| group: "Build") { |
| source = file("$contentDir/scss") |
| destinationDir = file("$generatedAssetDir/css") |
| exclude '_vendor/*.scss' |
| } |
| |
| task preprocessContentAssets(type: Copy, |
| description: "Pre-processes all .css, .js (not in the minimize list), images, etc from the content directory into the generated assets directory", |
| group: "Build") { |
| into generatedAssetDir |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| |
| from(contentDir) { |
| exclude(["/templates/**"]) |
| include "**/*.cgi", |
| "**/*.css", |
| "**/css/*.css", |
| "dtds/**", |
| "ns/**", |
| "fonts/**", |
| "**/*.gif", |
| "**/.htaccess", |
| "**/sitemap.xml.gz", |
| "**/robots.txt", |
| "**/*.jpeg", |
| "**/*.jpg", |
| "**/*.js", |
| "**/*.png", |
| "**/*.svg", |
| "**/*.ttf", |
| "**/*.woff", |
| "**/doap_NetBeans.rdf" |
| } |
| from(contentDir_old) { |
| include "**/*.jpeg", |
| "**/*.jpg", |
| "**/*.js", |
| "**/*.png", |
| "**/*.svg" |
| } |
| from("$contentDir/scss") { |
| into('css') |
| include "**/*.scss" |
| } |
| } |
| |
| task preprocessContentStaticsLanguage(type: Copy) { |
| from contentDir_ca |
| from contentDir_fr |
| from contentDir_ja |
| from contentDir_pt_BR |
| from contentDir_ru |
| from contentDir_zh_CN |
| from contentDir_old |
| |
| |
| into generatedContentDir |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| include "**/*.adoc" |
| exclude "kb/docs/**/section**" |
| } |
| |
| task preprocessContentStatics(type: Copy, |
| description: "Pre-processes all .html, .md, and possibly other files which have metadata/front matter in a side car file of the same name and extension with an extra .yml extension after that", |
| group: "Build") { |
| from contentDir |
| into generatedContentDir |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| include "**/*.html.yml", "**/*.md.yml", "**/*.html", "**/*.md", "**/*.asciidoc","**/*.adoc", "fonts/**", "**/.htaccess", "**/*.xml.gz", "**/*.txt", "**/.jbakeignore" |
| exclude "/templates/**", "/css/**", "fonts/**", "kb/docs/**/section**" |
| |
| def mergeList = [] |
| |
| eachFile { details -> |
| if(details.sourcePath.endsWith(".yml")) { |
| //we don't want to do anything else with this |
| //it will just be copied into the generated folder |
| //but will not be merged by |
| return |
| } |
| def contentFile = file("${contentDir}/${details.sourcePath}") |
| def ymlFile = file("${contentFile}.yml") |
| if(ymlFile.exists()) { |
| logger.info("Setting up merge for ${details.path}") |
| def mergeData = createMergeData(file("${generatedContentDir}/${details.path}.yml").absolutePath, |
| file("${generatedContentDir}/${details.path}").absolutePath) |
| mergeList << mergeData |
| } else { |
| logger.info("The content file ${contentFile} can not be merged because the corresponding YAML file ${ymlFile} was not found.") |
| } |
| } |
| doLast { |
| //let's merge up the metadata with the content yml+content from the merge map |
| mergeList.each { data -> |
| logger.info("Merging ${data.file} and ${data.yml}") |
| mergeContentAndMetadata(data) |
| } |
| } |
| } |
| |
| task preprocessTemplates(type: Copy, |
| description: "Pre-processes the templates for JBake to use for baking", |
| group: "Build") { |
| from templateDir |
| into generatedTemplateDir |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| include "**/*" |
| } |
| |
| task preprocessContentTemplates(type: Copy, |
| description: "Pre-processes the *.gsp and *.gsp.yml files under content for baking as Groovy templates; edit global.yml to add data used in content other than YAML front matter", |
| group: "Build") { |
| |
| def mergeList = [] |
| |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| |
| from contentDir |
| into generatedContentDir |
| |
| |
| //we need to do both of these to make sure we are or are not up to date |
| include "**/*.gsp", "**/*.gsp.yml" |
| |
| exclude "/templates/**" |
| |
| rename '(.*)\\.gsp', '$1' |
| |
| //expand the files using Groovy's SimpleTemplateEngine |
| //for processing content like templates are also processed |
| def props = [:] |
| props.putAll(globals) |
| expand props |
| |
| eachFile { details -> |
| if(details.sourcePath.endsWith(".yml")) { |
| //we don't want to do anything else with this |
| //it will just be copied into the generated folder |
| //but will not be merged by jbake as there will not |
| //be meta info |
| return |
| } |
| def contentFile = file("${contentDir}/${details.sourcePath}") |
| def ymlFile = file("${contentFile}.yml") |
| if(ymlFile.exists()) { |
| def mergeData = createMergeData(file("${generatedContentDir}/${details.path}.yml").absolutePath, |
| file("${generatedContentDir}/${details.path}").absolutePath) |
| mergeList << mergeData |
| } else { |
| throw new Exception("The content file ${contentFile} can not be processed because the corresponding YAML file ${ymlFile} was not found.") |
| } |
| } |
| doLast { |
| //let's merge up the metadata with the content yml+content from the merge map |
| mergeList.each { data -> |
| mergeContentAndMetadata(data) |
| } |
| } |
| |
| } |
| |
| task preprocessContent(dependsOn: ["compileContentSass", |
| "preprocessContentAssets", |
| "preprocessContentStatics", |
| "preprocessContentStaticsLanguage", |
| "preprocessTemplates", |
| "preprocessContentTemplates"], |
| description: "Runs all preprocess tasks to prepare for a bake", |
| group: "Build") { |
| |
| } |
| |
| jbake { |
| groovyTemplatesVersion = "${libs.groovy}" |
| version = "${libs.jbake}" |
| //the following vars are set the way they are because the way the jbake plugin works |
| srcDirName = generatedDirRelativePath |
| destDirName = bakedDirRelativePath |
| //this will cause builds to be faster as only changes will be baked, |
| //and since it is in the build directory, can be cleaned |
| configuration["db.store"]="local" |
| configuration["db.path"]=cacheDir.absolutePath |
| configuration.putAll(globals) |
| } |
| |
| bake.mustRunAfter preprocessContent |
| |
| task buildSite(dependsOn: ["preprocessContent", "bake"], |
| description: "Runs the site build: preprocessContent and bake", |
| group: "Build") { |
| |
| } |
| |
| build.dependsOn buildSite |
| |
| task run(type: JavaExec, group: "Run") { |
| |
| def wDir = new File(buildDir, "tomcat") |
| |
| doFirst { |
| wDir.mkdirs() |
| bakedDir.mkdirs() |
| } |
| |
| mainClass="TomcatMain" |
| classpath buildscript.configurations.classpath + files("${rootProject.projectDir}/buildSrc/build/classes/groovy/main") |
| args = [bakedDir, 8080, "SHUTDOWN", 8088] |
| workingDir = wDir |
| } |
| |
| task stop(type: JavaExec, group: "Run") { |
| mainClass="TomcatStopMain" |
| classpath buildscript.configurations.classpath + files("${rootProject.projectDir}/buildSrc/build/classes/groovy/main") |
| args = ["SHUTDOWN", 8082] |
| } |