//this doesn't work yet. Don't know why. see issue #64
buildscript {
    repositories {
        maven {
            credentials {
                username mavenUsername
                password mavenPassword
            }
            url mavenRepository
        }
    }
    dependencies {
        classpath libs.html.sanity.check
    }
}

apply plugin: 'org.aim42.htmlSanityCheck'

// configuration
def config
if (docDir.startsWith('.')) {
    docDir = new File(projectDir, docDir).canonicalPath
}
logger.info "docToolchain> docDir: ${docDir}"
logger.info "docToolchain> mainConfigFile: ${mainConfigFile}"
logger.info "docToolchain> pdfThemeDir: ${pdfThemeDir}"
def configSlurper = new ConfigSlurper()
config = configSlurper.parse(new File(docDir, mainConfigFile).text)

//tag::htmlSanityCheck[]
htmlSanityCheck {
    sourceDir = new File(config.htmlSanityCheck.sourceDir?targetDir+"/"+config.htmlSanityCheck.sourceDir:"$targetDir/html5")
    // files to check - in Set-notation
    //sourceDocuments = [ "one-file.html", "another-file.html", "index.html"]

    // where to put results of sanityChecks...
    checkingResultsDir = new File(config.htmlSanityCheck.checkingResultsDir?:checkingResultsPath)
    // directory where the results written to in JUnit XML format
    junitResultsDir = new File(config.htmlSanityCheck.junitResultsDir?:"$targetDir/test-results/htmlchecks")

    // which statuscodes shall be interpreted as warning, error or success defaults to standard
    httpSuccessCodes = config.htmlSanityCheck.httpSuccessCodes?:[]
    httpWarningCodes = config.htmlSanityCheck.httpWarningCodes?:[]
    httpErrorCodes = config.htmlSanityCheck.httpErrorCodes?:[]

    // fail build on errors?
    failOnErrors = config.htmlSanityCheck.failOnErrors?:false

    logger.info "docToolchain> HSC sourceDir: ${sourceDir}"
    logger.info "docToolchain> HSC checkingResultsDir: ${checkingResultsDir}"
}
//end::htmlSanityCheck[]
project.afterEvaluate {
    project.tasks.htmlSanityCheck.dependsOn generateHTML
}


