View Javadoc
1   package org.apache.maven.scm.provider.svn.svnexe.command.update;
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 java.io.File;
23  import java.util.ArrayList;
24  import java.util.Arrays;
25  import java.util.List;
26  
27  import org.apache.maven.scm.ChangeFile;
28  import org.apache.maven.scm.ChangeSet;
29  import org.apache.maven.scm.ScmFile;
30  import org.apache.maven.scm.ScmFileStatus;
31  import org.apache.maven.scm.provider.svn.svnexe.command.AbstractFileCheckingConsumer;
32  
33  /**
34   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
35   *
36   */
37  public class SvnUpdateConsumer
38      extends AbstractFileCheckingConsumer
39  {
40      private static final String UPDATED_TO_REVISION_TOKEN = "Updated to revision";
41  
42      private static final String AT_REVISION_TOKEN = "At revision";
43  
44      private static final String EXPORTED_REVISION_TOKEN = "Exported revision";
45  
46      private static final String RESTORED_TOKEN = "Restored";
47      
48      private List<ChangeSet> changeSets = new ArrayList<>();
49  
50      // ----------------------------------------------------------------------
51      //
52      // ----------------------------------------------------------------------
53  
54      public SvnUpdateConsumer( File workingDirectory )
55      {
56          super( workingDirectory );
57      }
58  
59      // ----------------------------------------------------------------------
60      // StreamConsumer Implementation
61      // ----------------------------------------------------------------------
62  
63      /** {@inheritDoc} */
64      protected void parseLine( String line )
65      {
66          line = line.trim();
67  
68          String statusString = line.substring( 0, 1 );
69  
70          String file = line.substring( 3 ).trim();
71          //[SCM-368]
72          if ( file.startsWith( workingDirectory.getAbsolutePath() ) )
73          {
74              if ( file.length() == workingDirectory.getAbsolutePath().length() )
75              {
76                  file = ".";
77              }
78              else
79              {
80                  file = file.substring( this.workingDirectory.getAbsolutePath().length() + 1 );
81              }
82          }
83  
84          ScmFileStatus status;
85  
86          if ( line.startsWith( UPDATED_TO_REVISION_TOKEN ) )
87          {
88              String revisionString = line.substring( UPDATED_TO_REVISION_TOKEN.length() + 1, line.length() - 1 );
89  
90              revision = parseInt( revisionString );
91  
92              return;
93          }
94          else if ( line.startsWith( AT_REVISION_TOKEN ) )
95          {
96              String revisionString = line.substring( AT_REVISION_TOKEN.length() + 1, line.length() - 1 );
97  
98              revision = parseInt( revisionString );
99  
100             return;
101         }
102         else if ( line.startsWith( EXPORTED_REVISION_TOKEN ) )
103         {
104             String revisionString = line.substring( EXPORTED_REVISION_TOKEN.length() + 1, line.length() - 1 );
105 
106             revision = parseInt( revisionString );
107 
108             return;
109         }
110         else if ( line.startsWith( RESTORED_TOKEN ) )
111         {
112             return;
113         }
114         else if ( statusString.equals( "A" ) )
115         {
116             status = ScmFileStatus.ADDED;
117         }
118         else if ( statusString.equals( "U" ) || statusString.equals( "M" ) )
119         {
120             status = ScmFileStatus.UPDATED;
121         }
122         else if ( statusString.equals( "D" ) )
123         {
124             status = ScmFileStatus.DELETED;
125         }
126         else
127         {
128             //Do nothing
129 
130             return;
131         }
132 
133         addFile( new ScmFile( file, status ) );
134         
135         List<ChangeFile>
136         changeFiles =
137             Arrays.asList( new ChangeFile[] { new ChangeFile( line, Integer.valueOf( revision ).toString() ) } );
138 
139         ChangeSet changeSet = new ChangeSet( null, null, null, changeFiles );
140         changeSets.add( changeSet );
141     }
142 
143     public List<ScmFile> getUpdatedFiles()
144     {
145         return getFiles();
146     }
147 
148     public List<ChangeSet> getChangeSets()
149     {
150         return changeSets;
151     }
152 
153     public void setChangeSets( List<ChangeSet> changeSets )
154     {
155         this.changeSets = changeSets;
156     }
157 }