01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.taskdefs;
20:
21: import java.io.IOException;
22: import org.apache.tools.ant.BuildException;
23: import org.apache.tools.ant.ProjectComponent;
24: import org.apache.tools.ant.Task;
25:
26: /**
27: * Logs standard output and error of a subprocess to the log system of ant.
28: *
29: * @since Ant 1.2
30: */
31: public class LogStreamHandler extends PumpStreamHandler {
32:
33: /**
34: * Creates log stream handler
35: *
36: * @param task the task for whom to log
37: * @param outlevel the loglevel used to log standard output
38: * @param errlevel the loglevel used to log standard error
39: */
40: public LogStreamHandler(Task task, int outlevel, int errlevel) {
41: this ((ProjectComponent) task, outlevel, errlevel);
42: }
43:
44: /**
45: * Creates log stream handler
46: *
47: * @param pc the project component for whom to log
48: * @param outlevel the loglevel used to log standard output
49: * @param errlevel the loglevel used to log standard error
50: */
51: public LogStreamHandler(ProjectComponent pc, int outlevel,
52: int errlevel) {
53: super (new LogOutputStream(pc, outlevel), new LogOutputStream(
54: pc, errlevel));
55: }
56:
57: /**
58: * Stop the log stream handler.
59: */
60: public void stop() {
61: super .stop();
62: try {
63: getErr().close();
64: getOut().close();
65: } catch (IOException e) {
66: // plain impossible
67: throw new BuildException(e);
68: }
69: }
70: }
|