|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 package com.symbian.ant; |
|
17 |
|
18 import java.io.BufferedReader; |
|
19 import java.io.IOException; |
|
20 import java.io.StringReader; |
|
21 |
|
22 import org.apache.tools.ant.BuildEvent; |
|
23 import org.apache.tools.ant.DefaultLogger; |
|
24 import org.apache.tools.ant.Project; |
|
25 import org.apache.tools.ant.util.StringUtils; |
|
26 |
|
27 public class ScanLogger extends DefaultLogger { |
|
28 |
|
29 /** |
|
30 * Logs a message, if the priority is suitable. |
|
31 * In non-emacs mode, task level messages are prefixed by the |
|
32 * task name which is right-justified. |
|
33 * |
|
34 * @param event A BuildEvent containing message information. |
|
35 * Must not be <code>null</code>. |
|
36 */ |
|
37 public void messageLogged(BuildEvent event) { |
|
38 int priority = event.getPriority(); |
|
39 // Filter out messages based on priority |
|
40 if (priority <= msgOutputLevel) { |
|
41 |
|
42 StringBuffer message = new StringBuffer(); |
|
43 if (event.getTask() != null && !emacsMode) { |
|
44 // Print out the name of the task if we're in one |
|
45 String name = event.getTask().getTaskName(); |
|
46 String label = "[" + name + "] "; |
|
47 int size = LEFT_COLUMN_SIZE - label.length(); |
|
48 StringBuffer tmp = new StringBuffer(); |
|
49 for (int i = 0; i < size; i++) { |
|
50 tmp.append(" "); |
|
51 } |
|
52 tmp.append(label); |
|
53 label = tmp.toString(); |
|
54 |
|
55 try { |
|
56 BufferedReader r = |
|
57 new BufferedReader( |
|
58 new StringReader(event.getMessage())); |
|
59 String line = r.readLine(); |
|
60 boolean first = true; |
|
61 while (line != null) { |
|
62 if (!first) { |
|
63 message.append(StringUtils.LINE_SEP); |
|
64 } |
|
65 first = false; |
|
66 message.append(label).append(line); |
|
67 line = r.readLine(); |
|
68 } |
|
69 } catch (IOException e) { |
|
70 // shouldn't be possible |
|
71 message.append("ERROR:").append(label).append(event.getMessage()); |
|
72 } |
|
73 } else { |
|
74 message.append(event.getMessage()); |
|
75 } |
|
76 |
|
77 String msg = message.toString(); |
|
78 if (priority != Project.MSG_ERR) { |
|
79 printMessage(msg, out, priority); |
|
80 } else { |
|
81 printMessage("ERROR:" + msg, err, priority); |
|
82 } |
|
83 log(msg); |
|
84 } |
|
85 } |
|
86 } |