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