001package org.apache.maven.scm.provider.perforce.command;
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
022import org.apache.maven.scm.ScmFileStatus;
023
024import java.util.HashMap;
025import java.util.Map;
026
027/**
028 * @author mperham
029 *
030 */
031public class PerforceVerbMapper
032{
033    private static final Map<String, ScmFileStatus> VERB = new HashMap<String, ScmFileStatus>();
034
035    static
036    {
037        // Perforce uses different tenses sometimes so we need to map
038        // the different tenses to the same status.
039        VERB.put( "add", ScmFileStatus.ADDED );
040        VERB.put( "added", ScmFileStatus.ADDED );
041        VERB.put( "delete", ScmFileStatus.DELETED );
042        VERB.put( "deleted", ScmFileStatus.DELETED );
043        VERB.put( "edit", ScmFileStatus.MODIFIED );
044        VERB.put( "edited", ScmFileStatus.MODIFIED );
045        VERB.put( "updating", ScmFileStatus.UPDATED );
046        VERB.put( "updated", ScmFileStatus.UPDATED );
047        // UNKNOWN means we just ignore this verb
048        VERB.put( "refreshing", ScmFileStatus.UNKNOWN );
049    }
050
051    public static ScmFileStatus toStatus( String verb )
052    {
053        ScmFileStatus stat = (ScmFileStatus) VERB.get( verb );
054        if ( stat == null )
055        {
056            // XXX testing only
057            System.err.println( "No such verb: " + verb );
058            return ScmFileStatus.UNKNOWN;
059        }
060        if ( stat == ScmFileStatus.UNKNOWN )
061        {
062            // Return a null status in cases where the verb does not indicate a status change.
063            stat = null;
064        }
065        return stat;
066    }
067
068}