Skip to content

Commit 1225e7d

Browse files
author
Paul Marbach
committed
fix error where mvn hangs if anything is output to stderr
1 parent 358b4e9 commit 1225e7d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "automatic"
3+
}

shared/src/main/kotlin/org/javacs/kt/classpath/MavenClassPathResolver.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.javacs.kt.util.findCommandOnPath
55
import java.nio.file.Path
66
import java.nio.file.Files
77
import java.io.File
8+
import java.io.InputStream
89

910
/** Resolver for reading maven dependencies */
1011
internal class MavenClassPathResolver private constructor(private val pom: Path) : ClassPathResolver {
@@ -58,21 +59,34 @@ private fun mavenJarName(a: Artifact, source: Boolean) =
5859
if (source) "${a.artifact}-${a.version}-sources.jar"
5960
else "${a.artifact}-${a.version}.jar"
6061

61-
private fun generateMavenDependencyList(pom: Path): Path {
62-
val mavenOutput = Files.createTempFile("deps", ".txt")
63-
val workingDirectory = pom.toAbsolutePath().parent.toFile()
64-
val cmd = "$mvnCommand dependency:list -DincludeScope=test -DoutputFile=$mavenOutput"
65-
LOG.info("Run {} in {}", cmd, workingDirectory)
66-
val process = Runtime.getRuntime().exec(cmd, null, workingDirectory)
67-
68-
process.inputStream.bufferedReader().use { reader ->
62+
private fun readInputStream(process: Process, inputStream: InputStream) {
63+
inputStream.bufferedReader().use { reader ->
6964
while (process.isAlive) {
7065
val line = reader.readLine()?.trim() ?: break
7166
if (line.isNotEmpty() && !line.startsWith("Progress")) {
7267
LOG.info("Maven: {}", line)
7368
}
7469
}
7570
}
71+
}
72+
73+
private fun generateMavenDependencyList(pom: Path): Path {
74+
val mavenOutput = Files.createTempFile("deps", ".txt")
75+
val workingDirectory = pom.toAbsolutePath().parent.toFile()
76+
val cmd = "$mvnCommand dependency:list -DincludeScope=test -DoutputFile=$mavenOutput"
77+
LOG.info("Run {} in {}", cmd, workingDirectory)
78+
val process = Runtime.getRuntime().exec(cmd, null, workingDirectory)
79+
80+
val inputStream = Thread() { readInputStream(process, process.inputStream) }
81+
val errorStream = Thread() { readInputStream(process, process.errorStream) }
82+
83+
// start the streams in parallel...
84+
inputStream.start()
85+
errorStream.start()
86+
87+
// ...then block on both of them
88+
inputStream.join()
89+
errorStream.join()
7690

7791
return mavenOutput
7892
}

0 commit comments

Comments
 (0)