diff --git a/src/main/kotlin/kscript/app/AppHelpers.kt b/src/main/kotlin/kscript/app/AppHelpers.kt index 440bced6..c639bedc 100644 --- a/src/main/kotlin/kscript/app/AppHelpers.kt +++ b/src/main/kotlin/kscript/app/AppHelpers.kt @@ -244,7 +244,7 @@ sourceSets.main.java.srcDirs 'src' // also symlink all includes includeURLs.distinctBy { it.fileName() } .forEach { - + val includeFile = when { it.protocol == "file" -> File(it.toURI()) else -> fetchFromURL(it.toString()) @@ -254,7 +254,7 @@ sourceSets.main.java.srcDirs 'src' } } - return "idea ${tmpProjectDir.absolutePath}" + return "idea \"${tmpProjectDir.absolutePath}\"" } private fun URL.fileName() = this.toURI().path.split("/").last() @@ -313,31 +313,14 @@ $stringifiedDeps compile group: 'org.jetbrains.kotlin', name: 'kotlin-script-runtime', version: '${KotlinVersion.CURRENT}' // https://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file - compile files('${scriptJar}') -} - -// http://www.capsule.io/user-guide/#really-executable-capsules -def reallyExecutable(jar) { - ant.concat(destfile: "tmp.jar", binary: true) { - //zipentry(zipfile: configurations.capsule.singleFile, name: 'capsule/execheader.sh') - fileset(dir: '.', includes: 'exec_header.sh') - - fileset(dir: jar.destinationDir) { - include(name: jar.archiveName) - } - } - copy { - from 'tmp.jar' - into jar.destinationDir - rename { jar.archiveName } - } - delete 'tmp.jar' + compile files('${scriptJar.invariantSeparatorsPath}') } task simpleCapsule(type: FatCapsule){ applicationClass '$wrapperClassName' - baseName '$appName' + archiveName '$appName' + reallyExecutable capsuleManifest { jvmArgs = [$jvmOptions] @@ -345,8 +328,6 @@ task simpleCapsule(type: FatCapsule){ //systemProperties['java.awt.headless'] = true } } - -simpleCapsule.doLast { task -> reallyExecutable(task) } """.trimIndent() val pckgedJar = File(Paths.get("").toAbsolutePath().toFile(), appName).absoluteFile @@ -360,11 +341,14 @@ exec java -jar ${'$'}0 "${'$'}@" File(tmpProjectDir, "build.gradle").writeText(gradleScript) - val pckgResult = evalBash("cd ${tmpProjectDir} && gradle simpleCapsule && cp build/libs/${appName}*.jar ${pckgedJar} && chmod +x ${pckgedJar}") + val pckgResult = evalBash("cd '${tmpProjectDir}' && gradle simpleCapsule") with(pckgResult) { kscript.app.errorIf(exitCode != 0) { "packaging of '$appName' failed:\n$pckgResult" } } + pckgedJar.delete() + File(tmpProjectDir, "build/libs/${appName}").copyTo(pckgedJar, true) + infoMsg("Finished packaging into ${pckgedJar}") } diff --git a/src/main/kotlin/kscript/app/Kscript.kt b/src/main/kotlin/kscript/app/Kscript.kt index 4ea43697..dd1d0fc3 100644 --- a/src/main/kotlin/kscript/app/Kscript.kt +++ b/src/main/kotlin/kscript/app/Kscript.kt @@ -270,7 +270,7 @@ fun main(args: Array) { if (classpath.isNotEmpty()) extClassPath += kscript.app.CP_SEPARATOR_CHAR + classpath - println("kotlin ${kotlinOpts} -classpath ${extClassPath} ${execClassName} ${joinedUserArgs} ") + println("kotlin ${kotlinOpts} -classpath \"${extClassPath}\" ${execClassName} ${joinedUserArgs} ") }