Skip to content

Commit 120ff45

Browse files
forrestbiceholgerbrandl
authored andcommitted
Create a default Run Configuration for Idea (#244)
* Create a default Run Configuration for Idea Create a default Run Configuration for Intellij when using the `idea` option. Achieved by creating a `Main` configuration within `.idea/runConfigurations`. The `userArgs` are also passed along by default. * Fix Incorrect Path In Script Tests Following from: #240 commits/d593d97c0db19b0f18aef6dc7fb7bc030b63384f.
1 parent 50ce008 commit 120ff45

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private fun bytesToHex(buffer: ByteArray): String {
200200
fun numLines(str: String) = str.split("\r\n|\r|\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray().size
201201

202202

203-
fun launchIdeaWithKscriptlet(scriptFile: File, dependencies: List<String>, customRepos: List<MavenRepo>, includeURLs: List<URL>): String {
203+
fun launchIdeaWithKscriptlet(scriptFile: File, userArgs: List<String>, dependencies: List<String>, customRepos: List<MavenRepo>, includeURLs: List<URL>): String {
204204
requireInPath("idea", "Could not find 'idea' in your PATH. It can be created in IntelliJ under `Tools -> Create Command-line Launcher`")
205205

206206
infoMsg("Setting up idea project from ${scriptFile}")
@@ -218,6 +218,28 @@ fun launchIdeaWithKscriptlet(scriptFile: File, dependencies: List<String>, custo
218218
// .run { File(this, "kscript_tmp_project") }
219219
// .apply { mkdir() }
220220

221+
File(tmpProjectDir, ".idea/runConfigurations/")
222+
.run {
223+
mkdirs()
224+
}
225+
File(tmpProjectDir, ".idea/runConfigurations/Main.xml").writeText(
226+
"""
227+
<component name="ProjectRunConfigurationManager">
228+
<configuration default="false" name="Main" type="BashConfigurationType" factoryName="Bash">
229+
<option name="INTERPRETER_OPTIONS" value="" />
230+
<option name="INTERPRETER_PATH" value="kscript" />
231+
<option name="PROJECT_INTERPRETER" value="false" />
232+
<option name="WORKING_DIRECTORY" value="" />
233+
<option name="PARENT_ENVS" value="true" />
234+
<option name="SCRIPT_NAME" value="${'$'}PROJECT_DIR${'$'}/src/${scriptFile.name}" />
235+
<option name="PARAMETERS" value="${userArgs.joinToString(" ")}" />
236+
<module name="" />
237+
<method v="2" />
238+
</configuration>
239+
</component>
240+
""".trimIndent()
241+
)
242+
221243
val stringifiedDeps = dependencies.map { " compile \"$it\"" }.joinToString("\n")
222244
val stringifiedRepos = customRepos.map { " maven {\n url '${it.url}'\n }\n" }.joinToString("\n")
223245

@@ -270,7 +292,7 @@ private fun URL.fileName() = this.toURI().path.split("/").last()
270292

271293
private fun createSymLink(link: File, target: File) {
272294
try {
273-
Files.createSymbolicLink(link.toPath(), target.absoluteFile.toPath());
295+
Files.createSymbolicLink(link.toPath(), target.absoluteFile.toPath())
274296
} catch (e: IOException) {
275297
errorMsg("Failed to create symbolic link to script. Copying instead...")
276298
target.copyTo(link)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fun main(args: Array<String>) {
150150

151151
// Create temporary dev environment
152152
if (docopt.getBoolean("idea")) {
153-
println(launchIdeaWithKscriptlet(rawScript, dependencies, customRepos, includeURLs))
153+
println(launchIdeaWithKscriptlet(rawScript, userArgs, dependencies, customRepos, includeURLs))
154154
exitProcess(0)
155155
}
156156

test/test_suite.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export -f kscript_nocall
268268
assert_raises 'tmpDir=$(kscript_nocall --idea test/resources/includes/include_variations.kts | cut -f2 -d" " | xargs echo); cd $tmpDir && gradle build' 0
269269

270270
## Ensure relative includes with in shebang mode
271-
assert_raises resources/includes/shebang_mode_includes 0
271+
assert_raises "${KSCRIPT_HOME}/test/resources/includes/shebang_mode_includes" 0
272272

273273
## support diamond-shaped include schemes (see #133)
274274
assert_raises 'tmpDir=$(kscript_nocall --idea test/resources/includes/diamond.kts | cut -f2 -d" " | xargs echo); cd $tmpDir && gradle build' 0

0 commit comments

Comments
 (0)