1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.scala_tools.maven;
17
18 import java.io.BufferedReader;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
22 import java.io.PrintWriter;
23
24 import org.apache.maven.plugin.logging.Log;
25 import org.codehaus.plexus.util.IOUtil;
26 import org.codehaus.plexus.util.StringUtils;
27
28 public class StreamLogger extends Thread {
29 private static final String LS = System.getProperty("line.separator");
30 private static final boolean emacsMode = StringUtils.isNotEmpty(System.getProperty("emacsMode"));
31
32 private InputStream in_;
33 private Log log_;
34 private boolean isErr_;
35 private PrintWriter out_;
36
37 public StreamLogger(InputStream in, Log log, boolean isErr) {
38 in_ = in;
39 log_ = log;
40 isErr_ = isErr;
41 }
42
43 @Override
44 public void run() {
45 BufferedReader reader = null;
46 try {
47 reader = new BufferedReader(new InputStreamReader(in_));
48 String line = null;
49 StringBuilder sb = null;
50 while ((line = reader.readLine()) != null) {
51 if (isErr_) {
52 if (!emacsMode) {
53 log_.warn(line);
54 } else {
55 if (sb == null) {
56 sb = new StringBuilder("Compilation failure"+ LS);
57 }
58 sb.append(LS + line);
59 }
60 } else {
61 log_.info(line);
62 }
63 }
64 if (sb != null) {
65 log_.warn(sb.toString());
66 }
67 } catch(IOException exc) {
68 throw new RuntimeException("wrap: " + exc.getMessage(), exc);
69 } finally {
70 IOUtil.close(reader);
71 IOUtil.close(in_);
72 IOUtil.close(out_);
73 }
74 }
75 }