1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.ant;
16  
17  import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
18  import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
19  import com.liferay.portal.kernel.util.StringBundler;
20  
21  import java.io.IOException;
22  
23  import org.apache.tools.ant.BuildEvent;
24  import org.apache.tools.ant.DefaultLogger;
25  import org.apache.tools.ant.Project;
26  import org.apache.tools.ant.util.StringUtils;
27  
28  /**
29   * <a href="SystemLogger.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class SystemLogger extends DefaultLogger {
34  
35      public void messageLogged(BuildEvent event) {
36          int priority = event.getPriority();
37  
38          if (priority <= msgOutputLevel) {
39              StringBundler sb = new StringBundler();
40  
41              try {
42                  UnsyncBufferedReader unsyncBufferedReader =
43                      new UnsyncBufferedReader(
44                          new UnsyncStringReader(event.getMessage()));
45  
46                  String line = unsyncBufferedReader.readLine();
47  
48                  boolean first = true;
49  
50                  while (line != null) {
51                      if (!first) {
52                          sb.append(StringUtils.LINE_SEP);
53                      }
54  
55                      first = false;
56  
57                      sb.append("  ");
58                      sb.append(line);
59  
60                      line = unsyncBufferedReader.readLine();
61                  }
62              }
63              catch (IOException e) {
64              }
65  
66              String msg = sb.toString();
67  
68              if (priority != Project.MSG_ERR) {
69                  printMessage(msg, out, priority);
70              }
71              else {
72                  printMessage(msg, err, priority);
73              }
74  
75              log(msg);
76          }
77      }
78  
79  }