1 | /*
|
---|
2 | * Copyright 2000,2002-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs;
|
---|
19 |
|
---|
20 | import java.io.IOException;
|
---|
21 | import java.io.OutputStream;
|
---|
22 | import org.apache.tools.ant.Task;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Redirects text written to a stream thru the standard
|
---|
26 | * ant logging mechanism. This class is useful for integrating
|
---|
27 | * with tools that write to System.out and System.err. For example,
|
---|
28 | * the following will cause all text written to System.out to be
|
---|
29 | * logged with "info" priority:
|
---|
30 | * <pre>System.setOut(new PrintStream(new TaskOutputStream(project, Project.MSG_INFO)));</pre>
|
---|
31 | *
|
---|
32 | * <p><strong>As of Ant 1.2, this class is considered to be dead code
|
---|
33 | * by the Ant developers and is unmaintained. Don't use
|
---|
34 | * it.</strong></p>
|
---|
35 | *
|
---|
36 | * @deprecated use LogOutputStream instead.
|
---|
37 | */
|
---|
38 |
|
---|
39 | public class TaskOutputStream extends OutputStream {
|
---|
40 |
|
---|
41 | private Task task;
|
---|
42 | private StringBuffer line;
|
---|
43 | private int msgOutputLevel;
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Constructs a new JavacOutputStream with the given project
|
---|
47 | * as the output source for messages.
|
---|
48 | */
|
---|
49 |
|
---|
50 | TaskOutputStream(Task task, int msgOutputLevel) {
|
---|
51 | System.err.println("As of Ant 1.2 released in October 2000, the "
|
---|
52 | + "TaskOutputStream class");
|
---|
53 | System.err.println("is considered to be dead code by the Ant "
|
---|
54 | + "developers and is unmaintained.");
|
---|
55 | System.err.println("Don\'t use it!");
|
---|
56 |
|
---|
57 | this.task = task;
|
---|
58 | this.msgOutputLevel = msgOutputLevel;
|
---|
59 |
|
---|
60 | line = new StringBuffer();
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Write a character to the output stream. This method looks
|
---|
65 | * to make sure that there isn't an error being reported and
|
---|
66 | * will flush each line of input out to the project's log stream.
|
---|
67 | */
|
---|
68 |
|
---|
69 | public void write(int c) throws IOException {
|
---|
70 | char cc = (char) c;
|
---|
71 | if (cc == '\r' || cc == '\n') {
|
---|
72 | // line feed
|
---|
73 | if (line.length() > 0) {
|
---|
74 | processLine();
|
---|
75 | }
|
---|
76 | } else {
|
---|
77 | line.append(cc);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Processes a line of input and determines if an error occurred.
|
---|
83 | */
|
---|
84 |
|
---|
85 | private void processLine() {
|
---|
86 | String s = line.toString();
|
---|
87 | task.log(s, msgOutputLevel);
|
---|
88 | line = new StringBuffer();
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|