@@ -2,10 +2,10 @@ package org.javacs.kt.classpath
2
2
3
3
import org.javacs.kt.LOG
4
4
import org.javacs.kt.util.findCommandOnPath
5
+ import org.javacs.kt.util.execAndReadStdoutAndStderr
5
6
import java.nio.file.Path
6
7
import java.nio.file.Files
7
8
import java.io.File
8
- import java.io.InputStream
9
9
10
10
/* * Resolver for reading maven dependencies */
11
11
internal class MavenClassPathResolver private constructor(private val pom : Path ) : ClassPathResolver {
@@ -59,35 +59,16 @@ private fun mavenJarName(a: Artifact, source: Boolean) =
59
59
if (source) " ${a.artifact} -${a.version} -sources.jar"
60
60
else " ${a.artifact} -${a.version} .jar"
61
61
62
- private fun readInputStream (process : Process , inputStream : InputStream ) {
63
- inputStream.bufferedReader().use { reader ->
64
- while (process.isAlive) {
65
- val line = reader.readLine()?.trim() ? : break
66
- if (line.isNotEmpty() && ! line.startsWith(" Progress" )) {
67
- LOG .info(" Maven: {}" , line)
68
- }
69
- }
70
- }
71
- }
72
-
73
62
private fun generateMavenDependencyList (pom : Path ): Path {
74
63
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()
90
-
64
+ val command = " $mvnCommand dependency:list -DincludeScope=test -DoutputFile=$mavenOutput "
65
+ val workingDirectory = pom.toAbsolutePath().parent
66
+ LOG .info(" Run {} in {}" , command, workingDirectory)
67
+ val (result, errors) = execAndReadStdoutAndStderr(command, workingDirectory)
68
+ LOG .debug(result)
69
+ if (" BUILD FAILURE" in errors) {
70
+ LOG .warn(" Maven task failed: {}" , errors.lines().firstOrNull())
71
+ }
91
72
return mavenOutput
92
73
}
93
74
0 commit comments