| SystemLogger.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
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 }