From 2f3839b51d7797cb178aae0edfd9dc22acbb6788 Mon Sep 17 00:00:00 2001 From: Ilya Muradyan Date: Sat, 7 Dec 2019 13:20:50 +0300 Subject: [PATCH] Fixed windows path separator issues and slightly refactored Gradle config --- .gitignore | 1 + build.gradle | 25 +++++++++++++++++-------- gradle.properties.template | 1 + 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 gradle.properties.template diff --git a/.gitignore b/.gitignore index e62b45360..3e6988e0e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build/ **/.ipynb* **/build/ *.DS_Store +gradle.properties diff --git a/build.gradle b/build.gradle index 4abfafa07..7c2ab44ef 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +import java.nio.file.Paths buildscript { ext.shadowJarVersion = "5.2.0" @@ -37,7 +38,9 @@ allprojects { version = '0.7.3' - ext.installPath = project.hasProperty('installPath') ? project.getProperty('installPath') : "${System.properties['user.home']}/.ipython/kernels/kotlin" + ext.installPath = project.hasProperty('installPath') ? + project.getProperty('installPath') : + Paths.get(System.properties['user.home'].toString(), ".ipython", "kernels", "kotlin").toAbsolutePath().toString() ext.debugPort = 1044 ext.configFile = "config.json" ext.debuggerConfig = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort" @@ -102,24 +105,30 @@ void createTaskForSpecs(Boolean debug) { task(taskName) { dependsOn cleanInstallDir doLast { - String spec = new File("kernelspec/kernel.json.template").getText('UTF-8') + String sep = File.separator + String spec = new File("kernelspec${sep}kernel.json.template").getText('UTF-8') File kernelFile = files { shadowJar }.singleFile - spec = spec.replace("\${KERNEL_JAR_PATH}", "$installPath/${kernelFile.name}") + spec = substitute(spec, "KERNEL_JAR_PATH", "$installPath${sep}${kernelFile.name}") + String libsCp = files { configurations.deploy }.files.collect { - "$installPath/${it.name}" + "$installPath${sep}${it.name}" } .join(File.pathSeparator) - spec = spec.replace("\${RUNTIME_CLASSPATH}", libsCp) - .replace("\${DEBUGGER_CONFIG}", debug ? "\"$debuggerConfig\"," : "") - .replace("\${LIBRARIES_PATH}", "$installPath/$configFile") + spec = substitute(spec, "RUNTIME_CLASSPATH", libsCp) + spec = substitute(spec, "DEBUGGER_CONFIG", debug ? "\"$debuggerConfig\"," : "") + spec = substitute(spec, "LIBRARIES_PATH", "$installPath$sep$configFile") File installDir = new File("$installPath") if (!installDir.exists()) { installDir.mkdirs(); } - new File("$installPath/kernel.json").write(spec, 'UTF-8') + new File("$installPath${sep}kernel.json").write(spec, 'UTF-8') } } } +static String substitute(String spec, String template, String val) { + return spec.replace("\${$template}", val.replace("\\", "\\\\")) +} + task copyLibrariesConfig(type: Copy, dependsOn: cleanInstallDir) { from configFile into installPath diff --git a/gradle.properties.template b/gradle.properties.template new file mode 100644 index 000000000..a14541584 --- /dev/null +++ b/gradle.properties.template @@ -0,0 +1 @@ +installPath=/kernels/kotlin