001 package org.apache.maven.scm.provider.svn.svnexe.command.mkdir;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.ArrayList;
023 import java.util.List;
024
025 import org.apache.maven.scm.ScmFile;
026 import org.apache.maven.scm.ScmFileStatus;
027 import org.apache.maven.scm.log.ScmLogger;
028 import org.codehaus.plexus.util.StringUtils;
029 import org.codehaus.plexus.util.cli.StreamConsumer;
030
031 /**
032 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
033 *
034 */
035 public class SvnMkdirConsumer
036 implements StreamConsumer
037 {
038 private ScmLogger logger;
039
040 private static final String COMMITTED_REVISION_TOKEN = "Committed revision";
041
042 private int revision;
043
044 private List<ScmFile> createdDirs = new ArrayList<ScmFile>();
045
046 public SvnMkdirConsumer( ScmLogger logger )
047 {
048 this.logger = logger;
049 }
050
051 /** {@inheritDoc} */
052 public void consumeLine( String line )
053 {
054 if ( StringUtils.isBlank( line ) )
055 {
056 return;
057 }
058
059 String statusString = line.substring( 0, 1 );
060 ScmFileStatus status;
061
062 if ( line.startsWith( COMMITTED_REVISION_TOKEN ) )
063 {
064 String revisionString = line.substring( COMMITTED_REVISION_TOKEN.length() + 1, line.length() - 1 );
065
066 revision = Integer.parseInt( revisionString );
067
068 return;
069 }
070 else if( statusString.equals( "A" ) )
071 {
072 String file = line.substring( 3 );
073
074 status = ScmFileStatus.ADDED;
075
076 createdDirs.add( new ScmFile( file, status ) );
077 }
078 else
079 {
080 if ( logger.isInfoEnabled() )
081 {
082 logger.info( "Unknown line: '" + line + "'" );
083 }
084
085 return;
086 }
087 }
088
089 public int getRevision()
090 {
091 return revision;
092 }
093
094 public List<ScmFile> getCreatedDirs()
095 {
096 return createdDirs;
097 }
098 }