forked from contiki-ng/cooja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
272 lines (249 loc) · 8.94 KB
/
build.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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
plugins {
id 'application'
id 'jvm-test-suite'
id 'com.diffplug.spotless' version '6.25.0'
id 'net.ltgt.errorprone' version '4.1.0'
}
group = 'org.contikios.cooja'
def javaVersion = 21
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
}
spotless {
java {
toggleOffOn()
// FIXME: gives unclosed string literal in ScriptRunner.java with spotless 6.23.3.
// removeUnusedImports()
importOrder()
// trimTrailingWhitespace()
// cleanthat()
// formatAnnotations()
// Use a different clang-format binary with -PclangFormat=clang-format-15.
// FIXME: make clang-format default in the future
// def clangFormatBinary = (String) project.findProperty('clangFormat') ?: 'clang-format'
def clangFormatBinary = (String) project.findProperty('clangFormat')
if (clangFormatBinary) {
try {
def clangOutput = new ByteArrayOutputStream()
exec {
commandLine clangFormatBinary, '--version'
standardOutput = clangOutput
}
def clangVersion = (String) (clangOutput.toString() =~ /\d+\.\d+\.\d+/)[0]
clangFormat(clangVersion).pathToExe(clangFormatBinary).style('file')
} catch (IndexOutOfBoundsException ignored) {
logger.warn("Failed to parse version when running '{} --version'", clangFormatBinary)
} catch (Exception e) {
logger.warn("Failed to run '{} --version': {}", clangFormatBinary, e.getMessage())
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation files('lib/jipv6.jar')
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
implementation 'ch.qos.logback:logback-classic:1.5.12'
// https://mvnrepository.com/artifact/com.github.cliftonlabs/json-simple
implementation 'com.github.cliftonlabs:json-simple:4.0.1'
// https://mvnrepository.com/artifact/com.formdev/flatlaf
implementation 'com.formdev:flatlaf:3.5.2'
// https://mvnrepository.com/artifact/de.sciss/syntaxpane
implementation 'de.sciss:syntaxpane:1.3.0'
// https://mvnrepository.com/artifact/info.picocli/picocli
implementation 'info.picocli:picocli:4.7.6'
// https://mvnrepository.com/artifact/info.picocli/picocli-codegen
annotationProcessor 'info.picocli:picocli-codegen:4.7.6'
// https://mvnrepository.com/artifact/org.jdom/jdom2
implementation 'org.jdom:jdom2:2.0.6.1'
// https://mvnrepository.com/artifact/org.jfree/jfreechart
implementation 'org.jfree:jfreechart:1.5.5'
// https://mvnrepository.com/artifact/org.openjdk.nashorn/nashorn-core
implementation 'org.openjdk.nashorn:nashorn-core:15.4'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
implementation 'org.slf4j:slf4j-api:2.0.16'
// https://mvnrepository.com/artifact/org.swinglabs.swingx/swingx-autocomplete
implementation 'org.swinglabs.swingx:swingx-autocomplete:1.6.5-1'
errorprone("com.google.errorprone:error_prone_core:2.35.1")
}
// FIXME: add test resources.
sourceSets {
data {
resources {
srcDirs = ['tools/coffee-manager']
include '*.properties'
}
}
main {
java {
srcDirs = ['java', 'tools/coffee-manager']
}
resources {
srcDirs = [data.resources, 'config']
}
}
}
application {
mainClass = 'org.contikios.cooja.Main'
applicationDefaultJvmArgs = ['-Xms400M', '-Xmx2048M',
// Several Contiki-NG tests crash the JVM without these flags with Java 17,
// 08-ipv6-unicast.csc is one example. Unclear why, the JVM should not
// do anything with the pointers in C-land part of ContikiMoteType.
'-XX:-UseCompressedOops', '-XX:-UseCompressedClassPointers',
// Enable the preview foreign function interface.
'--enable-preview', '--enable-native-access', 'ALL-UNNAMED']
}
testing {
suites {
configureEach {
dependencies {
implementation project()
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
implementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
runtimeOnly 'org.junit.platform:junit-platform-launcher'
}
}
test(JvmTestSuite) {
useJUnitJupiter()
testType = TestSuiteType.INTEGRATION_TEST
}
}
}
test {
reports {
junitXml {
outputPerTestCase = true
mergeReruns = true
}
}
testLogging {
events "failed", "passed", "skipped"
}
}
tasks.withType(JavaCompile).configureEach {
// ErrorProne is slow, only enable with ./gradlew build -Perrorprone.
options.errorprone.enabled = project.hasProperty('errorprone')
// Uncomment the next two lines and the disable line to generate a patch.
//options.errorprone.errorproneArgs = ['-XepPatchChecks:MissingOverride',
// '-XepPatchLocation:' + buildscript.sourceFile.getParent()]
options.errorprone.disable('AnnotateFormatMethod')
options.errorprone.disable('ByteBufferBackingArray')
options.errorprone.disable('CatchAndPrintStackTrace')
options.errorprone.disable('DefaultCharset')
options.errorprone.disable('DoubleCheckedLocking')
options.errorprone.disable('EmptyBlockTag')
options.errorprone.disable('EmptyCatch')
options.errorprone.disable('EqualsGetClass')
options.errorprone.disable('EqualsHashCode')
options.errorprone.disable('EqualsUnsafeCast')
options.errorprone.disable('ErroneousBitwiseExpression')
options.errorprone.disable('FallThrough')
options.errorprone.disable('FloatingPointLiteralPrecision')
options.errorprone.disable('HidingField')
options.errorprone.disable('ImmutableEnumChecker')
options.errorprone.disable('InconsistentCapitalization')
options.errorprone.disable('InlineMeSuggester')
options.errorprone.disable('JavaUtilDate')
options.errorprone.disable('JdkObsolete')
options.errorprone.disable('MissingCasesInEnumSwitch')
options.errorprone.disable('MissingSummary')
options.errorprone.disable('MutablePublicArray')
options.errorprone.disable('NarrowingCompoundAssignment')
options.errorprone.disable('NonApiType')
options.errorprone.disable('OperatorPrecedence')
options.errorprone.disable('ReferenceEquality')
options.errorprone.disable('StaticAssignmentInConstructor')
options.errorprone.disable('StringSplitter')
options.errorprone.disable('ThreadPriorityCheck')
options.errorprone.disable('UnusedMethod')
options.errorprone.disable('UnusedVariable')
options.compilerArgs += ['-Werror', '--enable-preview',
"-Aproject=${project.group}/${project.name}"]
String compilerArgs = project.findProperty('compilerArgs') as String
if (compilerArgs) {
compilerArgs.split().each { arg ->
options.compilerArgs << arg
}
}
}
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
tasks.register('copyDependencies', Copy) {
def dir = layout.buildDirectory.dir("libs/lib")
description = "Copy jar dependencies into ${dir.get()}"
group = "Build"
from configurations.runtimeClasspath.files
into dir
}
// Run Cooja with: java <JVM parameters> -jar build/libs/cooja.jar <Cooja parameters>
jar {
dependsOn copyDependencies
manifest {
attributes 'Main-Class': 'org.contikios.cooja.Main',
'Class-Path': '. ' + configurations.runtimeClasspath.files.collect { "lib/" + it.getName() }.join(' ')
}
}
tasks.register('fullJar', Jar) {
description = "Assembles a jar that contains all dependencies."
group = "Build"
archiveClassifier.set('full')
manifest {
attributes 'Main-Class': 'org.contikios.cooja.Main',
'Class-Path': '. ' + configurations.runtimeClasspath.files.collect { "lib/" + it.getName() }.join(' ')
}
from sourceSets.main.output
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
}
// Make startScripts use the fullJar and application settings.
tasks.named("startScripts") {
mainClass = application.mainClass
defaultJvmOpts = application.applicationDefaultJvmArgs
classpath = fullJar.outputs.files
doLast {
delete windowsScript
}
}
distributions {
main {
// Exclude default libraries and include fullJar instead.
contents {
exclude { FileTreeElement details ->
details.file.name.endsWith('.jar') && !details.file.name.contains('cooja-full')
}
into('lib') {
from fullJar
}
}
}
}
run {
// Bad Cooja location detected with gradle run, explicitly pass -cooja.
doFirst {
args += ['--cooja', "$projectDir"]
}
// Connect stdin to make the MSPSim CLI work, except when running in CI.
if (System.getenv('CI') == null) {
standardInput = System.in
}
// Pass all command line "-Dcooja.k=v" as "-Dk=v" to Cooja.
System.properties.each { k,v ->
if (k.startsWith("cooja.")) {
systemProperty k - "cooja.", v
}
}
systemProperty 'picocli.disable.closures', "true"
// Enable assertions with "-Passertions".
enableAssertions = project.hasProperty('assertions')
// Prevent Gradle from changing directory to tools/cooja.
workingDir = System.getProperty("user.dir")
}