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