File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed
shared/src/main/kotlin/org/javacs/kt Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import java.util.function.BiPredicate
88import org.javacs.kt.util.tryResolving
99import org.javacs.kt.util.findCommandOnPath
1010import org.javacs.kt.LOG
11+ import org.javacs.kt.util.OSContext
1112import 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)
8081private 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
8384private fun Path.existsOrNull () =
8485 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+ * 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+ }
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 candidateAlternativeLibraryLocations (name : String ): Array <String > = // Snap (Linux)
8+ arrayOf(" /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+ 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+ }
You can’t perform that action at this time.
0 commit comments