Some Gradle refactoring

This commit is contained in:
IgorNitto 2018-02-13 10:24:57 +00:00 committed by Stefano Franz
parent bc3facaed9
commit 18cc1bbb0c
8 changed files with 104 additions and 128 deletions

View File

@ -9,65 +9,11 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
} }
ext {
loaderClassName = "net.corda.launcher.Loader"
launcherClassName = "net.corda.launcher.Launcher"
}
jar { jar {
baseName 'corda-launcher' baseName 'corda-launcher'
} }
//task gatherDependencies(type: Copy, dependsOn: jar) {
// from configurations.runtime
// from jar
// into "$buildDir/bin/lib"
//}
//
//def launcherOutputDir = null
//
//task makeExecutable(type: Exec, dependsOn: [gatherDependencies]) {
// def isLinux = System.properties['os.name'].toLowerCase().contains('linux')
// def isMac = System.properties['os.name'].toLowerCase().contains('mac')
//
// if (!isLinux && !isMac)
// throw new GradleException("Preparing distribution package is currently only supported on Linux/Mac")
//
// def distributionDir = "${buildDir}/tmp/"
// if (isLinux) launcherOutputDir = "${distributionDir}/bundles/launcher/"
// else launcherOutputDir = "${distributionDir}/bundles/launcher.app/Contents"
//
// def classPath = []
//
// workingDir project.projectDir
//
// def extraArgs = [
// "-BjvmOptions=-javaagent:quasar-core-${quasar_version}-jdk8.jar=${project(':node:capsule').quasarExcludeExpression}",
// '-BuserJvmOptions=-Xmx=4g',
// '-BuserJvmOptions=-XX\\:=+UseG1GC',
// '-BjvmProperties=java.system.class.loader=net.corda.launcher.Loader'
// ]
//
// doFirst {
// def dependencies = []
//
// fileTree(gatherDependencies.destinationDir).forEach({ file ->
// classPath.add("../../lib/" + file.getName())
// })
//
// commandLine = [
// 'javapackager',
// '-deploy',
// '-nosign',
// '-native', 'image',
// '-outdir', "$distributionDir",
// '-outfile', 'launcher',
// '-name', 'launcher',
// "-BmainJar=${jar.archiveName}",
// "-Bclasspath=${classPath.join(":")}",
// '-appclass', 'net.corda.launcher.Launcher',
// '-srcdir', "${gatherDependencies.destinationDir}",
// '-srcfiles', "${jar.archiveName}"
// ] + extraArgs
// }
//}
//
//task exportLauncher(type: Copy, dependsOn: makeExecutable ) {
// from launcherOutputDir into "${buildDir}/bin"
//}

View File

@ -11,7 +11,7 @@ fun main(args: Array<String>) {
val sysClassLoader = ClassLoader.getSystemClassLoader() val sysClassLoader = ClassLoader.getSystemClassLoader()
val appClassLoader = (sysClassLoader as? Loader) ?: { val appClassLoader = (sysClassLoader as? Loader) ?: {
println("WARNING: failed to overried system classloader") println("WARNING: failed to override system classloader")
Loader(sysClassLoader) Loader(sysClassLoader)
} () } ()
@ -36,8 +36,7 @@ fun main(args: Array<String>) {
appClassLoader.augmentClasspath(pluginURLs) appClassLoader.augmentClasspath(pluginURLs)
// Propagate current working directory, as workaround for javapackager // Propagate current working directory via system property, to patch it after javapackager
// corrupting it
System.setProperty("corda.launcher.cwd", nodeBaseDir.toString()) System.setProperty("corda.launcher.cwd", nodeBaseDir.toString())
System.setProperty("user.dir", nodeBaseDir.toString()) System.setProperty("user.dir", nodeBaseDir.toString())

View File

@ -3,8 +3,7 @@ package net.corda.launcher
import java.net.URL import java.net.URL
import java.net.URLClassLoader import java.net.URLClassLoader
class Loader(parent: ClassLoader?): class Loader(parent: ClassLoader?): URLClassLoader(Settings.CLASSPATH.toTypedArray(), parent) {
URLClassLoader(Settings.CLASSPATH.toTypedArray(), parent) {
fun augmentClasspath(urls: List<URL>) { fun augmentClasspath(urls: List<URL>) {
urls.forEach { addURL(it) } urls.forEach { addURL(it) }

View File

@ -10,10 +10,11 @@ import kotlin.collections.HashSet
object Settings { object Settings {
val CORDA_RUNTIME_SETTINGS = "../runtime.properties"
val WORKING_DIR: Path val WORKING_DIR: Path
val CLASSPATH: List<URL> val CLASSPATH: List<URL>
val PLUGINS: List<Path> val PLUGINS: List<Path>
val CORDA_RUNTIME_SETTINGS = "../runtime.properties" val LIBPATH: Path
init { init {
WORKING_DIR = Paths.get(System.getenv("CORDA_LAUNCHER_CWD") ?: "..") WORKING_DIR = Paths.get(System.getenv("CORDA_LAUNCHER_CWD") ?: "..")
@ -24,15 +25,16 @@ object Settings {
CLASSPATH = parseClasspath(settings) CLASSPATH = parseClasspath(settings)
PLUGINS = parsePlugins(settings) PLUGINS = parsePlugins(settings)
LIBPATH = Paths.get(settings.getProperty("libpath") ?: ".")
} }
private fun parseClasspath(config: Properties): List<URL> { private fun parseClasspath(config: Properties): List<URL> {
val launcherDir = Paths.get("..").toAbsolutePath() val libDir = Paths.get("..").resolve(LIBPATH).toAbsolutePath()
val cp = config.getProperty("classpath") ?: val cp = config.getProperty("classpath") ?:
throw Error("Missing 'classpath' property from config") throw Error("Missing 'classpath' property from config")
return cp.split(':').map { return cp.split(':').map {
launcherDir.resolve(it).toUri().toURL() libDir.resolve(it).toUri().toURL()
} }
} }

124
node/dist/build.gradle vendored
View File

@ -1,37 +1,43 @@
description 'Corda Node Executable Image' description 'Package Node as stand-alone application'
evaluationDependsOn(":node") evaluationDependsOn(":node")
evaluationDependsOn(":docs") evaluationDependsOn(":docs")
evaluationDependsOn(":launcher") evaluationDependsOn(":launcher")
def outputDir = "$buildDir/release" ext {
outputDir = "$buildDir/corda"
}
def tmpDir = "${buildDir}/tmp/"
configurations { configurations {
launcherClasspath launcherClasspath
} }
// Define location of predefined startup scripts, license and README files
sourceSets { sourceSets {
binFiles { binFiles {
resources { resources {
srcDir file('src/main/resources/bin') srcDir file('src/main/resources/bin')
} }
} }
licenseFiles { readmeFiles {
resources { resources {
srcDir file('src/main/resources/license') srcDir file('src/main/resources/readme')
} }
} }
} }
// Runtime dependencies of launcher
dependencies { dependencies {
launcherClasspath "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" launcherClasspath project(':launcher')
launcherClasspath "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
launcherClasspath "org.slf4j:jul-to-slf4j:$slf4j_version" launcherClasspath "org.slf4j:jul-to-slf4j:$slf4j_version"
launcherClasspath "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}" launcherClasspath "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
launcherClasspath "org.apache.logging.log4j:log4j-web:${log4j_version}" launcherClasspath "org.apache.logging.log4j:log4j-web:${log4j_version}"
// Required by JVM agents:
launcherClasspath "com.google.guava:guava:$guava_version" launcherClasspath "com.google.guava:guava:$guava_version"
launcherClasspath "de.javakaffee:kryo-serializers:0.41" launcherClasspath "de.javakaffee:kryo-serializers:0.41"
launcherClasspath project(':launcher')
} }
task copyLauncherLibs(type: Copy, dependsOn: [project(':launcher').jar]) { task copyLauncherLibs(type: Copy, dependsOn: [project(':launcher').jar]) {
@ -39,41 +45,45 @@ task copyLauncherLibs(type: Copy, dependsOn: [project(':launcher').jar]) {
into "$buildDir/tmp/launcher-lib" into "$buildDir/tmp/launcher-lib"
} }
// The launcher building is done as it depends on application-specific settings which
// cannot be overridden later
task buildLauncher(type: Exec, dependsOn: [copyLauncherLibs]) { task buildLauncher(type: Exec, dependsOn: [copyLauncherLibs]) {
description 'Build Launcher executable'
def isLinux = System.properties['os.name'].toLowerCase().contains('linux') def isLinux = System.properties['os.name'].toLowerCase().contains('linux')
def isMac = System.properties['os.name'].toLowerCase().contains('mac') def isMac = System.properties['os.name'].toLowerCase().contains('mac')
if (!isLinux && !isMac) if (!isLinux && !isMac)
throw new GradleException("Preparing distribution package is currently only supported on Linux/Mac") throw new GradleException("Preparing distribution package is currently only supported on Linux/Mac")
def distributionDir = "${buildDir}/tmp/"
def relativeDir def relativeDir
if (isLinux) relativeDir = "launcher" if (isLinux)
else relativeDir = "launcher.app/Contents" relativeDir = "launcher"
else
ext { relativeDir = "launcher.app/Contents"
launcherBinDir = "${distributionDir}/bundles/$relativeDir"
}
workingDir project.projectDir
def extraArgs = [ def extraArgs = [
"-BjvmOptions=-javaagent:../../lib/quasar-core-${quasar_version}-jdk8.jar=${project(':node:capsule').quasarExcludeExpression}", "-BjvmOptions=-javaagent:../../lib/quasar-core-${quasar_version}-jdk8.jar=${project(':node:capsule').quasarExcludeExpression}",
'-BuserJvmOptions=-Xmx=4g', '-BuserJvmOptions=-Xmx=4g',
'-BuserJvmOptions=-XX\\:=+UseG1GC', '-BuserJvmOptions=-XX\\:=+UseG1GC',
'-BjvmProperties=java.system.class.loader=net.corda.launcher.Loader' "-BjvmProperties=java.system.class.loader=${project(':launcher').loaderClassName}'}"
] ]
ext {
launcherBinDir = "${tmpDir}/bundles/$relativeDir"
}
workingDir project.projectDir
doFirst { doFirst {
def launcherLib = copyLauncherLibs.destinationDir def launcherLib = copyLauncherLibs.destinationDir
def srcfiles = [] def srcfiles = []
def classpath = [] def launcherClasspath = []
fileTree(launcherLib).forEach({ file -> fileTree(launcherLib).forEach({ file ->
srcfiles.add("-srcfiles") srcfiles.add("-srcfiles")
srcfiles.add(file.name) srcfiles.add(file.name)
classpath.add(file.name) launcherClasspath.add(file.name)
}) })
commandLine = [ commandLine = [
@ -81,60 +91,62 @@ task buildLauncher(type: Exec, dependsOn: [copyLauncherLibs]) {
'-deploy', '-deploy',
'-nosign', '-nosign',
'-native', 'image', '-native', 'image',
'-outdir', "$distributionDir", '-outdir', "$tmpDir",
'-outfile', 'launcher', '-outfile', 'launcher',
'-name', 'launcher', '-name', 'launcher',
"-BmainJar=${project(':launcher').jar.archiveName}", "-BmainJar=${project(':launcher').jar.archiveName}",
"-Bclasspath=${classpath.join(":")}", "-Bclasspath=${launcherClasspath.join(":")}",
'-appclass', 'net.corda.launcher.Launcher', '-appclass', '${project(\':launcher\').launcherClassName}',
'-srcdir', "$launcherLib" '-srcdir', "$launcherLib"
] + srcfiles + extraArgs ] + srcfiles + extraArgs
} }
}
task installNodeLib(type: Copy, dependsOn: [project(':node').jar]) {
from project(':node').configurations.runtime
from project(':node').jar
into "${outputDir}/lib"
}
task installLauncher(type: Copy, dependsOn: [buildLauncher, installNodeLib]) {
from buildLauncher.launcherBinDir
into "${outputDir}/launcher"
// Add configuration for running Node application
doLast { doLast {
def classpath = [] def nodeClasspath = []
def libRelPath = "../lib/"
fileTree("${outputDir}/lib").forEach({ file -> project(':node').configurations.runtime.forEach({ file ->
classpath.add("../lib/" + file.getName()) nodeClasspath.add(file.getName())
}) })
new File("${outputDir}/launcher/runtime.properties").text = [ nodeClasspath.add(project(':node').jar.getName())
"classpath=${classpath.join(':')}",
new File("${launcherBinDir}/runtime.properties").text = [
"libpath=${libRelPath}",
"classpath=${nodeClasspath.join(':')}",
"plugins=./drivers:./cordapps"].join("\n") "plugins=./drivers:./cordapps"].join("\n")
} }
} }
task installStartupScripts(type: Copy) { task buildNode(type: Copy, dependsOn: [buildLauncher, project(':docs').tasks['makeDocs']]) {
from sourceSets.binFiles.resources description 'Build stand-alone Corda Node distribution'
into "$outputDir/bin"
}
task installReadmeFiles(type: Copy) { into(outputDir)
from sourceSets.licenseFiles.resources
into "$outputDir"
}
task installDocs(type: Copy, dependsOn: [project(':docs').tasks['makeDocs']]) { from(buildLauncher.launcherBinDir) {
from(project(':docs').buildDir) into("launcher")
into "$outputDir/docs" }
}
task buildNode(dependsOn: [installLauncher, from(project(':node').configurations.runtime) {
installNodeLib, into("lib")
installDocs, }
installStartupScripts,
installReadmeFiles]) { from(project(':node').jar) {
into("lib")
}
from(sourceSets.binFiles.resources) {
into("bin")
}
from(sourceSets.readmeFiles.resources) {
into(".")
}
from(project(':docs').buildDir) {
into("docs")
}
doLast { doLast {
new File("${outputDir}/cordapps").mkdirs() new File("${outputDir}/cordapps").mkdirs()

View File

@ -6,6 +6,4 @@ To start a node, please edit supplied node.conf file so it contains appropriate
Your CordApps should be placed in cordapps directory, from which they will be loaded automatically. Your CordApps should be placed in cordapps directory, from which they will be loaded automatically.
Linux: Linux/Mac: main executable file is ./bin/corda
Main executable file is corda - run by simply ./corda
MacOS: Main executable file is MacOS/corda - run simply by typing ./MacOS/corda

View File

@ -0,0 +1,22 @@
myLegalName : "O=Bank A,L=London,C=GB"
keyStorePassword : "cordacadevpass"
trustStorePassword : "trustpass"
dataSourceProperties : {
dataSourceClassName : org.h2.jdbcx.JdbcDataSource
"dataSource.url" : "jdbc:h2:file:"${baseDirectory}"/persistence"
"dataSource.user" : sa
"dataSource.password" : ""
}
p2pAddress : "my-corda-node:10002"
rpcSettings = {
useSsl = false
standAloneBroker = false
address : "my-corda-node:10003"
adminAddress : "my-corda-node:10004"
}
webAddress : "localhost:10004"
rpcUsers : [
{ username=user1, password=letmein, permissions=[ StartFlow.net.corda.protocols.CashProtocol ] }
]
devMode : true
// certificateSigningService : "https://testnet.certificate.corda.net"

View File

@ -70,12 +70,10 @@ class NodeArgsParser : AbstractArgsParser<CmdLineOptions>() {
} }
// Note: this is a workaround for javapackager misbehaving with cwd. // Note: this is a workaround for javapackager misbehaving with cwd.
// The correct working directory is propagated from launcher via system property. // The correct working directory is propagated from launcher via system property.
val baseDirectory = System.getProperty("corda.launcher.cwd")?.let { Paths.get(it) } val baseDirectory = System.getProperty("corda.launcher.cwd")?.let { Paths.get(it) }
?: optionSet.valueOf(baseDirectoryArg) ?: optionSet.valueOf(baseDirectoryArg)
.normalize() .normalize()
.toAbsolutePath() .toAbsolutePath()
val configFile = baseDirectory / optionSet.valueOf(configFileArg) val configFile = baseDirectory / optionSet.valueOf(configFileArg)
val loggingLevel = optionSet.valueOf(loggerLevel) val loggingLevel = optionSet.valueOf(loggerLevel)
val logToConsole = optionSet.has(logToConsoleArg) val logToConsole = optionSet.has(logToConsoleArg)