|
@@ -20,6 +20,7 @@ package org.elasticsearch.gradle.vagrant
|
|
|
|
|
|
import com.carrotsearch.gradle.junit4.LoggingOutputStream
|
|
|
import org.gradle.logging.ProgressLogger
|
|
|
+import org.gradle.logging.ProgressLoggerFactory
|
|
|
|
|
|
/**
|
|
|
* Adapts an OutputStream being written to by vagrant into a ProcessLogger. It
|
|
@@ -42,79 +43,82 @@ import org.gradle.logging.ProgressLogger
|
|
|
* to catch so it can render the output like
|
|
|
* "Heading text > stdout from the provisioner".
|
|
|
*/
|
|
|
-class VagrantLoggerOutputStream extends LoggingOutputStream {
|
|
|
- static final String HEADING_PREFIX = '==> '
|
|
|
+public class VagrantLoggerOutputStream extends LoggingOutputStream {
|
|
|
+ private static final String HEADING_PREFIX = '==> '
|
|
|
|
|
|
- ProgressLogger progressLogger
|
|
|
- String squashedPrefix
|
|
|
- String lastLine = ''
|
|
|
- boolean inProgressReport = false
|
|
|
- String heading = ''
|
|
|
+ ProgressLoggerFactory progressLoggerFactory
|
|
|
|
|
|
- VagrantLoggerOutputStream(Map args) {
|
|
|
- progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
|
|
|
- progressLogger.setDescription("Vagrant $args.command")
|
|
|
- progressLogger.started()
|
|
|
- progressLogger.progress("Starting vagrant $args.command...")
|
|
|
- squashedPrefix = args.squashedPrefix
|
|
|
- }
|
|
|
|
|
|
- void flush() {
|
|
|
- if (end == start) return
|
|
|
- line(new String(buffer, start, end - start))
|
|
|
- start = end
|
|
|
- }
|
|
|
+ private ProgressLogger progressLogger
|
|
|
+ String squashedPrefix
|
|
|
+ String lastLine = ''
|
|
|
+ boolean inProgressReport = false
|
|
|
+ String heading = ''
|
|
|
|
|
|
- void line(String line) {
|
|
|
- // debugPrintLine(line) // Uncomment me to log every incoming line
|
|
|
- if (line.startsWith('\r\u001b')) {
|
|
|
- /* We don't want to try to be a full terminal emulator but we want to
|
|
|
- keep the escape sequences from leaking and catch _some_ of the
|
|
|
- meaning. */
|
|
|
- line = line.substring(2)
|
|
|
- if ('[K' == line) {
|
|
|
- inProgressReport = true
|
|
|
- }
|
|
|
- return
|
|
|
+ VagrantLoggerOutputStream(Map args) {
|
|
|
+ progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
|
|
|
+ progressLogger.setDescription("Vagrant output for `$args.command`")
|
|
|
+ progressLogger.started()
|
|
|
+ progressLogger.progress("Starting `$args.command`...")
|
|
|
+ squashedPrefix = args.squashedPrefix
|
|
|
}
|
|
|
- if (line.startsWith(squashedPrefix)) {
|
|
|
- line = line.substring(squashedPrefix.length())
|
|
|
- inProgressReport = false
|
|
|
- lastLine = line
|
|
|
- if (line.startsWith(HEADING_PREFIX)) {
|
|
|
- line = line.substring(HEADING_PREFIX.length())
|
|
|
- heading = line + ' > '
|
|
|
- } else {
|
|
|
- line = heading + line
|
|
|
- }
|
|
|
- } else if (inProgressReport) {
|
|
|
- inProgressReport = false
|
|
|
- line = lastLine + line
|
|
|
- } else {
|
|
|
- return
|
|
|
+
|
|
|
+ void flush() {
|
|
|
+ if (end == start) return
|
|
|
+ line(new String(buffer, start, end - start))
|
|
|
+ start = end
|
|
|
+ }
|
|
|
+
|
|
|
+ void line(String line) {
|
|
|
+ // debugPrintLine(line) // Uncomment me to log every incoming line
|
|
|
+ if (line.startsWith('\r\u001b')) {
|
|
|
+ /* We don't want to try to be a full terminal emulator but we want to
|
|
|
+ keep the escape sequences from leaking and catch _some_ of the
|
|
|
+ meaning. */
|
|
|
+ line = line.substring(2)
|
|
|
+ if ('[K' == line) {
|
|
|
+ inProgressReport = true
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (line.startsWith(squashedPrefix)) {
|
|
|
+ line = line.substring(squashedPrefix.length())
|
|
|
+ inProgressReport = false
|
|
|
+ lastLine = line
|
|
|
+ if (line.startsWith(HEADING_PREFIX)) {
|
|
|
+ line = line.substring(HEADING_PREFIX.length())
|
|
|
+ heading = line + ' > '
|
|
|
+ } else {
|
|
|
+ line = heading + line
|
|
|
+ }
|
|
|
+ } else if (inProgressReport) {
|
|
|
+ inProgressReport = false
|
|
|
+ line = lastLine + line
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // debugLogLine(line) // Uncomment me to log every line we add to the logger
|
|
|
+ progressLogger.progress(line)
|
|
|
}
|
|
|
- // debugLogLine(line) // Uncomment me to log every line we add to the logger
|
|
|
- progressLogger.progress(line)
|
|
|
- }
|
|
|
|
|
|
- void debugPrintLine(line) {
|
|
|
- System.out.print '----------> '
|
|
|
- for (int i = start; i < end; i++) {
|
|
|
- switch (buffer[i] as char) {
|
|
|
- case ' '..'~':
|
|
|
- System.out.print buffer[i] as char
|
|
|
- break
|
|
|
- default:
|
|
|
- System.out.print '%'
|
|
|
- System.out.print Integer.toHexString(buffer[i])
|
|
|
- }
|
|
|
+ void debugPrintLine(line) {
|
|
|
+ System.out.print '----------> '
|
|
|
+ for (int i = start; i < end; i++) {
|
|
|
+ switch (buffer[i] as char) {
|
|
|
+ case ' '..'~':
|
|
|
+ System.out.print buffer[i] as char
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ System.out.print '%'
|
|
|
+ System.out.print Integer.toHexString(buffer[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.print '\n'
|
|
|
}
|
|
|
- System.out.print '\n'
|
|
|
- }
|
|
|
|
|
|
- void debugLogLine(line) {
|
|
|
- System.out.print '>>>>>>>>>>> '
|
|
|
- System.out.print line
|
|
|
- System.out.print '\n'
|
|
|
- }
|
|
|
+ void debugLogLine(line) {
|
|
|
+ System.out.print '>>>>>>>>>>> '
|
|
|
+ System.out.print line
|
|
|
+ System.out.print '\n'
|
|
|
+ }
|
|
|
}
|