blob: a5c8f1f691665a75518e9fdbe4eb5738e132de05 [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.
*/
import groovy.text.markup.MarkupTemplateEngine
import groovy.text.markup.TemplateConfiguration
import org.gradle.internal.logging.ConsoleRenderer
import util.CssFilter
import util.JsFilter
import util.CheckLinks
ext.watchmode = project.hasProperty('watchmode')?project.getProperty('watchmode'):'false'
// a collection of links which have either been validated or are dummy links
ext.excludeFromChecks = [
'http://issues.apache.org/jira',
'https://issues.apache.org/jira',
'target.html',
'foo.html',
'http://www.acme.com/cars',
'http://localhost:8080/groovy/hello.groovy'
]
apply plugin: 'base'
task copyAssets(type:Copy) {
from file('../site/src/site/assets')
into layout.buildDirectory.dir('site')
filesMatching('**/*.css') { f->
if (!f.name.contains('.min.')) {
filter(CssFilter)
}
}
filesMatching('**/*.js') { f->
if (!f.name.contains('.min.')) {
filter(JsFilter)
}
}
}
task copyReleaseNotesAssets(type:Copy) {
from file('../site/src/site/releasenotes/img')
into layout.buildDirectory.dir('site/releasenotes/img')
}
task generateSite(type:JavaExec) {
description = 'Generates the Groovy User Website'
dependsOn copyAssets
dependsOn copyReleaseNotesAssets
ext.sources = file('../site/src/site')
ext.outputDir = layout.buildDirectory.dir('site')
inputs.files fileTree(sources)
outputs.files fileTree(outputDir)
classpath = project(':generator').sourceSets.main.runtimeClasspath
mainClass = 'generator.SiteGenerator'
args = [sources, outputDir.get().asFile, 'sitemap-user.groovy', project.watchmode]
systemProperties.docs_baseurl = System.getProperty('docs_baseurl')
}
task checkDeadLinks(dependsOn: generateSite) {
description = 'Checks for dead links in the generated Groovy website'
ext.outputDir = layout.buildDirectory.dir('reports')
ext.reportFile = layout.buildDirectory.file('reports/deadlinks.html')
inputs.files fileTree(generateSite.outputDir)
outputs.file reportFile
doLast {
def baseDir = generateSite.outputDir.get().asFile
def checkLinks = new CheckLinks(baseDir: baseDir, excludeFromChecks: excludeFromChecks, logger: logger)
baseDir.eachFileRecurse {
if (it.name.endsWith('.html')) {
checkLinks.checkPage(it)
}
}
outputDir.get().asFile.mkdirs()
def tplConf = new TemplateConfiguration(autoIndent: true, autoNewLine: true)
def tplEngine = new MarkupTemplateEngine(this.class.classLoader, file('../site/gradle/templates'), tplConf)
def report = tplEngine.createTemplateByPath('deadlinks.groovy').make(deadLinks: checkLinks.deadLinks).toString()
def file = reportFile.get().asFile
file.write(report, 'utf-8')
def reportURL = new ConsoleRenderer().asClickableFileUrl(file)
logger.lifecycle "Dead links report written at $reportURL"
}
}
task webzip(type:Zip, dependsOn: checkDeadLinks) {
description = 'Creates a zip with the generated website and the deadlink report'
destinationDirectory = layout.buildDirectory.dir('distributions')
archiveBaseName = 'groovy'
archiveAppendix = 'website'
from(generateSite.outputDir) {
into 'site'
}
from (checkDeadLinks.outputDir) {
into 'reports'
}
}