Skip to content

Commit d98b3fd

Browse files
committed
Add support for Kotlin installed by Scoop
1 parent 394c6a3 commit d98b3fd

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

shared/src/main/kotlin/org/javacs/kt/classpath/BackupClassPathResolver.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.util.function.BiPredicate
88
import org.javacs.kt.util.tryResolving
99
import org.javacs.kt.util.findCommandOnPath
1010
import org.javacs.kt.LOG
11+
import org.javacs.kt.util.OSContext
1112
import java.nio.file.Paths
1213

1314
/** Backup classpath that find Kotlin in the user's Maven/Gradle home or kotlinc's libraries folder. */
@@ -78,7 +79,7 @@ private fun findKotlinCliCompilerLibrary(name: String): Path? =
7879
// alternative library locations like for snap
7980
// (can probably just use elvis operator and multiple similar expressions for other install directories)
8081
private fun findAlternativeLibraryLocation(name: String): Path? =
81-
Paths.get("/snap/kotlin/current/lib/${name}.jar").existsOrNull()
82+
Paths.get(OSContext.CURRENT_OS.findAlternativeLibraryLocation(name)).existsOrNull()
8283

8384
private fun Path.existsOrNull() =
8485
if (Files.exists(this)) this else null
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.javacs.kt.util
2+
3+
/**
4+
* Tasks that depends on user's OS
5+
*/
6+
interface OSContext {
7+
/**
8+
* Resolves the locations of the given JAR
9+
*
10+
* @param name the name of the JAR
11+
* @return the full path to the JAR
12+
*/
13+
fun findAlternativeLibraryLocation(name: String): String
14+
companion object {
15+
/**
16+
* Gets the instance for the current OS
17+
*/
18+
@JvmStatic
19+
val CURRENT_OS by lazy<OSContext> {
20+
val osName = System.getProperty("os.name")!!.lowercase()
21+
when {
22+
osName.contains("windows") -> WindowsContext()
23+
else -> UnixContext()
24+
}
25+
}
26+
}
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.javacs.kt.util
2+
3+
/**
4+
* Tasks for other than Windows
5+
*/
6+
class UnixContext : OSContext {
7+
override fun findAlternativeLibraryLocation(name: String): String = // Snap (Linux)
8+
"/snap/kotlin/current/lib/${name}.jar"
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.javacs.kt.util
2+
3+
/**
4+
* Tasks only for Windows
5+
*/
6+
class WindowsContext : OSContext {
7+
/**
8+
* Absolute path to the user's profile folder (home directory)
9+
*/
10+
private val userProfile = System.getenv("USERPROFILE")
11+
override fun findAlternativeLibraryLocation(name: String): String = // Scoop (https://scoop.sh)
12+
"${userProfile}\\scoop\\apps\\kotlin\\current\\lib\\\${name}.jar"
13+
}

0 commit comments

Comments
 (0)