source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.8 KB
Line 
1/*
2 * Copyright 2001-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
18package org.apache.tools.ant.taskdefs.optional.perforce;
19
20import java.io.ByteArrayInputStream;
21import java.io.IOException;
22import java.io.InputStream;
23import java.io.OutputStream;
24
25import org.apache.tools.ant.BuildException;
26import org.apache.tools.ant.taskdefs.PumpStreamHandler;
27/**
28 * base class to manage streams around the execution of the Perforce
29 * command line client
30 */
31public abstract class P4HandlerAdapter implements P4Handler {
32
33 String p4input = "";
34 private PumpStreamHandler myHandler = null;
35 /**
36 * set any data to be written to P4's stdin
37 * @param p4Input the text to write to P4's stdin
38 */
39 public void setOutput(String p4Input) {
40 this.p4input = p4Input;
41 }
42 /**
43 * subclasses of P4HandlerAdapter must implement this routine
44 * processing of one line of stdout or of stderr
45 * @param line line of stdout or stderr to process
46 */
47 public abstract void process(String line);
48
49 /**
50 * this routine gets called by the execute routine of the Execute class
51 * it connects the PumpStreamHandler to the input/output/error streams of the process.
52 * @throws BuildException
53 * @see org.apache.tools.ant.taskdefs.Execute#execute
54 */
55 public void start() throws BuildException {
56 if (p4input != null && p4input.length() > 0) {
57 myHandler = new PumpStreamHandler(new P4OutputStream(this), new P4OutputStream(this),
58 new ByteArrayInputStream(p4input.getBytes()));
59 } else {
60 myHandler = new PumpStreamHandler(new P4OutputStream(this), new P4OutputStream(this));
61 }
62 myHandler.setProcessInputStream(os);
63 myHandler.setProcessErrorStream(es);
64 myHandler.setProcessOutputStream(is);
65 myHandler.start();
66 }
67
68 /**
69 * stops the processing of streams
70 * called from P4Base#execP4Command(String command, P4Handler handler)
71 * @see P4Base#execP4Command(String, P4Handler)
72 */
73 public void stop() {
74 myHandler.stop();
75 }
76
77 OutputStream os; //Input
78 InputStream is; //Output
79 InputStream es; //Error
80
81 /**
82 * connects the handler to the input stream into Perforce
83 * used indirectly by tasks requiring to send specific standard input
84 * such as p4label, p4change
85 * @param os the stream bringing input to the p4 executable
86 * @throws IOException under unknown circumstances
87 */
88 public void setProcessInputStream(OutputStream os) throws IOException {
89 this.os = os;
90 }
91
92 /**
93 * connects the handler to the stderr of the Perforce process
94 * @param is stderr coming from Perforce
95 * @throws IOException under unknown circumstances
96 */
97 public void setProcessErrorStream(InputStream is) throws IOException {
98 this.es = is;
99 }
100
101 /**
102 * connects the handler to the stdout of the Perforce process
103 * @param is stdout coming from Perforce
104 * @throws IOException under unknown circumstances
105 */
106 public void setProcessOutputStream(InputStream is) throws IOException {
107 this.is = is;
108 }
109}
Note: See TracBrowser for help on using the repository browser.