Skip to content

Commit a86e326

Browse files
committed
Bugfixes to gradleDependencyResolver related to file paths on Windows
1 parent f141586 commit a86e326

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/main/kotlin/org/javacs/kt/classpath/gradleDependencyResolver.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private fun createTemporaryGradleFile(): File {
5252
}
5353

5454
temp.bufferedWriter().use {
55-
it.write("rootProject { apply from: '${config.absolutePath}'} ")
55+
it.write("rootProject { apply from: '${config.absolutePath.replace("\\", "\\\\")}'} ")
5656
}
5757

5858
return temp
@@ -67,21 +67,21 @@ private fun getGradleCommand(workspace: Path): Path {
6767
}
6868
}
6969

70+
val jarArtifactOutputLine by lazy { Pattern.compile("^.+?\\.jar$") }
71+
7072
private fun readDependenciesViaTask(directory: Path): Set<Path>? {
7173
val gradle = getGradleCommand(directory)
7274
val config = createTemporaryGradleFile()
7375

7476
val gradleCommand = "$gradle -I ${config.absolutePath} classpath"
7577
val classpathCommand = Runtime.getRuntime().exec(gradleCommand, null, directory.toFile())
7678
val stdout = classpathCommand.inputStream
77-
val artifact = Pattern.compile("^.+?\\.jar$")
7879
val dependencies = mutableSetOf<Path>()
7980

8081
stdout.bufferedReader().use { reader ->
81-
for (dependency in reader.lines()) {
82-
val line = dependency.toString().trim()
83-
84-
if (artifact.matcher(line).matches()) {
82+
reader.lines().forEach {
83+
val line = it.toString().trim()
84+
if (!line.startsWith("Download") && jarArtifactOutputLine.matcher(line).matches()) {
8585
dependencies.add(Paths.get(line))
8686
}
8787
}

src/main/kotlin/org/javacs/kt/util/utils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ fun <T> tryResolving(what: String, resolver: () -> T?): T? {
8585
if (resolved != null) {
8686
LOG.info("Successfully resolved $what")
8787
return resolved
88+
} else {
89+
LOG.info("Could not resolve $what as it is null")
8890
}
8991
} catch (e: Exception) {
90-
LOG.info("Could not resolve $what due to ${e.message}")
92+
LOG.info("Could not resolve $what: ${e.message}")
9193
}
9294
return null
9395
}

0 commit comments

Comments
 (0)