forked from NationalSecurityAgency/ghidra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpProject.gradle
185 lines (131 loc) · 5.36 KB
/
helpProject.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*****************************************************************************************
This file is a "mix-in" gradle script that individual gradle projects should include if they
have content for the Ghidra help system. A gradle project can include help support by adding
the following to its build.gradle file.
apply from: "$rootProject.projectDir/gradle/helpProject.gradle"
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.
*****************************************************************************************/
// The help modules must be configured first so that we can reference its runtime classpath
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"
helpIndexCompile project(path: ':Help', configuration: 'archives')
}
// 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. [gradle/helpProject.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. [gradle/helpProject.gradle]\n"
File helpRootDir = file('src/main/help/help')
File outputDir = file('build/help/main/help')
inputs.dir helpRootDir
outputs.dir outputDir
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 {
// this modules runtime classpath (contains jhall.jar)
classpath project(':Help').sourceSets.main.runtimeClasspath
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}"
}
}
// Task for finding unused images that are not referenced from Ghidra help files
task findUnusedHelp(type: JavaExec) {
group rootProject.GHIDRA_GROUP
description " Finds unused help images for this module. [gradle/helpProject.gradle]\n"
File helpRootDir = file('src/main/help/help')
File outputDir = file('build/help/main/help')
dependsOn configurations.helpPath
inputs.dir helpRootDir
main = 'help.validator.UnusedHelpImageFileFinder'
// args '-debug' // print debug info
doFirst {
classpath project(':Help').sourceSets.main.runtimeClasspath
// the current help dir to process
args "-hp"
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
// make sure generated help directories exist during prepdev so that the directories are created and
// eclipse doesn't complain about missing src directories.
rootProject.prepDev.dependsOn buildHelp