View Javadoc
1   package org.apache.maven.scm.provider.svn.svnexe.command.info;
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.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.scm.command.info.InfoItem;
26  import org.codehaus.plexus.util.cli.StreamConsumer;
27  
28  /**
29   * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
30   *
31   */
32  public class SvnInfoConsumer
33      implements StreamConsumer
34  {
35      private List<InfoItem> infoItems = new ArrayList<InfoItem>();
36  
37      private InfoItem currentItem = new InfoItem();
38  
39      /** {@inheritDoc} */
40      public void consumeLine( String s )
41      {
42          if ( s.equals( "" ) )
43          {
44              if ( currentItem != null )
45              {
46                  infoItems.add( currentItem );
47              }
48  
49              currentItem = new InfoItem();
50          }
51          else if ( s.startsWith( "Path: " ) )
52          {
53              currentItem.setPath( getValue( s ) );
54          }
55          else if ( s.startsWith( "URL: " ) )
56          {
57              currentItem.setURL( getValue( s ) );
58          }
59          else if ( s.startsWith( "Repository Root: " ) )
60          {
61              currentItem.setRepositoryRoot( getValue( s ) );
62          }
63          else if ( s.startsWith( "Repository UUID: " ) )
64          {
65              currentItem.setRepositoryUUID( getValue( s ) );
66          }
67          else if ( s.startsWith( "Revision: " ) )
68          {
69              currentItem.setRevision( getValue( s ) );
70          }
71          else if ( s.startsWith( "Node Kind: " ) )
72          {
73              currentItem.setNodeKind( getValue( s ) );
74          }
75          else if ( s.startsWith( "Schedule: " ) )
76          {
77              currentItem.setSchedule( getValue( s ) );
78          }
79          else if ( s.startsWith( "Last Changed Author: " ) )
80          {
81              currentItem.setLastChangedAuthor( getValue( s ) );
82          }
83          else if ( s.startsWith( "Last Changed Rev: " ) )
84          {
85              currentItem.setLastChangedRevision( getValue( s ) );
86          }
87          else if ( s.startsWith( "Last Changed Date: " ) )
88          {
89              currentItem.setLastChangedDate( getValue( s ) );
90          }
91      }
92  
93      private static String getValue( String s )
94      {
95          int idx = s.indexOf( ": " );
96  
97          if ( idx < 0 )
98          {
99              // FIXME: Can't throw any exceptions in consumeLine..
100             return null;
101         }
102         else
103         {
104             return s.substring( idx + 2 );
105         }
106     }
107 
108     public List<InfoItem> getInfoItems()
109     {
110         return infoItems;
111     }
112 }