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