File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed
shared/src/main/kotlin/org/javacs/kt Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import java.util.function.BiPredicate
8
8
import org.javacs.kt.util.tryResolving
9
9
import org.javacs.kt.util.findCommandOnPath
10
10
import org.javacs.kt.LOG
11
+ import org.javacs.kt.util.OSContext
11
12
import java.nio.file.Paths
12
13
13
14
/* * 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? =
78
79
// alternative library locations like for snap
79
80
// (can probably just use elvis operator and multiple similar expressions for other install directories)
80
81
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()
82
83
83
84
private fun Path.existsOrNull () =
84
85
if (Files .exists(this )) this else null
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments