Skip to content

Commit a33a399

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # build.gradle.kts # src/main/kotlin/kscript/app/AppHelpers.kt
2 parents e53b3f7 + faa5388 commit a33a399

File tree

4 files changed

+59
-43
lines changed

4 files changed

+59
-43
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Installation
4747

4848
To use `kscript` just Kotlin and Maven are required. To [install Kotlin](https://kotlinlang.org/docs/tutorials/command-line.html) we recommend [sdkman](http://sdkman.io/install):
4949
```
50-
curl -s "https://get.sdkman.io" | bash # install sdkman
51-
source ~/.bash_profile # add sdkman to PATH
50+
curl -s "https://get.sdkman.io" | bash # install sdkman
51+
source "$HOME/.sdkman/bin/sdkman-init.sh" # add sdkman to PATH
5252
53-
sdk install kotlin # install Kotlin
53+
sdk install kotlin # install Kotlin
5454
```
5555

5656
Once Kotlin is ready, you can install `kscript` with
@@ -64,7 +64,7 @@ To test your installation simply run
6464
kscript --help
6565
```
6666

67-
This will check and inform about udpates. To update `kscript` simply install it again as described above.
67+
This will check and inform about updates. To update `kscript` simply install it again as described above.
6868

6969
#### Run with docker
7070

build.gradle.kts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22

33
plugins {
44
kotlin("jvm") version "1.4.10"
5-
id("com.github.johnrengelman.shadow") version "2.0.4"
5+
id("com.github.johnrengelman.shadow") version "5.2.0"
66
}
77

88
group = "com.github.holgerbrandl.kscript.launcher"
@@ -11,32 +11,18 @@ group = "com.github.holgerbrandl.kscript.launcher"
1111
val kotlinVersion: String ="1.4.10"
1212

1313
dependencies {
14-
compile("org.jetbrains.kotlin:kotlin-stdlib")
15-
1614
compile("com.offbytwo:docopt:0.6.0.20150202")
1715

18-
// compile("com.jcabi:jcabi-aether:0.10.1") {
19-
// exclude("org.hibernate", "hibernate-validator")
20-
// exclude("org.slf4j", "slf4j-api")
21-
// exclude("org.slf4j", "jcl-over-slf4j")
22-
// exclude("org.apache.commons", "commons-lang3")
23-
// exclude("cglib", "cglib")
24-
// exclude("org.kuali.maven.wagons", "maven-s3-wagon")
25-
// }
26-
// compile("com.jcabi:jcabi-aether:0.10.1:sources") //can be used for debugging, but somehow adds logging to dependency resolvement?
27-
// compile("org.apache.maven:maven-core:3.0.3")
28-
// compile("org.slf4j:slf4j-nop:1.7.25")
29-
3016
implementation("org.jetbrains.kotlin:kotlin-scripting-common:$kotlinVersion")
3117
implementation("org.jetbrains.kotlin:kotlin-scripting-jvm:$kotlinVersion")
3218
implementation("org.jetbrains.kotlin:kotlin-scripting-dependencies:$kotlinVersion")
3319
implementation("org.jetbrains.kotlin:kotlin-scripting-dependencies-maven:$kotlinVersion")
3420

35-
compile("org.slf4j:slf4j-simple:1.7.30")
21+
compile("org.slf4j:slf4j-nop:1.7.30")
3622

37-
testCompile("junit:junit:4.12")
38-
testCompile( "io.kotlintest:kotlintest:2.0.7")
39-
testCompile(kotlin("script-runtime"))
23+
testImplementation("junit:junit:4.12")
24+
testImplementation( "io.kotlintest:kotlintest:2.0.7")
25+
testImplementation(kotlin("script-runtime"))
4026
}
4127

4228
repositories {
@@ -45,11 +31,11 @@ repositories {
4531

4632
val shadowJar by tasks.getting(ShadowJar::class) {
4733
// set empty string to classifier and version to get predictable jar file name: build/libs/kscript.jar
48-
archiveName = "kscript.jar"
34+
archiveFileName.set("kscript.jar")
4935
doLast {
5036
copy {
5137
from(File(projectDir, "src/kscript"))
52-
into(archivePath.parentFile)
38+
into(archiveFile.get().asFile.parentFile)
5339
}
5440
}
5541
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/kotlin/kscript/app/AppHelpers.kt

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ fun launchIdeaWithKscriptlet(scriptFile: File,
207207
includeURLs: List<URL>,
208208
compilerOpts: String): String {
209209
val intellijCommand = System.getenv("KSCRIPT_IDEA_COMMAND") ?: "idea"
210+
val gradleCommand = System.getenv("KSCRIPT_GRADLE_COMMAND") ?: "gradle"
211+
210212
requireInPath(intellijCommand, "Could not find '$intellijCommand' in your PATH. You must set the command used to launch your intellij as 'KSCRIPT_IDEA_COMMAND' env property")
211213

212214
infoMsg("Setting up idea project from ${scriptFile}")
@@ -229,20 +231,10 @@ fun launchIdeaWithKscriptlet(scriptFile: File,
229231
mkdirs()
230232
}
231233
File(tmpProjectDir, ".idea/runConfigurations/Main.xml").writeText(
232-
"""
233-
<component name="ProjectRunConfigurationManager">
234-
<configuration default="false" name="Main" type="BashConfigurationType" factoryName="Bash">
235-
<option name="INTERPRETER_OPTIONS" value="" />
236-
<option name="INTERPRETER_PATH" value="kscript" />
237-
<option name="PROJECT_INTERPRETER" value="false" />
238-
<option name="WORKING_DIRECTORY" value="" />
239-
<option name="PARENT_ENVS" value="true" />
240-
<option name="SCRIPT_NAME" value="${'$'}PROJECT_DIR${'$'}/src/${scriptFile.name}" />
241-
<option name="PARAMETERS" value="${userArgs.joinToString(" ")}" />
242-
<module name="" />
243-
<method v="2" />
244-
</configuration>
245-
</component>
234+
"""
235+
<component name="ProjectRunConfigurationManager">
236+
${runConfig(scriptFile, tmpProjectDir, userArgs)}
237+
</component>
246238
""".trimIndent()
247239
)
248240

@@ -328,15 +320,15 @@ $kotlinOptions
328320

329321
// https://stackoverflow.com/questions/17926459/creating-a-symbolic-link-with-java
330322
createSymLink(File(this, scriptFile.name), scriptFile)
331-
val scriptDir = Paths.get(scriptFile.path).parent
323+
val scriptDir = Paths.get(scriptFile.absolutePath).parent
332324

333325
// also symlink all includes
334326
includeURLs.distinctBy { it.fileName() }
335327
.forEach {
336328
val symlinkSrcDirAndDestination = when {
337329
it.protocol == "file" -> {
338330
val includeFile = File(it.toURI())
339-
val includeDir = Paths.get(includeFile.path).parent
331+
val includeDir = Paths.get(includeFile.absolutePath).parent
340332
val symlinkRelativePathToScript = File(this, scriptDir.relativize(includeDir).toFile().path)
341333
symlinkRelativePathToScript.mkdirs()
342334
Pair(symlinkRelativePathToScript, includeFile)
@@ -351,11 +343,50 @@ $kotlinOptions
351343
}
352344

353345
val projectPath = tmpProjectDir.absolutePath
346+
347+
// Create gradle wrapper
348+
requireInPath("$gradleCommand", "Could not find '$gradleCommand' in your PATH. You must set the command used to launch your intellij as 'KSCRIPT_GRADLE_COMMAND' env property")
349+
runProcess("$gradleCommand wrapper", wd = tmpProjectDir)
350+
354351
infoMsg("Project set up at $projectPath")
355352

356353
return "$intellijCommand \"$projectPath\""
357354
}
358355

356+
private fun runConfig(scriptFile: File, tmpProjectDir: File, userArgs: List<String>): String {
357+
return if (scriptFile.extension == "kt") {
358+
"""
359+
<configuration name="${scriptFile.name.substringBeforeLast(".")}" type="JetRunConfigurationType">
360+
<module name="${tmpProjectDir.name}.main" />
361+
<option name="VM_PARAMETERS" value="" />
362+
<option name="PROGRAM_PARAMETERS" value="" />
363+
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
364+
<option name="ALTERNATIVE_JRE_PATH" />
365+
<option name="PASS_PARENT_ENVS" value="true" />
366+
<option name="MAIN_CLASS_NAME" value="${scriptFile.name.substringBeforeLast(".").capitalize()}Kt" />
367+
<option name="WORKING_DIRECTORY" value="" />
368+
<method v="2">
369+
<option name="Make" enabled="true" />
370+
</method>
371+
</configuration>
372+
""".trimIndent()
373+
} else {
374+
"""
375+
<configuration default="false" name="Main" type="BashConfigurationType" factoryName="Bash">
376+
<option name="INTERPRETER_OPTIONS" value="" />
377+
<option name="INTERPRETER_PATH" value="kscript" />
378+
<option name="PROJECT_INTERPRETER" value="false" />
379+
<option name="WORKING_DIRECTORY" value="" />
380+
<option name="PARENT_ENVS" value="true" />
381+
<option name="SCRIPT_NAME" value="${'$'}PROJECT_DIR${'$'}/src/${scriptFile.name}" />
382+
<option name="PARAMETERS" value="${userArgs.joinToString(" ")}" />
383+
<module name="" />
384+
<method v="2" />
385+
</configuration>
386+
""".trimIndent()
387+
}
388+
}
389+
359390
private fun URL.fileName() = this.toURI().path.split("/").last()
360391

361392
private fun createSymLink(link: File, target: File) {
@@ -430,7 +461,6 @@ task simpleCapsule(type: FatCapsule){
430461
}
431462
}
432463
""".trimIndent()
433-
434464
val pckgedJar = File(Paths.get("").toAbsolutePath().toFile(), appName).absoluteFile
435465

436466

0 commit comments

Comments
 (0)