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:
Andrius Dagys 2019-02-22 16:48:28 +00:00 committed by Katelyn Baker
parent 136f6a6be6
commit b52c7a09a3
3 changed files with 22 additions and 11 deletions

View File

@ -233,6 +233,7 @@ allprojects {
jcenter() jcenter()
maven { url "$artifactory_contextUrl/corda-dependencies" } maven { url "$artifactory_contextUrl/corda-dependencies" }
maven { url 'https://jitpack.io' } maven { url 'https://jitpack.io' }
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
} }
configurations { configurations {

View File

@ -37,6 +37,8 @@ dependencies {
compile "org.eclipse.jetty:jetty-webapp:${jetty_version}" compile "org.eclipse.jetty:jetty-webapp:${jetty_version}"
compile "javax.servlet:javax.servlet-api:3.1.0" 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 // Jersey for JAX-RS implementation for use in Jetty
compile "org.glassfish.jersey.core:jersey-server:${jersey_version}" compile "org.glassfish.jersey.core:jersey-server:${jersey_version}"
compile "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}" compile "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}"

View File

@ -4,7 +4,8 @@ import io.github.classgraph.ClassGraph
import net.corda.core.internal.* import net.corda.core.internal.*
import net.corda.core.utilities.contextLogger import net.corda.core.utilities.contextLogger
import net.corda.testing.node.TestCordapp 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.nio.file.Path
import java.util.* import java.util.*
import java.util.concurrent.ConcurrentHashMap 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 { private fun buildCordappJar(projectRoot: Path): Path {
return projectRootToBuiltJar.computeIfAbsent(projectRoot) { 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 ...") log.info("Generating CorDapp jar from local project in $projectRoot ...")
val exitCode = ProcessBuilder(gradlew.toString(), "jar").directory(projectRoot.toFile()).inheritIO().start().waitFor() runGradleBuild(projectRoot)
check(exitCode == 0) { "Unable to generate CorDapp jar from local project in $projectRoot (exit=$exitCode)" }
val libs = projectRoot / "build" / "libs" val libs = projectRoot / "build" / "libs"
val jars = libs.list { it.filter { it.toString().endsWith(".jar") }.toList() }.sortedBy { it.attributes().creationTime() } val jars = libs.list { it.filter { it.toString().endsWith(".jar") }.toList() }.sortedBy { it.attributes().creationTime() }
checkNotNull(jars.lastOrNull()) { "No jars were built in $libs" } checkNotNull(jars.lastOrNull()) { "No jars were built in $libs" }
} }
} }
private fun findGradlewDir(path: Path): Path { private fun runGradleBuild(projectRoot: Path) {
var current = path val gradleConnector = GradleConnector.newConnector().apply {
while (true) { useBuildDistribution()
if ((current / "gradlew").exists() && (current / "gradlew.bat").exists()) { forProjectDirectory(projectRoot.toFile())
return current
} }
current = current.parent
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()
}
} }
} }