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: * Portions of this software are based upon public domain software
20: * originally written at the National Center for Supercomputing Applications,
21: * University of Illinois, Urbana-Champaign.
22: */
23:
24: package org.apache.tools.ant.taskdefs.optional.perforce;
25:
26: import org.apache.tools.ant.BuildException;
27: import org.apache.tools.ant.Project;
28: import org.apache.tools.ant.util.StringUtils;
29:
30: /**
31: * simple implementation of P4HandlerAdapter used by tasks which are not
32: * actually processing the output from Perforce
33: */
34: public class SimpleP4OutputHandler extends P4HandlerAdapter {
35:
36: // CheckStyle:VisibilityModifier OFF - bc
37: P4Base parent;
38:
39: // CheckStyle:VisibilityModifier ON
40:
41: /**
42: * simple constructor
43: * @param parent a P4Base instance
44: */
45: public SimpleP4OutputHandler(P4Base parent) {
46: this .parent = parent;
47: }
48:
49: /**
50: * process one line of stderr/stdout
51: * if error conditions are detected, then setters are called on the
52: * parent
53: * @param line line of output
54: * @throws BuildException does not throw exceptions any more
55: */
56: public void process(String line) throws BuildException {
57: if (parent.util.match("/^exit/", line)) {
58: return;
59: }
60:
61: //Throw exception on errors (except up-to-date)
62: //
63: //When a server is down, the code expects :
64: //Perforce client error:
65: //Connect to server failed; check $P4PORT.
66: //TCP connect to localhost:1666 failed.
67: //connect: localhost:1666: Connection refused
68: //Some forms producing commands (p4 -s change -o) do tag the output
69: //others don't.....
70: //Others mark errors as info, for example edit a file
71: //which is already open for edit.....
72: //Just look for error: - catches most things....
73:
74: if (parent.util.match("/^error:/", line)
75: || parent.util.match("/^Perforce client error:/", line)) {
76: //when running labelsync, if view elements are in sync,
77: //Perforce produces a line of output
78: //looking like this one :
79: //error: //depot/file2 - label in sync.
80: if (!parent.util.match("/label in sync/", line)
81: && !parent.util.match("/up-to-date/", line)) {
82: parent.setInError(true);
83: } else {
84: //sync says "error:" when a file is up-to-date
85: line = parent.util.substitute("s/^[^:]*: //", line);
86: }
87: } else if (parent.util.match("/^info.*?:/", line)) {
88: //sometimes there's "info1:
89: line = parent.util.substitute("s/^[^:]*: //", line);
90: }
91: parent.log(line, parent.getInError() ? Project.MSG_ERR
92: : Project.MSG_INFO);
93:
94: if (parent.getInError()) {
95: parent.setErrorMessage(parent.getErrorMessage() + line
96: + StringUtils.LINE_SEP);
97: }
98: }
99: }
|