@@ -5,6 +5,7 @@ import org.javacs.kt.util.findCommandOnPath
5
5
import java.nio.file.Path
6
6
import java.nio.file.Files
7
7
import java.io.File
8
+ import java.io.InputStream
8
9
9
10
/* * Resolver for reading maven dependencies */
10
11
internal class MavenClassPathResolver private constructor(private val pom : Path ) : ClassPathResolver {
@@ -58,21 +59,34 @@ private fun mavenJarName(a: Artifact, source: Boolean) =
58
59
if (source) " ${a.artifact} -${a.version} -sources.jar"
59
60
else " ${a.artifact} -${a.version} .jar"
60
61
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 ->
69
64
while (process.isAlive) {
70
65
val line = reader.readLine()?.trim() ? : break
71
66
if (line.isNotEmpty() && ! line.startsWith(" Progress" )) {
72
67
LOG .info(" Maven: {}" , line)
73
68
}
74
69
}
75
70
}
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()
76
90
77
91
return mavenOutput
78
92
}
0 commit comments