Skip to content

Commit 127b25c

Browse files
committed
fixed dependency lookup for cygwin
1 parent f62f058 commit 127b25c

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
package kscript.app
22

3-
import java.io.BufferedReader
43
import java.io.File
5-
import java.io.InputStreamReader
64

7-
/**
8-
* @author Holger Brandl
9-
*/
105

6+
val DEP_LOOKUP_CACHE_FILE = File(KSCRIPT_CACHE_DIR, "dependency_cache.txt")
117

12-
// Use cached classpath from previous run if present
13-
val DEP_LOOKUP_CACHE_FILE = File(File(System.getProperty("user.home"), ".kscript"), "dependency_cache.txt")
14-
15-
//val CP_SEPARATOR_CHAR= if(PlatformUtil.isWindows()) ";" else ":"
168
val CP_SEPARATOR_CHAR = if (System.getProperty("os.name").toLowerCase().contains("windows")) ";" else ":"
179

1810

@@ -26,6 +18,7 @@ fun resolveDependencies(depIds: List<String>): String? {
2618
val depsHash = depIds.joinToString(CP_SEPARATOR_CHAR)
2719

2820

21+
// Use cached classpath from previous run if present
2922
if (DEP_LOOKUP_CACHE_FILE.isFile()) {
3023
val cache = DEP_LOOKUP_CACHE_FILE.
3124
readLines().filter { it.isNotBlank() }.
@@ -84,35 +77,32 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
8477
fun runMaven(pom: String, goal: String): Iterable<String> {
8578
val temp = File.createTempFile("__resdeps__temp__", "_pom.xml")
8679
temp.writeText(pom)
87-
val exec = Runtime.getRuntime().exec("mvn -f ${temp.absolutePath} ${goal}")
88-
return BufferedReader(InputStreamReader(exec.inputStream)).
89-
lines().toArray().map { it.toString() }
80+
81+
val mavenCmd = if (System.getenv("PATH").run { this != null && contains("cygwin") }) {
82+
// when running with cygwin we need to map the pom path into windows space to work
83+
"mvn -f $(cygpath -w '${temp.absolutePath}') ${goal}"
84+
} else {
85+
"mvn -f ${temp.absolutePath} ${goal}"
86+
}
87+
88+
return evalBash(mavenCmd).stdout.lines()
9089
}
9190

9291
val mavenResult = runMaven(pom, "dependency:build-classpath")
9392

94-
//println(pom)
95-
//println(mavenResult.joinToString("\n"))
9693

9794
// The following artifacts could not be resolved: log4ja:log4ja:jar:9.8.87, log4j:log4j:jar:9.8.105: Could not
9895

9996
// Check for errors (e.g. when using non-existing deps resdeps.kts log4j:log4j:1.2.14 org.org.docopt:org.docopt:22.3-MISSING)
10097
mavenResult.filter { it.startsWith("[ERROR]") }.find { it.contains("Could not resolve dependencie") }?.let {
10198
System.err.println("Failed to lookup dependencies. Maven reported the following error:")
10299
System.err.println(it)
103-
// val matchResult = "Failure to find ([^ ]*)".toRegex().find(it)
104-
// println(matchResult.toString())
105-
// val failedDep = matchResult !!.groupValues[1]
106-
// System.err.println("Failed to resolve: ${failedDep}")
107100

108101
quit(1)
109102
}
110103

111104

112105
// Extract the classpath from the maven output
113-
//System.err.println(mavenResult)
114-
//mavenResult.dropWhile { !it.contains("Dependencies classpath:") }.forEach { println(">>>> ${it}") }
115-
116106
val classPath = mavenResult.dropWhile { !it.contains("Dependencies classpath:") }.drop(1).firstOrNull()
117107

118108
if (classPath == null) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import javax.xml.bind.DatatypeConverter
1414

1515

1616
/**
17-
* A kscript reimplementation in kotlin
17+
* A kscript - Scripting enhancements for Kotlin
18+
*
19+
* For details and license see https://github.com/holgerbrandl/kscript
1820
*
1921
* @author Holger Brandl
2022
*/
2123

22-
const val KSCRIPT_VERSION = "2.0.0"
24+
const val KSCRIPT_VERSION = "2.0.1"
2325

2426
val USAGE = """
2527
kscript - Enhanced scripting support for Kotlin on *nix-based systems.

0 commit comments

Comments
 (0)