ghidra/gradleScripts/buildHelp.gradle
2019-03-26 13:46:51 -04:00

152 lines
4.2 KiB
Groovy

/*
This gradle file is a 'script plugin'. That is, a script that provides features
meant to be used by other build files via an 'apply' call like so:
apply from: "$rootProject.projectDir/gradleScripts/buildHelp.gradle"
This call will pull in the tasks in this file. Clients can register dependencies
on other help modules by using the 'helpPath' configuration, like so:
helpPath project(path: ":Base", configuration: 'helpPath')
This example will put into the 'helpPath' configuration the project path of
'Base', using the value of it's 'helpPath' configuration. This brings us to the next
point--'helpPath' gets updated when the jar file is built to include the path of
the generated jar file. This allows future clients of a given help module to get
the jar file path of that help module's output.
*/
configurations {
// The Help Build System takes optional paths to resolve dependencies. Build files
// that use this 'script plugin' may put project paths into this variable.
helpPath
}
artifacts {
// The helpPath is updated to include the jar file output of the help build.
helpPath jar
}
sourceSets {
helpIndex {
java {
}
}
main {
resources {
srcDir 'src/main/help'
srcDir 'build/help/main'
}
}
}
dependencies {
helpIndexCompile "javax.help:javahelp:2.0.05"
}
// Task for calling the java help indexer, which creates a searchable index of the
// help contents.
task indexHelp(type: JavaExec) {
group "private"
description "indexes the helps files for this module. [gradleScripts/buildHelp.gradle]"
File helpRootDir = file('src/main/help/help')
File outputFile = file("build/help/main/help/${project.name}_JavaHelpSearch")
dependsOn configurations.helpPath
inputs.dir helpRootDir
outputs.dir outputFile
classpath = sourceSets.helpIndex.runtimeClasspath
main = 'com.sun.java.help.search.Indexer'
// tell the indexer where send its output
args '-db', outputFile.absolutePath
// The index has a config file parameter. The only thing we use in the config file
// is a root directory path that should be stripped off all the help references to
// make them relative instead of absolute
File configFile = file('build/helpconfig')
// gather up all the help files into a file collection
FileTree helpFiles = fileTree('src/main/help') {
include '**/*.htm'
include '**/*.html'
}
// pass the config file we created as an argument to the indexer
args '-c',"$configFile"
doFirst {
if (helpFiles.isEmpty()) {
// must have help to index
throw new GradleException("No help files found")
}
// create the config file when the task runs and not during configuration.
configFile.parentFile.mkdirs();
configFile.write "IndexRemove ${helpRootDir.absolutePath}" + File.separator + "\n"
// for each help file that was found, add it as an argument to the indexer
helpFiles.each { File file ->
args "${file.absolutePath}"
}
}
}
// Task for building Ghidra help files
// - depends on the output from the help indexer
task buildHelp(type: JavaExec, dependsOn: indexHelp) {
group rootProject.GHIDRA_GROUP
description " Builds the help for this module. [gradleScripts/buildHelp.gradle]\n"
File helpRootDir = file('src/main/help/help')
File outputDir = file('build/help/main/help')
inputs.dir helpRootDir
outputs.dir outputDir
// this modules runtime classpath (contains jhall.jar)
classpath = project(':Help').sourceSets.main.runtimeClasspath
main = 'help.GHelpBuilder'
args '-n', "${project.name}" // use the module's name for the help file name
args '-o', "${outputDir.absolutePath}" // set the output directory arg
// args '-debug' // print debug info
doFirst {
configurations.helpPath.each {
args "-hp"
args "${it.absolutePath}"
}
// The help dir to process. This needs to be the last argument to the process,
// thus, this is why it is inside of this block
args "${helpRootDir.absolutePath}"
}
}
// include the help into the module's jar
jar {
from "build/help/main" // include the generated help index files
from "src/main/help" // include the help source files
}
// build the help whenever this module's jar file is built
jar.dependsOn 'buildHelp'