KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > perforce > SimpleP4OutputHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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     // CheckStyle:VisibilityModifier ON
39

40     /**
41      * simple constructor
42      * @param parent a P4Base instance
43      */

44     public SimpleP4OutputHandler(P4Base parent) {
45         this.parent = parent;
46     }
47
48     /**
49      * process one line of stderr/stdout
50      * if error conditions are detected, then setters are called on the
51      * parent
52      * @param line line of output
53      * @throws BuildException does not throw exceptions any more
54      */

55     public void process(String JavaDoc line) throws BuildException {
56         if (parent.util.match("/^exit/", line)) {
57             return;
58         }
59
60         //Throw exception on errors (except up-to-date)
61
//
62
//When a server is down, the code expects :
63
//Perforce client error:
64
//Connect to server failed; check $P4PORT.
65
//TCP connect to localhost:1666 failed.
66
//connect: localhost:1666: Connection refused
67
//Some forms producing commands (p4 -s change -o) do tag the output
68
//others don't.....
69
//Others mark errors as info, for example edit a file
70
//which is already open for edit.....
71
//Just look for error: - catches most things....
72

73         if (parent.util.match("/^error:/", line)
74             || parent.util.match("/^Perforce client error:/", line)) {
75             //when running labelsync, if view elements are in sync,
76
//Perforce produces a line of output
77
//looking like this one :
78
//error: //depot/file2 - label in sync.
79
if (!parent.util.match("/label in sync/", line)
80                 && !parent.util.match("/up-to-date/", line)) {
81                 parent.setInError(true);
82             } else {
83                 //sync says "error:" when a file is up-to-date
84
line = parent.util.substitute("s/^[^:]*: //", line);
85             }
86         } else if (parent.util.match("/^info.*?:/", line)) {
87             //sometimes there's "info1:
88
line = parent.util.substitute("s/^[^:]*: //", line);
89         }
90         parent.log(line, parent.getInError() ? Project.MSG_ERR : Project.MSG_INFO);
91
92         if (parent.getInError()) {
93             parent.setErrorMessage(parent.getErrorMessage() + line + StringUtils.LINE_SEP);
94         }
95     }
96 }
97
Popular Tags