Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions src/main/kotlin/kscript/app/AppHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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()
Expand Down Expand Up @@ -313,40 +313,21 @@ $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]
//args = []
//systemProperties['java.awt.headless'] = true
}
}

simpleCapsule.doLast { task -> reallyExecutable(task) }
""".trimIndent()

val pckgedJar = File(Paths.get("").toAbsolutePath().toFile(), appName).absoluteFile
Expand All @@ -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}")
}
2 changes: 1 addition & 1 deletion src/main/kotlin/kscript/app/Kscript.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fun main(args: Array<String>) {
if (classpath.isNotEmpty())
extClassPath += kscript.app.CP_SEPARATOR_CHAR + classpath

println("kotlin ${kotlinOpts} -classpath ${extClassPath} ${execClassName} ${joinedUserArgs} ")
println("kotlin ${kotlinOpts} -classpath \"${extClassPath}\" ${execClassName} ${joinedUserArgs} ")
}


Expand Down