Skip to content

Commit 1397848

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

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-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+
OSContext.CURRENT_OS.candidateAlternativeLibraryLocations(name).firstNotNullOfOrNull { Paths.get(it).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+
* Suggests the candidate locations of the given JAR
9+
*
10+
* @param name the name of the JAR
11+
* @return the candidate full paths to the JAR
12+
*/
13+
fun candidateAlternativeLibraryLocations(name: String): Array<String>
14+
15+
companion object {
16+
/**
17+
* Gets the instance for the current OS
18+
*/
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 candidateAlternativeLibraryLocations(name: String): Array<String> = // Snap (Linux)
8+
arrayOf("/snap/kotlin/current/lib/${name}.jar")
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.javacs.kt.util
2+
3+
/**
4+
* Tasks only for Windows
5+
*/
6+
class WindowsContext : OSContext {
7+
override fun candidateAlternativeLibraryLocations(name: String): Array<String> = // Scoop (https://scoop.sh)
8+
CANDIDATE_PATHS.map {
9+
"$it$name.jar"
10+
}.toTypedArray()
11+
companion object {
12+
/**
13+
* Absolute path to the user's profile folder (home directory)
14+
*/
15+
private val USERPROFILE = System.getenv("USERPROFILE")
16+
private val CANDIDATE_PATHS = arrayOf(
17+
"${USERPROFILE}\\scoop\\apps\\kotlin\\current\\lib\\",
18+
)
19+
}
20+
}

0 commit comments

Comments
 (0)