1 package org.apache.maven.scm.provider.perforce.command.checkout;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.maven.scm.ScmFile;
23 import org.apache.maven.scm.ScmFileStatus;
24 import org.apache.maven.scm.provider.perforce.command.AbstractPerforceConsumer;
25 import org.apache.maven.scm.provider.perforce.command.PerforceVerbMapper;
26 import org.apache.regexp.RE;
27 import org.codehaus.plexus.util.cli.StreamConsumer;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33 * @author Mike Perham
34 * @version $Id: PerforceChangeLogConsumer.java 331276 2005-11-07 15:04:54Z
35 * evenisse $
36 */
37 public class PerforceCheckOutConsumer
38 extends AbstractPerforceConsumer
39 implements StreamConsumer
40 {
41 public static final int STATE_CLIENTSPEC = 0;
42
43 public static final int STATE_NORMAL = 1;
44
45 public static final int STATE_ERROR = 2;
46
47 private int currentState = STATE_CLIENTSPEC;
48
49 private RE fileRegexp = new RE( "([^#]+)#\\d+ - ([a-z]+)" );
50
51 private List<ScmFile> checkedout = new ArrayList<ScmFile>();
52
53 private String repo = null;
54
55 private String specname = null;
56
57 public PerforceCheckOutConsumer( String clientspec, String repoPath )
58 {
59 repo = repoPath;
60 specname = clientspec;
61 }
62
63 /*
64 * Client mperham-mikeperham-dt-maven saved.
65 */
66 /*
67 * //depot/modules/cordoba/runtime-ear/.j2ee#1 - deleted as
68 * d:\perforce\depot\modules\cordoba\runtime-ear\.j2ee
69 * //depot/modules/cordoba/runtime-ear/.project#1 - deleted as
70 * d:\perforce\depot\modules\cordoba\runtime-ear\.project
71 * //depot/modules/cordoba/runtime-ear/.runtime#1 - deleted as
72 * d:\perforce\depot\modules\cordoba\runtime-ear\.runtime
73 * //depot/modules/cordoba/runtime-ear/Foo.java#1 - deleted as
74 * d:\perforce\depot\modules\cordoba\runtime-ear\Foo.java
75 * //depot/modules/cordoba/runtime-ear/META-INF/.modulemaps#1 - deleted as
76 * d:\perforce\depot\modules\cordoba\runtime-ear\META-INF\.modulemaps
77 * //depot/modules/cordoba/runtime-ear/META-INF/application.xml#1 - deleted
78 * as d:\perforce\depot\modules\cordoba\runtime-ear\META-INF\application.xml
79 * //depot/modules/cordoba/runtime-ear/pom.xml#4 - deleted as
80 * d:\perforce\depot\modules\cordoba\runtime-ear\pom.xml
81 */
82 /*
83 * Invalid changelist/client/label/date '@somelabel'.
84 */
85 /** {@inheritDoc} */
86 public void consumeLine( String line )
87 {
88 if ( currentState == STATE_CLIENTSPEC
89 && ( line.startsWith( "Client " + specname + " saved." ) || line.startsWith( "Client " + specname
90 + " not changed." ) ) )
91 {
92 currentState = STATE_NORMAL;
93 return;
94 }
95
96 // Handle case where the clientspec is current
97 if ( currentState == STATE_NORMAL && line.indexOf( "ile(s) up-to-date" ) != -1 )
98 {
99 return;
100 }
101
102 if ( currentState != STATE_ERROR && fileRegexp.match( line ) )
103 {
104 String location = fileRegexp.getParen( 1 );
105 if ( location.startsWith( repo ) )
106 {
107 location = location.substring( repo.length() + 1 );
108 }
109 ScmFileStatus status = PerforceVerbMapper.toStatus( fileRegexp.getParen( 2 ) );
110 if ( status != null )
111 {
112 // there are cases where Perforce prints out something but the file did not
113 // actually change (especially when force syncing). Those files will have
114 // a null status.
115 checkedout.add( new ScmFile( location, status ) );
116 }
117 return;
118 }
119
120 error( line );
121 }
122
123 private void error( String line )
124 {
125 currentState = STATE_ERROR;
126 output.println( line );
127 }
128
129 public boolean isSuccess()
130 {
131 return currentState == STATE_NORMAL;
132 }
133
134 public List<ScmFile> getCheckedout()
135 {
136 return checkedout;
137 }
138 }