View Javadoc
1   package org.apache.maven.scm.provider.svn.svnexe.command.mkdir;
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.ScmFile;
26  import org.apache.maven.scm.ScmFileStatus;
27  import org.apache.maven.scm.log.ScmLogger;
28  import org.codehaus.plexus.util.StringUtils;
29  import org.codehaus.plexus.util.cli.StreamConsumer;
30  
31  /**
32   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
33   *
34   */
35  public class SvnMkdirConsumer
36      implements StreamConsumer
37  {
38      private ScmLogger logger;
39  
40      private static final String COMMITTED_REVISION_TOKEN = "Committed revision";
41  
42      private int revision;
43      
44      private List<ScmFile> createdDirs = new ArrayList<ScmFile>();
45      
46      public SvnMkdirConsumer( ScmLogger logger )
47      {
48          this.logger = logger;
49      }
50      
51      /** {@inheritDoc} */
52      public void consumeLine( String line )
53      {
54          if ( StringUtils.isBlank( line ) )
55          {
56              return;
57          }
58          
59          String statusString = line.substring( 0, 1 );
60          ScmFileStatus status;
61         
62          if ( line.startsWith( COMMITTED_REVISION_TOKEN ) )
63          {
64              String revisionString = line.substring( COMMITTED_REVISION_TOKEN.length() + 1, line.length() - 1 );
65  
66              revision = Integer.parseInt( revisionString );
67              
68              return;
69          }
70          else if( statusString.equals( "A" ) )
71          {
72              String file = line.substring( 3 );
73              
74              status = ScmFileStatus.ADDED;
75              
76              createdDirs.add( new ScmFile( file, status ) );
77          }        
78          else
79          {
80              if ( logger.isInfoEnabled() )
81              {
82                  logger.info( "Unknown line: '" + line + "'" );
83              }
84  
85              return;
86          }
87      }
88  
89      public int getRevision()
90      {
91          return revision;
92      }
93      
94      public List<ScmFile> getCreatedDirs()
95      {
96          return createdDirs;
97      }
98  }