blob: e5892b6726bf8a1e2dd1e9af4fb7eed1ac782201 [file] [log] [blame]
/*
* 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
task compileContentSass(type: io.freefair.gradle.plugins.jsass.SassCompile,
description: "Compiles the projects SaSS files to the build directory.",
group: "Build") {
sourceDir = file("$contentDir/scss")
destinationDir = file("$generatedAssetDir/css")
// Compile netbeans.scss, which imports all requirements
includePaths = files(file("$contentDir/scss/netbeans.scss"))
// @TODO - source maps not currently working
omitSourceMapUrl = true
// Compress the generated CSS
outputStyle = io.bit3.jsass.OutputStyle.COMPRESSED
// Precission to 3 digits
precision = 3
}
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") {
from contentDir
into generatedAssetDir
filteringCharset 'UTF-8'
includeEmptyDirs false
include "**/*.js", "**/*.css", "**/css/*.css",
"dtds/**",
"**/*.png", "**/*.gif",
"**/*.jpeg", "**/*.jpg",
"**/*.svg", "**/*.ttf",
"**/*.woff", "**/.htaccess",
"fonts/**","**/*.cgi"
exclude "/templates/**"
}
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", "fonts/**", "**/.htaccess"
exclude "/templates/**", "/css/**", "fonts/**"
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",
"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") {
}
task("run", type: JavaExec, group: "Run", overwrite: true) {
def wDir = new File(buildDir, "tomcat")
doFirst {
wDir.mkdirs()
bakedDir.mkdirs()
}
main "TomcatMain"
classpath buildscript.configurations.classpath + files("${rootProject.projectDir}/buildSrc/build/classes/main")
args = [bakedDir, 8080, "SHUTDOWN", 8088]
workingDir = wDir
}
task("stop", type: JavaExec, group: "Run", overwrite: true) {
main "TomcatStopMain"
classpath buildscript.configurations.classpath + files("${rootProject.projectDir}/buildSrc/build/classes/main")
args = ["SHUTDOWN", 8082]
}
wrapper {
gradleVersion = libs.gradle
}