From 2649981d16fda0d93935b6d8c55342b9d3e6d959 Mon Sep 17 00:00:00 2001 From: josecoll Date: Wed, 25 Sep 2019 11:48:57 +0100 Subject: [PATCH] CORDA-3224 Java 11 support tweaks. (#251) * Added support for corda artifacts published with jdkClassifier (eg. JDK11 support). * Support for multiple JDK versions on Macos. * Bump version label and added changelog entry. * Update changelog entry. * Revert version label + changelog update. * Add static regex declarations for corda versioned fat jar artifacts. * Address PR review feedback. --- changelog.md | 4 +++ .../kotlin/net/corda/plugins/Cordformation.kt | 5 ++-- .../main/resources/net/corda/plugins/runnodes | 7 +++-- .../kotlin/net/corda/plugins/CordformTest.kt | 28 +++++++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) mode change 100644 => 100755 cordformation/src/main/resources/net/corda/plugins/runnodes diff --git a/changelog.md b/changelog.md index 1600c565c3..87b67affd6 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,10 @@ ### Version 5.0.4 +* `cordformation`: remove hard dependency on java 1.8 for macos in runnodes (and allow for usage of JAVA_HOME if set) + +* `cordformation`: add support for classifier (eg. jdk11) in detection of corda runtime artifacts (eg. corda.jar, test-server.jar). + ### Version 5.0.3 * `quasar-utils`: Add `excludeClassLoaders` option to the `quasar` extension. This option requires Quasar 0.7.12_r3 and above, excluding 0.8.0. diff --git a/cordformation/src/main/kotlin/net/corda/plugins/Cordformation.kt b/cordformation/src/main/kotlin/net/corda/plugins/Cordformation.kt index 6be2d0550f..394faaf3b6 100644 --- a/cordformation/src/main/kotlin/net/corda/plugins/Cordformation.kt +++ b/cordformation/src/main/kotlin/net/corda/plugins/Cordformation.kt @@ -40,8 +40,10 @@ class Cordformation : Plugin { fun verifyAndGetRuntimeJar(project: Project, jarName: String): File { val releaseVersion = project.findRootProperty("corda_release_version") ?: throw IllegalStateException("Could not find a valid declaration of \"corda_release_version\"") + // need to cater for optional classifier (eg. corda-4.3-jdk11.jar) + val pattern = "\\Q$jarName\\E(-enterprise)?-\\Q$releaseVersion\\E(-.+)?\\.jar\$".toRegex() val maybeJar = project.configuration("runtime").filter { - "$jarName-$releaseVersion.jar" in it.toString() || "$jarName-enterprise-$releaseVersion.jar" in it.toString() + it.toString().contains(pattern) } if (maybeJar.isEmpty) { throw IllegalStateException("No $jarName JAR found. Have you deployed the Corda project to Maven? Looked for \"$jarName-$releaseVersion.jar\"") @@ -50,7 +52,6 @@ class Cordformation : Plugin { require(jar.isFile) { "$jar either does not exist or is not a file" } return jar } - } val executableFileMode = "0755".toInt(8) diff --git a/cordformation/src/main/resources/net/corda/plugins/runnodes b/cordformation/src/main/resources/net/corda/plugins/runnodes old mode 100644 new mode 100755 index 9e3ba4c5be..4fb22b482e --- a/cordformation/src/main/resources/net/corda/plugins/runnodes +++ b/cordformation/src/main/resources/net/corda/plugins/runnodes @@ -1,13 +1,14 @@ #!/usr/bin/env bash -set -euo pipefail +set -eo pipefail # Allow the script to be run from outside the nodes directory. basedir=$( dirname "$0" ) cd "$basedir" -if which osascript >/dev/null; then - /usr/libexec/java_home -v 1.8 --exec java -jar runnodes.jar "$@" +if [ -z "$JAVA_HOME" ] && which osascript >/dev/null; then + # use default version of java installed on mac + /usr/libexec/java_home --exec java -jar runnodes.jar "$@" else "${JAVA_HOME:+$JAVA_HOME/bin/}java" -jar runnodes.jar "$@" fi diff --git a/cordformation/src/test/kotlin/net/corda/plugins/CordformTest.kt b/cordformation/src/test/kotlin/net/corda/plugins/CordformTest.kt index dad640163e..e8169e6652 100644 --- a/cordformation/src/test/kotlin/net/corda/plugins/CordformTest.kt +++ b/cordformation/src/test/kotlin/net/corda/plugins/CordformTest.kt @@ -89,6 +89,30 @@ class CordformTest : BaseformTest() { assertThat(getNodeCordappConfig(notaryNodeName, localCordappJarName)).isRegularFile() } - - + @Test + fun `regex matching used by verifyAndGetRuntimeJar()`() { + val jarName = "corda" + + var releaseVersion = "4.3" + var pattern = "\\Q$jarName\\E(-enterprise)?-\\Q$releaseVersion\\E(-.+)?\\.jar\$".toRegex() + assertThat("corda-4.3.jar".contains(pattern)).isTrue() + assertThat("corda-4.3.jar".contains(pattern)).isTrue() + assertThat("corda-4.3.jarBla".contains(pattern)).isFalse() + assertThat("bla\\bla\\bla\\corda-4.3.jar".contains(pattern)).isTrue() + assertThat("corda-4.3-jdk11.jar".contains(pattern)).isTrue() + assertThat("corda-4.3jdk11.jar".contains(pattern)).isFalse() + assertThat("bla\\bla\\bla\\corda-enterprise-4.3.jar".contains(pattern)).isTrue() + assertThat("corda-enterprise-4.3.jar".contains(pattern)).isTrue() + assertThat("corda-enterprise-4.3-jdk11.jar".contains(pattern)).isTrue() + + releaseVersion = "4.3-RC01" + pattern = "\\Q$jarName\\E(-enterprise)?-\\Q$releaseVersion\\E(-.+)?\\.jar\$".toRegex() + assertThat("corda-4.3-RC01.jar".contains(pattern)).isTrue() + assertThat("corda-4.3RC01.jar".contains(pattern)).isFalse() + + releaseVersion = "4.3.20190925" + pattern = "\\Q$jarName\\E(-enterprise)?-\\Q$releaseVersion\\E(-.+)?\\.jar\$".toRegex() + assertThat("corda-4.3.20190925.jar".contains(pattern)).isTrue() + assertThat("corda-4.3.20190925-TEST.jar".contains(pattern)).isTrue() + } } \ No newline at end of file