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   */
36  public class SvnUpdateConsumer extends AbstractFileCheckingConsumer {
37      private static final String UPDATED_TO_REVISION_TOKEN = "Updated to revision";
38  
39      private static final String AT_REVISION_TOKEN = "At revision";
40  
41      private static final String EXPORTED_REVISION_TOKEN = "Exported revision";
42  
43      private static final String RESTORED_TOKEN = "Restored";
44  
45      private List<ChangeSet> changeSets = new ArrayList<>();
46  
47      // ----------------------------------------------------------------------
48      //
49      // ----------------------------------------------------------------------
50  
51      public SvnUpdateConsumer(File workingDirectory) {
52          super(workingDirectory);
53      }
54  
55      // ----------------------------------------------------------------------
56      // StreamConsumer Implementation
57      // ----------------------------------------------------------------------
58  
59      /** {@inheritDoc} */
60      protected void parseLine(String line) {
61          line = line.trim();
62  
63          String statusString = line.substring(0, 1);
64  
65          String file = line.substring(3).trim();
66          // [SCM-368]
67          if (file.startsWith(workingDirectory.getAbsolutePath())) {
68              if (file.length() == workingDirectory.getAbsolutePath().length()) {
69                  file = ".";
70              } else {
71                  file = file.substring(this.workingDirectory.getAbsolutePath().length() + 1);
72              }
73          }
74  
75          ScmFileStatus status;
76  
77          if (line.startsWith(UPDATED_TO_REVISION_TOKEN)) {
78              String revisionString = line.substring(UPDATED_TO_REVISION_TOKEN.length() + 1, line.length() - 1);
79  
80              revision = parseInt(revisionString);
81  
82              return;
83          } else if (line.startsWith(AT_REVISION_TOKEN)) {
84              String revisionString = line.substring(AT_REVISION_TOKEN.length() + 1, line.length() - 1);
85  
86              revision = parseInt(revisionString);
87  
88              return;
89          } else if (line.startsWith(EXPORTED_REVISION_TOKEN)) {
90              String revisionString = line.substring(EXPORTED_REVISION_TOKEN.length() + 1, line.length() - 1);
91  
92              revision = parseInt(revisionString);
93  
94              return;
95          } else if (line.startsWith(RESTORED_TOKEN)) {
96              return;
97          } else if (statusString.equals("A")) {
98              status = ScmFileStatus.ADDED;
99          } else if (statusString.equals("U") || statusString.equals("M")) {
100             status = ScmFileStatus.UPDATED;
101         } else if (statusString.equals("D")) {
102             status = ScmFileStatus.DELETED;
103         } else {
104             // Do nothing
105 
106             return;
107         }
108 
109         addFile(new ScmFile(file, status));
110 
111         List<ChangeFile> changeFiles = Arrays.asList(
112                 new ChangeFile[] {new ChangeFile(line, Integer.valueOf(revision).toString())});
113 
114         ChangeSet changeSet = new ChangeSet(null, null, null, changeFiles);
115         changeSets.add(changeSet);
116     }
117 
118     public List<ScmFile> getUpdatedFiles() {
119         return getFiles();
120     }
121 
122     public List<ChangeSet> getChangeSets() {
123         return changeSets;
124     }
125 
126     public void setChangeSets(List<ChangeSet> changeSets) {
127         this.changeSets = changeSets;
128     }
129 }