forked from NationalSecurityAgency/ghidra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaProject.gradle
More file actions
257 lines (227 loc) · 8.21 KB
/
javaProject.gradle
File metadata and controls
257 lines (227 loc) · 8.21 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* ###
* IP: GHIDRA
*
* Licensed 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.
*/
/*****************************************************************************************
This file is a "mix-in" gradle script that individual gradle projects should include if they
have java code.
A gradle project can add java support by including the following to its build.gradle file:
apply from: "$rootProject.projectDir/gradle/support/distributableGhidraModule.gradle"
*****************************************************************************************/
import org.gradle.plugins.ide.eclipse.model.Container;
import org.gradle.plugins.ide.eclipse.model.Library;
/*********************************************************************************
* Subproject configuration
* - all subs will have access to these properties.
*********************************************************************************/
apply plugin: 'java-library'
// Rec 25: ratchet -Xlint back on.
//
// Was: -Xlint:none across compileJava + compileTestJava. That muted
// every javac warning in the tree and hid genuine bugs (the audit
// found dozens of obvious deprecation + unchecked-cast sites).
//
// Stage 1 (shipped earlier): -Xlint:deprecation,unchecked. First
// sweep to make warnings visible. No -Werror.
//
// Stage 2 (Sprint 8): widen to deprecation,unchecked,rawtypes,cast.
// rawtypes flags `List` vs `List<T>` usage; cast flags redundant
// casts. The build does NOT fail on warnings yet — this just
// surfaces the next ratchet level so we can measure the per-
// subproject count toward Stage 3 (pre-clean ≥50-warning
// subprojects, then -Werror promotion).
//
// To opt a single subproject out (temporary, while fixing its
// backlog), set `ext.lintOpts = ['none']` in that subproject's
// build.gradle.
// `-Xmaxwarns 0` removes javac's default cap of 100 warnings per compile.
// Sprint 9 Stage 3 prep: the cap hides the true count for the largest
// subprojects (Generic/Emulation/Features/Base were all at exactly 100
// in the post-Stage-2 master log — almost certainly all >100 with the
// rest truncated). We need accurate per-subproject counts before the
// `-Werror` flip so we know what to pre-clean. See
// docs/testing/STAGE3_ENUMERATION.md.
compileJava {
def lintOpts = project.hasProperty('lintOpts') ? project.lintOpts : ['deprecation', 'unchecked', 'rawtypes', 'cast']
options.compilerArgs << "-Xlint:${lintOpts.join(',')}".toString()
options.compilerArgs << '-XDignore.symbol.file'
options.compilerArgs << '-Xmaxwarns' << '0'
options.fork = true
options.warnings = true
}
compileTestJava {
def lintOpts = project.hasProperty('lintOpts') ? project.lintOpts : ['deprecation', 'unchecked', 'rawtypes', 'cast']
options.compilerArgs << "-Xlint:${lintOpts.join(',')}".toString()
options.compilerArgs << '-XDignore.symbol.file'
options.compilerArgs << '-Xmaxwarns' << '0'
options.fork = true
options.warnings = true
}
processResources {
duplicatesStrategy = 'exclude'
}
processTestResources {
duplicatesStrategy = 'exclude'
}
java {
sourceCompatibility = "${rootProject.JAVA_COMPILER}"
targetCompatibility = "${rootProject.JAVA_COMPILER}"
}
jar {
manifest {
attributes (
"Specification-Title": "${project.name}",
"Specification-Version": "${rootProject.RELEASE_VERSION}",
"Specification-Vendor": "Ghidra"
)
}
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
}
}
test {
java {
srcDir 'src/test/java'
}
resources {
srcDir 'src/test/resources'
}
}
integrationTest {
java {
srcDirs = ['src/test.slow/java'] // overwrite srcDir with new path
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
resources {
srcDirs = ['src/test.slow/resources']
}
}
screenShots {
java {
srcDir 'src/screen/java'
// Screenshots are essentially tests, and depend on classes in several other
// test directories so they must be included here
compileClasspath += main.output + test.output + integrationTest.output
runtimeClasspath += main.output + test.output + integrationTest.output
}
}
pcodeTest {
java {
srcDir 'src/test.processors/java'
compileClasspath += main.output
runtimeClasspath += main.output
}
resources {
srcDir 'src/test.processors/resources'
}
}
scripts {
java {
srcDir 'developer_scripts'
srcDir 'ghidra_scripts'
compileClasspath += main.output
}
}
}
configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly, integrationTestImplementation
pcodeTestImplementation.extendsFrom implementation
cspecTestImplementation.extendsFrom implementation
scriptsImplementation.extendsFrom implementation
testArtifacts.extendsFrom testRuntimeOnly
integrationTestArtifacts.extendsFrom integrationTestRuntimeOnly
screenShotsImplementation.extendsFrom integrationTestImplementation
}
task testJar(type: Jar) {
archiveClassifier.set("test") // value part of file name
from sourceSets.test.output
}
task integrationTestJar(type: Jar) {
archiveClassifier.set("integrationTest") // value part of file name
from sourceSets.integrationTest.output
}
artifacts {
testArtifacts testJar
integrationTestArtifacts integrationTestJar
}
/*
Provide test dependencies here so each build file does not have to.
*/
dependencies {
integrationTestImplementation "org.hamcrest:hamcrest:2.2"
testImplementation "org.hamcrest:hamcrest:2.2"
testImplementation "junit:junit:4.13.2"
pcodeTestImplementation "junit:junit:4.13.2"
cspecTestImplementation "junit:junit:4.13.2"
// Rec 27: Mockito for the next generation of unit tests. New tests
// should prefer Mockito over heavyweight real-Swing/real-Program
// setup; existing tests are migrated opportunistically.
// See docs/testing/MOCKITO_ADOPTION.md.
testImplementation "org.mockito:mockito-core:5.12.0"
testImplementation "org.mockito:mockito-junit-jupiter:5.12.0"
// Rec 29 Stage 1: add JUnit 5 (Jupiter) + the Vintage engine that
// runs JUnit 4 tests through the JUnit Platform. The above JUnit 4
// dependencies stay; existing tests are unchanged. New tests may
// be written in JUnit 5 immediately. See
// docs/testing/JUNIT5_MIGRATION.md.
testImplementation "org.junit.jupiter:junit-jupiter:5.10.2"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.10.2"
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.2"
}
// For Java 9, we must explicitly export references to the internal classes we are using.
// We export them to all "unnamed" modules, which are modules that don't define themselves
// as a new Java 9 style module. Ghidra is currently using unnamed modules everywhere.
ext.addExports = { List<String> exports ->
tasks.withType(JavaCompile) {
exports.each {
options.compilerArgs.addAll(['--add-exports', it])
}
}
eclipse.classpath.file.whenMerged { classpath ->
classpath.entries.each { ent ->
if (ent instanceof Container && ent.path.contains('JRE_CONTAINER')) {
ent.entryAttributes.put('module', true);
ent.entryAttributes.put('add-exports', exports.join(':'));
}
}
}
}
// Customize generated Eclipse projects
apply plugin: 'eclipse'
eclipse {
classpath {
// Expose test classes to dependent projects
containsTestFixtures = true
// Customizing which Eclipse source directories should be marked as test.
// Only screenShots must be added...test and integrationTest are automatically picked up.
// NOTE: When we upgrade to Gradle 7.5+, we can just set the "testSourceSets" property
file {
whenMerged { classpath ->
classpath.entries.findAll {
it.kind == 'src' && it.path.startsWith('src/screen/')
}.each {
it.entryAttributes['test'] = 'true'
}
}
}
}
}