View Javadoc
1   package org.apache.maven.scm.provider.svn.svnexe.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.commons.lang.StringUtils;
23  import org.apache.maven.scm.ScmFile;
24  import org.apache.maven.scm.ScmFileStatus;
25  import org.apache.maven.scm.log.ScmLogger;
26  import org.apache.maven.scm.provider.svn.svnexe.command.AbstractFileCheckingConsumer;
27  
28  import java.io.File;
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  /**
33   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
34   * @author Olivier Lamy
35   *
36   */
37  public class SvnCheckOutConsumer
38      extends AbstractFileCheckingConsumer
39  {
40      private static final String CHECKED_OUT_REVISION_TOKEN = "Checked out revision";
41  
42      private List<ScmFile> files = new ArrayList<ScmFile>();
43  
44      public SvnCheckOutConsumer( ScmLogger logger, File workingDirectory )
45      {
46          super( logger, workingDirectory );
47      }
48  
49      /**
50       * {@inheritDoc}
51       */
52      protected void parseLine( String line )
53      {
54          String statusString = line.substring( 0, 1 );
55  
56          String file = line.substring( 3 ).trim();
57          //[SCM-368]
58          if ( file.startsWith( getWorkingDirectory().getAbsolutePath() ) )
59          {
60              file = StringUtils.substring( file, getWorkingDirectory().getAbsolutePath().length() + 1 );
61          }
62  
63          ScmFileStatus status;
64  
65          if ( line.startsWith( CHECKED_OUT_REVISION_TOKEN ) )
66          {
67              String revisionString = line.substring( CHECKED_OUT_REVISION_TOKEN.length() + 1, line.length() - 1 );
68  
69              revision = parseInt( revisionString );
70  
71              return;
72          }
73          else if ( statusString.equals( "A" ) )
74          {
75              status = ScmFileStatus.ADDED;
76          }
77          else if ( statusString.equals( "U" ) )
78          {
79              status = ScmFileStatus.UPDATED;
80          }
81          else
82          {
83              //Do nothing
84  
85              return;
86          }
87  
88          addFile( new ScmFile( file, status ) );
89      }
90  
91      // ----------------------------------------------------------------------
92      //
93      // ----------------------------------------------------------------------
94  
95      public List<ScmFile> getCheckedOutFiles()
96      {
97          return getFiles();
98      }
99  
100     protected void addFile( ScmFile file )
101     {
102         files.add( file );
103     }
104 
105     protected List<ScmFile> getFiles()
106     {
107         List<ScmFile> onlyFiles = new ArrayList<ScmFile>();
108         for ( ScmFile file : files )
109         {
110             // second part is for svn 1.7 as the co output is now relative not a full path as for svn 1.7-
111             if ( !( !file.getStatus().equals( ScmFileStatus.DELETED ) && !new File( getWorkingDirectory(),
112                                                                                     file.getPath() ).isFile() ) || !(
113                 !file.getStatus().equals( ScmFileStatus.DELETED ) && !new File( getWorkingDirectory().getParent(),
114                                                                                 file.getPath() ).isFile() ) )
115             {
116                 onlyFiles.add( file );
117             }
118         }
119 
120         return onlyFiles;
121     }
122 
123 }