-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
112 lines (92 loc) · 3.38 KB
/
build.gradle.kts
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
/* Originally based on https://github.com/mingyang91/openjml-template */
import com.diffplug.gradle.spotless.SpotlessExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import hu.bme.mit.ftsrg.openjmlhelper.*
import java.io.File
val openJMLDir = layout.projectDirectory.dir(".openjml")
val openJMLJavaHomeDir = openJMLDir.dir("jdk")
val downloadDir = layout.buildDirectory.dir(".tmp/download")
val jmlavac = openJMLJavaHomeDir.file("bin/jmlavac")
val jmlava = openJMLJavaHomeDir.file("bin/jmlava")
plugins {
application
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.diffplug.spotless") version "6.19.0"
}
group = "hu.bme.mit.ftsrg.tpcc"
version = "0.1.0"
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
dependencies {
implementation("org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.5.0")
implementation("org.hyperledger.fabric:fabric-protos:0.3.0")
implementation("org.json:json:20230227")
implementation("com.google.code.gson:gson:2.10.1")
// Included also as implementation dependency so shadow will package it
implementation(files("$openJMLDir/jmlruntime.jar"))
testImplementation("org.junit.jupiter:junit-jupiter:5.4.2")
testImplementation("org.assertj:assertj-core:3.11.1")
testImplementation("org.mockito:mockito-core:2.28.2")
testImplementation(files("$openJMLDir/jmlruntime.jar"))
}
application { mainClass.set("org.hyperledger.fabric.contract.ContractRouter") }
tasks.named<ShadowJar>("shadowJar") {
dependsOn(tasks.named("initOpenJML"))
archiveBaseName.set("chaincode")
archiveClassifier.set("")
archiveVersion.set("")
}
tasks.named<Test>("test") { useJUnitPlatform() }
tasks.test {
java {
executable = "$openJMLDir/bin/jmlava"
jvmArgs = listOf("-Dorg.jmlspecs.openjml.rac=exception")
}
}
// java {
// sourceCompatibility = JavaVersion.VERSION_17
// targetCompatibility = JavaVersion.VERSION_17
// }
tasks.withType<JavaCompile>().configureEach {
dependsOn(tasks.named("initOpenJML"))
// Only when not compiling because of Spotless
if (!gradle.startParameter.taskNames.any { it.contains("spotlessApply") }) {
val mode =
when (System.getenv("JML_MODE")) {
"esc" -> "esc"
else -> "rac"
}
options.isFork = true
options.compilerArgs.addAll(listOf("-jml", "-$mode", "-timeout", "30", "--nullable-by-default"))
options.forkOptions.javaHome = openJMLJavaHomeDir.asFile
}
}
configure<SpotlessExtension> {
java {
importOrder()
removeUnusedImports()
googleJavaFormat()
formatAnnotations()
}
kotlin {
target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt")
ktfmt()
}
kotlinGradle { ktfmt() }
}
tasks.register("initOpenJML") {
val openJMLVersion: String by project
val zipFile: File = downloadDir.get().file("openjml.zip").asFile
downloadOpenJML(openJMLVersion, zipFile, logger)
extractOpenJML(zipFile, openJMLDir, logger)
// `jmlavac' is what we call `javac' that is actually
// OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with
// OpenJML already in the classpath
generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger)
replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger)
generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger)
replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger)
logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir")
}