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