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.info;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.maven.scm.command.info.InfoItem;
25  import org.apache.maven.scm.util.AbstractConsumer;
26  
27  /**
28   * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
29   *
30   */
31  public class SvnInfoConsumer extends AbstractConsumer {
32      private final List<InfoItem> infoItems = new ArrayList<>();
33  
34      private InfoItem currentItem = new InfoItem();
35  
36      /** {@inheritDoc} */
37      public void consumeLine(String s) {
38          if (s.equals("")) {
39              if (currentItem != null) {
40                  infoItems.add(currentItem);
41              }
42  
43              currentItem = new InfoItem();
44          } else if (s.startsWith("Path: ")) {
45              currentItem.setPath(getValue(s));
46          } else if (s.startsWith("URL: ")) {
47              currentItem.setURL(getValue(s));
48          } else if (s.startsWith("Repository Root: ")) {
49              currentItem.setRepositoryRoot(getValue(s));
50          } else if (s.startsWith("Repository UUID: ")) {
51              currentItem.setRepositoryUUID(getValue(s));
52          } else if (s.startsWith("Revision: ")) {
53              currentItem.setRevision(getValue(s));
54          } else if (s.startsWith("Node Kind: ")) {
55              currentItem.setNodeKind(getValue(s));
56          } else if (s.startsWith("Schedule: ")) {
57              currentItem.setSchedule(getValue(s));
58          } else if (s.startsWith("Last Changed Author: ")) {
59              currentItem.setLastChangedAuthor(getValue(s));
60          } else if (s.startsWith("Last Changed Rev: ")) {
61              currentItem.setLastChangedRevision(getValue(s));
62          } else if (s.startsWith("Last Changed Date: ")) {
63              currentItem.setLastChangedDate(getValue(s));
64          }
65      }
66  
67      private static String getValue(String s) {
68          int idx = s.indexOf(": ");
69  
70          if (idx < 0) {
71              // FIXME: Can't throw any exceptions in consumeLine..
72              return null;
73          } else {
74              return s.substring(idx + 2);
75          }
76      }
77  
78      public List<InfoItem> getInfoItems() {
79          return infoItems;
80      }
81  }