View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider.svn.svnexe.command.update;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.List;
25  
26  import org.apache.maven.scm.ChangeFile;
27  import org.apache.maven.scm.ChangeSet;
28  import org.apache.maven.scm.ScmFile;
29  import org.apache.maven.scm.ScmFileStatus;
30  import org.apache.maven.scm.provider.svn.svnexe.command.AbstractFileCheckingConsumer;
31  
32  /**
33   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
34   */
35  public class SvnUpdateConsumer extends AbstractFileCheckingConsumer {
36      private static final String UPDATED_TO_REVISION_TOKEN = "Updated to revision";
37  
38      private static final String AT_REVISION_TOKEN = "At revision";
39  
40      private static final String EXPORTED_REVISION_TOKEN = "Exported revision";
41  
42      private static final String RESTORED_TOKEN = "Restored";
43  
44      private List<ChangeSet> changeSets = new ArrayList<>();
45  
46      // ----------------------------------------------------------------------
47      //
48      // ----------------------------------------------------------------------
49  
50      public SvnUpdateConsumer(File workingDirectory) {
51          super(workingDirectory);
52      }
53  
54      // ----------------------------------------------------------------------
55      // StreamConsumer Implementation
56      // ----------------------------------------------------------------------
57  
58      /**
59       * {@inheritDoc}
60       */
61      protected void parseLine(String line) {
62          line = line.trim();
63  
64          String statusString = line.substring(0, 1);
65  
66          String file = line.substring(3).trim();
67          // [SCM-368]
68          if (file.startsWith(workingDirectory.getAbsolutePath())) {
69              if (file.length() == workingDirectory.getAbsolutePath().length()) {
70                  file = ".";
71              } else {
72                  file = file.substring(this.workingDirectory.getAbsolutePath().length() + 1);
73              }
74          }
75  
76          ScmFileStatus status;
77  
78          if (line.startsWith(UPDATED_TO_REVISION_TOKEN)) {
79              String revisionString = line.substring(UPDATED_TO_REVISION_TOKEN.length() + 1, line.length() - 1);
80  
81              revision = parseInt(revisionString);
82  
83              return;
84          } else if (line.startsWith(AT_REVISION_TOKEN)) {
85              String revisionString = line.substring(AT_REVISION_TOKEN.length() + 1, line.length() - 1);
86  
87              revision = parseInt(revisionString);
88  
89              return;
90          } else if (line.startsWith(EXPORTED_REVISION_TOKEN)) {
91              String revisionString = line.substring(EXPORTED_REVISION_TOKEN.length() + 1, line.length() - 1);
92  
93              revision = parseInt(revisionString);
94  
95              return;
96          } else if (line.startsWith(RESTORED_TOKEN)) {
97              return;
98          } else if (statusString.equals("A")) {
99              status = ScmFileStatus.ADDED;
100         } else if (statusString.equals("U") || statusString.equals("M")) {
101             status = ScmFileStatus.UPDATED;
102         } else if (statusString.equals("D")) {
103             status = ScmFileStatus.DELETED;
104         } else {
105             // Do nothing
106 
107             return;
108         }
109 
110         addFile(new ScmFile(file, status));
111 
112         List<ChangeFile> changeFiles = Arrays.asList(
113                 new ChangeFile[] {new ChangeFile(line, Integer.valueOf(revision).toString())});
114 
115         ChangeSet changeSet = new ChangeSet(null, null, null, changeFiles);
116         changeSets.add(changeSet);
117     }
118 
119     public List<ScmFile> getUpdatedFiles() {
120         return getFiles();
121     }
122 
123     public List<ChangeSet> getChangeSets() {
124         return changeSets;
125     }
126 
127     public void setChangeSets(List<ChangeSet> changeSets) {
128         this.changeSets = changeSets;
129     }
130 }