package com.github.blindpirate.gogradle.build;

import com.github.blindpirate.gogradle.util.ExceptionHandler;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static com.github.blindpirate.gogradle.GogradleGlobal.DEFAULT_CHARSET;

public class SubprocessReader extends Thread {
    private Supplier<InputStream> is;
    private CountDownLatch latch;
    private Consumer<String> consumer;

    public SubprocessReader(Supplier<InputStream> is,
                            Consumer<String> consumer,
                            CountDownLatch latch) {
        this.is = is;
        this.latch = latch;
        this.consumer = consumer;
    }

    @Override
    public void run() {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(is.get(), DEFAULT_CHARSET))) {
            String line;
            try {
                while ((line = br.readLine()) != null) {
                    consumer.accept(line);
                }
            } catch (IOException e) {
                consumer.accept(ExceptionHandler.getStackTrace(e));
            }
        } catch (IOException e) {
            throw ExceptionHandler.uncheckException(e);
        } finally {
            latch.countDown();
        }
    }
}

@@ -301,24 +301,61 @@
 n.Consumer;%0A
+import java.util.function.Predicate;%0A
 import java.
@@ -374,24 +374,24 @@
 n.Supplier;%0A
-
 %0Aimport stat
@@ -615,16 +615,73 @@
 onsumer;
+%0A    private Predicate%3CString%3E lineFilter = line -%3E true;
 %0A%0A    pu
@@ -926,16 +926,364 @@
 %0A    %7D%0A%0A
+    public SubprocessReader(Supplier%3CInputStream%3E is,%0A                            Consumer%3CString%3E consumer,%0A                            CountDownLatch latch,%0A                            Predicate%3CString%3E lineFilter) %7B%0A        this.is = is;%0A        this.latch = latch;%0A        this.consumer = consumer;%0A        this.lineFilter = lineFilter;%0A    %7D%0A%0A
     @Ove
@@ -1513,24 +1513,77 @@
  != null) %7B%0A
+                    if (lineFilter.test(line)) %7B%0A    
             
@@ -1609,24 +1609,46 @@
 cept(line);%0A
+                    %7D%0A
             

Add line predicate to filter output lines