mirror of
https://github.com/corda/corda.git
synced 2025-01-18 02:39:51 +00:00
CORDA-2668 - TestCordapp – use Gradle tooling API for builds (#4794)
TestCordapp – disable daemon on internal gradle process The TestCordappImpl runs gradle to build cordapp jars required for tests. The started gradle process reuses a Gradle daemon that's potentially already used for running the tests causing the JVM to die with SIGBUS.
This commit is contained in:
parent
136f6a6be6
commit
b52c7a09a3
@ -233,6 +233,7 @@ allprojects {
|
||||
jcenter()
|
||||
maven { url "$artifactory_contextUrl/corda-dependencies" }
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
|
||||
}
|
||||
|
||||
configurations {
|
||||
|
@ -37,6 +37,8 @@ dependencies {
|
||||
compile "org.eclipse.jetty:jetty-webapp:${jetty_version}"
|
||||
compile "javax.servlet:javax.servlet-api:3.1.0"
|
||||
|
||||
compile "org.gradle:gradle-tooling-api:4.10.1"
|
||||
|
||||
// Jersey for JAX-RS implementation for use in Jetty
|
||||
compile "org.glassfish.jersey.core:jersey-server:${jersey_version}"
|
||||
compile "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}"
|
||||
|
@ -4,7 +4,8 @@ import io.github.classgraph.ClassGraph
|
||||
import net.corda.core.internal.*
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import net.corda.testing.node.TestCordapp
|
||||
import org.apache.commons.lang.SystemUtils
|
||||
import org.gradle.tooling.GradleConnector
|
||||
import org.gradle.tooling.ProgressEvent
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@ -77,24 +78,31 @@ data class TestCordappImpl(val scanPackage: String, override val config: Map<Str
|
||||
|
||||
private fun buildCordappJar(projectRoot: Path): Path {
|
||||
return projectRootToBuiltJar.computeIfAbsent(projectRoot) {
|
||||
val gradlew = findGradlewDir(projectRoot) / (if (SystemUtils.IS_OS_WINDOWS) "gradlew.bat" else "gradlew")
|
||||
log.info("Generating CorDapp jar from local project in $projectRoot ...")
|
||||
val exitCode = ProcessBuilder(gradlew.toString(), "jar").directory(projectRoot.toFile()).inheritIO().start().waitFor()
|
||||
check(exitCode == 0) { "Unable to generate CorDapp jar from local project in $projectRoot (exit=$exitCode)" }
|
||||
runGradleBuild(projectRoot)
|
||||
|
||||
val libs = projectRoot / "build" / "libs"
|
||||
val jars = libs.list { it.filter { it.toString().endsWith(".jar") }.toList() }.sortedBy { it.attributes().creationTime() }
|
||||
checkNotNull(jars.lastOrNull()) { "No jars were built in $libs" }
|
||||
}
|
||||
}
|
||||
|
||||
private fun findGradlewDir(path: Path): Path {
|
||||
var current = path
|
||||
while (true) {
|
||||
if ((current / "gradlew").exists() && (current / "gradlew.bat").exists()) {
|
||||
return current
|
||||
}
|
||||
current = current.parent
|
||||
private fun runGradleBuild(projectRoot: Path) {
|
||||
val gradleConnector = GradleConnector.newConnector().apply {
|
||||
useBuildDistribution()
|
||||
forProjectDirectory(projectRoot.toFile())
|
||||
}
|
||||
|
||||
val projectConnection = gradleConnector.connect()
|
||||
val build = projectConnection.newBuild().apply {
|
||||
forTasks("jar")
|
||||
addProgressListener { event: ProgressEvent ->
|
||||
log.info(event.description)
|
||||
}
|
||||
}
|
||||
// Blocks until the build is complete
|
||||
build.run()
|
||||
projectConnection.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user