Skip to content

Commit

Permalink
Merge feat-25-jml_in_ides
Browse files Browse the repository at this point in the history
Resolves #25
  • Loading branch information
bzp99 committed Apr 22, 2024
2 parents c14a312 + bb2b7df commit 7b36b72
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 55 deletions.
8 changes: 1 addition & 7 deletions smart-contract/hyperledger-fabric/v2/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
.idea/
out/
!**/src/main/**/out/
!**/src/test/**/out/
Expand Down
10 changes: 10 additions & 0 deletions smart-contract/hyperledger-fabric/v2/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ However, note that normally, you do not need to locally build the chaincode.
The [test network](../../../../test-network/README.adoc) will build generate this JAR as part of a [dockerized](https://www.docker.com/) build process.
Build directly only if you know what you are doing.

## Development

You most likely do not want to build with OpenJML for local development, eg in your IDE.
To disable OpenJML, simply set the `withoutOpenJML` Gradle property to `true`.
For example, in `gradle.properties`:

```properties
withoutOpenJML = "true"
```


## License

Expand Down
99 changes: 51 additions & 48 deletions smart-contract/hyperledger-fabric/v2/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ val downloadDir = layout.buildDirectory.dir("tmp/download")
val jmlavac = openJMLJavaHomeDir.file("bin/jmlavac")
val jmlava = openJMLJavaHomeDir.file("bin/jmlava")

val withoutOpenJML: String? by project
val noOpenJML: Boolean = withoutOpenJML != null && withoutOpenJML.toBoolean()

plugins {
application
id("com.github.johnrengelman.shadow") version "7.1.2"
Expand Down Expand Up @@ -49,72 +52,72 @@ dependencies {
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")
if (!noOpenJML) {
tasks.named<ShadowJar>("shadowJar") {
dependsOn(tasks.named("initOpenJML"))
}
}

// java {
// sourceCompatibility = JavaVersion.VERSION_17
// targetCompatibility = JavaVersion.VERSION_17
// }
tasks.test {
java {
executable = "$openJMLDir/bin/jmlava"
jvmArgs = listOf("-Dorg.jmlspecs.openjml.rac=exception")
}
}

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 =
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(
options.isFork = true
options.compilerArgs.addAll(
listOf(
"-jml", "-$mode", "-timeout", "30", "--nullable-by-default", "--specs-path", "specs/"))
options.forkOptions.javaHome = openJMLJavaHomeDir.asFile
"-jml", "-$mode", "-timeout", "30", "--nullable-by-default", "--specs-path", "specs/"))
options.forkOptions.javaHome = openJMLJavaHomeDir.asFile
}
}
}

configure<SpotlessExtension> {
java {
importOrder()
removeUnusedImports()
googleJavaFormat()
formatAnnotations()
toggleOffOn()
configure<SpotlessExtension> {
java {
importOrder()
removeUnusedImports()
googleJavaFormat()
formatAnnotations()
toggleOffOn()
}
kotlin {
target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt")
ktfmt()
}
kotlinGradle { ktfmt() }
}
kotlin {
target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt")
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")
}
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")
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
openJMLVersion = 0.17.0-alpha-15
withoutOpenJML = true

0 comments on commit 7b36b72

Please sign in to comment.